⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocn_e02.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 4 页
字号:

	3.0000 	Left 	22.0000 	10.5000 	  8.5000 	 3.9167
	3.0000 	Right 	22.0000 	12.0000 	-36.0000 	36.0000

	4.0000 	Left 	22.0000 	-6.0000  	  0.0000 	36.0000
	4.0000 	Right 	22.0000 	-6.0000 	  0.0000 	 1.5000

	5.0000 	Left 	16.2500 	-5.2500 	  1.5000 	 1.5000
	5.0000 	Right 	16.2500 	-5.2500 	  1.5000	 1.5000

	6.0000 	Left 	12.0000 	-3.0000 	  3.0000	 1.5000
	6.0000 	Right 	12.0000 	-3.0000 	  3.0000	 1.5000
			
Return:
	This function returns NAG error code, 0 if no error.
	
	11: On entry, spline.n must not be less than 8: spline.n = _value_.
	70: On entry, parameter derivs had an illegal value.
	238: On entry, x must satisfy spline.lamda[3] = x = spline.lamda[spline.n-4]: spline.lamda[3] = _value_, x = _value_, spline.lamda[_value_] = _value_.
	269: On entry, the cubic spline range is invalid: spline.lamda[3] = _value_ while spline.lamda[spline.n-4] = _value_.  These must satisfy spline.lamda[3] < spline.lamda[spline.n-4].
	
	successfully call of the nag_1d_spline_deriv function.		
*/

	int  nag_1d_spline_deriv(
	Nag_DerivType derivs, 
		double x, 	//the argument x at which the cubic spline and its derivatives are to be evaluated.
		double s[], // the value of the jth derivative of the spline at the argument x, for j = 0, 1, 2, 3.
	Nag_Spline *spline // Pointer to structure of type Nag_Spline
); //Evaluation of fitted cubic spline, function and derivatives


/** e02bdc
		computes the definite integral of a cubic spline from its B-spline
		representation.
	
Example:
	Determine the definite integral over the interval [0,6] of a cubic spline having 6 interior 
	knots at the positions lamda= 1, 3, 3, 3, 4, 4, the 8 additional knots 0, 0, 0, 0, 6, 6, 6, 6, 
	and the 10 B-spline coefficients 10, 12, 13, 15, 22, 26, 24, 18, 14, 12.

void test_nag_1d_spline_intg()
{
	int j;
	double integral;
	Nag_Spline spline;
	spline.n = 14;
	double lamda[] = {0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 3.0, 3.0,4.0, 4.0, 6.0, 6.0, 6.0, 6.0};
	double c[] = {10.0, 12.0, 13.0, 15.0, 22.0, 26.0, 24.0, 18.0,14.0, 12.0, 0, 0, 0}
	spline.c = c;
	spline.lamda = lamda;
	
	nag_1d_spline_intg(&spline, &integral);
	
	printf("Definite integral = %11.3e\n",integral);
}

	The output is following:

Definite integral = 1.000e+02

Return:
	The function returns NAG error, 0 if no error.
	
	11: On entry, spline.n must not be less than 8: spline.n = _value_.
	253: On entry, the knots must satisfy the following constraints: spline.lamda[spline.n-4] > spline.lamda[3], spline.lamda[j] = spline.lamda[j - 1], for j = 1, 2, . . . ,spline.n-1, with equality in the cases j = 1, 2, 3,spline.n-3,spline.n-2 and spline.n-1.
		
	successfully call of the nag_1d_spline_intg function.
*/
	
	int  nag_1d_spline_intg(
	 	Nag_Spline *spline, //pointer to structure of type Nag_Spline
		double *integral	//the value of the definite integral of s(x) between the limits x = a and x = b,
); // Evaluation of fitted cubic spline, definite integral


/** e02bec
		computes a cubic spline approximation to an arbitrary set of data points.
		
Example:
	This example program reads in a set of data values, followed by a set of values of S. For each value
	of S it calls nag_1d_spline_fit to compute a spline approximation, and prints the values of the knots
	and the B-spline coefficients ci.

void test_nag_1d_spline_fit()
{
	int NEST = 54;
	int m = 15, r, j;
	double weights[50] = {1.00, 2.00, 1.50, 1.00, 3.00, 1.00, 0.50, 1.00, 2.00, 2.50, 1.00, 3.00, 1.00, 2.00, 1.00};  
	double x[50] = {0.0000E+00, 5.0000E-01, 1.0000E+00, 1.5000E+00, 2.0000E+00, 2.5000E+00, 3.0000E+00, 4.0000E+00, 
	4.5000E+00, 5.0000E+00, 5.5000E+00, 6.0000E+00, 7.0000E+00, 7.5000E+00, 8.0000E+00};
	double y[50] = {-1.1000E+00, -3.7200E-01, 4.3100E-01, 1.6900E+00, 2.1100E+00, 3.1000E+00, 4.2300E+00, 4.3500E+00,
	4.8100E+00, 4.6100E+00, 4.7900E+00, 5.2300E+00, 6.3500E+00, 7.1900E+00, 7.9700E+00};
	double s[3] = {1.0, 0.5, 0.1};
	double fp, sp[99], txr;
	Nag_Start start;
	Nag_Comm warmstartinf;
	Nag_Spline spline;
	
	start = Nag_Cold;

	for(int i = 0; i < 3; i ++)
	{
		nag_1d_spline_fit(start, m, x, y, weights, s[i], NEST, &fp, &warmstartinf, &spline);
		
		for (r=0; r<m; r++)
			nag_1d_spline_evaluate(x[r], &sp[r*2], &spline);
		for (r=0; r<m-1; r++)
		{
			txr = (x[r] + x[r+1]) / 2;
			nag_1d_spline_evaluate(txr, &sp[r*2], &spline);
		}
		
		printf("\nCalling with smoothing factor s = %12.3e\n",s);
		printf("\nNumber of distinct knots = %ld\n\n", spline.n-6);
		printf("Distinct knots located at \n\n");
		for (j=3; j<spline.n-3; j++)
		{
			printf("%8.4f",spline.lamda[j]);
			if((j-3)%6==5 || j==spline.n-4)
				printf("\n");
		}
		printf("\n\n J B-spline coeff c\n\n");
		for (j=0; j<spline.n-4; ++j)
			printf(" %3ld %13.4f\n",j+1,spline.c[j]);
		printf("\nWeighted sum of squared residuals fp = %12.3e\n",fp);
		if (fp == 0.0)
			printf("The spline is an interpolating spline\n");
		if (spline.n == 8)
			printf("The spline is the weighted least-squares cubic	polynomial\n");
		start = Nag_Warm;	
	}
	nag_free(spline.c);
	nag_free(spline.lamda);
	nag_free(warmstartinf.nag_w);
	nag_free(warmstartinf.nag_iw);	

}

	The output is following:
	
	Calling with smoothing factor s = 1.000e+00
	
	Number of distinct knots = 3
	
	Distinct knots located at
	
	0.0000 4.0000 8.0000
	
	J 	B-spline coeff c
	
	1 	-1.3201
	2 	 1.3542
	3 	 5.5510
	4 	 4.7031
	5 	 8.2277
	
	Weighted sum of squared residuals fp = 1.000e+00
	
	Calling with smoothing factor s = 5.000e-01
	
	Number of distinct knots = 7
	
	Distinct knots located at
	
	0.0000 1.0000 2.0000 4.0000 5.0000 6.0000	8.0000
	
	J 	B-spline coeff c
	
	1 	-1.1072
	2 	-0.6571
	3 	 0.4350
	4 	 2.8061
	5 	 4.6824
	6 	 4.6416
	7 	 5.1976
	8 	 6.9008
	9 	 7.9979
	
	Weighted sum of squared residuals fp = 5.001e-01
	
	Calling with smoothing factor s = 1.000e-01
	
	Number of distinct knots = 10
	
	Distinct knots located at
	
	0.0000 1.0000 1.5000 2.0000 3.0000 4.0000	4.5000 5.0000 6.0000 8.0000
	
	J 	B-spline coeff c
	1 	-1.0900
	2 	-0.6422
	3 	 0.0369
	4 	 1.6353
	5 	 2.1274
	6 	 4.5526
	7 	 4.2225
	8 	 4.9108
	9 	 4.4159
	10 	 5.4794
	11 	 6.8308
	12   7.9935
	
	Weighted sum of squared residuals fp = 1.000e-01
	
Return:
	The function returns NAG error, 0 if no error.
	
	70: On entry, parameter start had an illegal value.
	11: On entry, m must not be less than 4: m = _value_.  On entry, nest must not be less than 8: nest = _value_.
	5: On entry, s must not be less than 0.0: s = _value_.
	240: On entry, the weights are not strictly positive: weights[_value_] = _value_.
	63: The sequence x is not strictly increasing: x[_value_] = _value_ x[_value_] = _value_.
	268: On entry, nest = _value_, s = _value_, m = _value_.  Constraint: nest = m + 4 when s = 0.0.
	73: Memory allocation failed.
	266: Start has been set to Nag Warm at the .rst call of this function. It must be set to Nag Cold at the FIrst call. 
	264: The number of knots needed is greater than nest, nest = _value_. If nest is already large, say nest > m/2, this may indicate that possibly s is too small: s = _value_.  
	254: The iterative process has failed to converge. Possibly s is too small: s = _value_.  If the function fails with an error exit of NE SPLINE COEFF CONV or NE NUM KNOTS ID GT, a spline approximation is returned, but it fails to satisfy the .tting criterion (see (2) and (3) in Section 3) - perhaps by only a small amount, however. 
		
	successfully call of the nag_1d_spline_fit function.	
*/

	int  nag_1d_spline_fit(
		Nag_Start start, // start must be set to Nag Cold or Nag Warm.
		int m, // the number of data points
		const double x[], // the value x[r] of the independent variable (abscissa) x, for r = 1, 2, . . .,m.
		const double y[], // the value y[r] of the dependent variable (ordinate) y, for r = 1, 2, . . .,m.
		const double weights[], // the value w[r] of the weights,for r = 1, 2, . . .,m.
		double s, //the smoothing factor
		int nest, // an over-estimate for the number, n, of knots required.
		double *fp, //the sum of the squared weighted residuals of the computed spline approximation
		Nag_Comm *warmstartinf, // Pointer to structure of type Nag_Comm
		Nag_Spline *spline //Pointer to structure of type Nag_Spline
);//Least-squares cubic spline curve fit, automatic knot placement, one variable


/** e02dcc
		computes a bicubic spline approximation to a set of data values,
		given on a rectangular grid in the x-y plane.

Example:

	This example program reads in values of mx, my, xq, for q = 1, 2, . . . ,mx, 
	and yr, for r = 1, 2, . . .,my, followed by values of the ordinates fq,
	r defined at the grid points (xq, yr). It then calls nag 2d spline fit
	grid to compute a bicubic spline approximation for one specified value of s,
	and prints the values of the computed knots and B-spline coefficients. 
	Finally it evaluates the spline at a small sample of points on a rectangular grid.
	

void test_nag_2d_spline_fit_grid()
{
	int NXEST = 15;
	int NYEST = 13;
	int mx = 11, my = 9, nx, ny, npx, npy, i, j;
	double fg[49], px[7], py[7];
	double xhi, yhi, xlo, ylo, delta, s, fp;
	Nag_Start start;
	Nag_2dSpline spline;
	Nag_Comm warmstartinf;
	double x[] ={0.0000E+00, 5.0000E-01, 1.0000E+00, 1.5000E+00, 2.0000E+00,2.5000E+00,
		 	3.0000E+00, 3.5000E+00, 4.0000E+00, 4.5000E+00,5.0000E+00};
	double y[] ={0.0000E+00, 5.0000E-01, 1.0000E+00, 1.5000E+00, 2.0000E+00,2.5000E+00,
				 3.0000E+00, 3.5000E+00, 4.0000E+00}	
	double f[] ={1.0000E+00, 8.8758E-01, 5.4030E-01, 7.0737E-02, -4.1515E-01,
			-8.0114E-01, -9.7999E-01, -9.3446E-01, -6.5664E-01, 1.5000E+00,
			1.3564E+00, 8.2045E-01, 1.0611E-01, -6.2422E-01, -1.2317E+00,
			-1.4850E+00, -1.3047E+00, -9.8547E-01, 2.0600E+00, 1.7552E+00,
			1.0806E+00, 1.5147E-01, -8.3229E-01, -1.6023E+00, -1.9700E+00,
			-1.8729E+00, -1.4073E+00, 2.5700E+00, 2.1240E+00, 1.3508E+00,
			1.7684E-01, -1.0404E+00, -2.0029E+00, -2.4750E+00, -2.3511E+00,
			-1.6741E+00, 3.0000E+00, 2.6427E+00, 1.6309E+00, 2.1221E-01,
			-1.2484E+00, -2.2034E+00, -2.9700E+00, -2.8094E+00, -1.9809E+00,
			3.5000E+00, 3.1715E+00, 1.8611E+00, 2.4458E-01, -1.4565E+00,
			-2.8640E+00, -3.2650E+00, -3.2776E+00, -2.2878E+00, 4.0400E+00,
			3.5103E+00, 2.0612E+00, 2.8595E-01, -1.6946E+00, -3.2046E+00,
			-3.9600E+00, -3.7958E+00, -2.6146E+00, 4.5000E+00, 3.9391E+00,
			2.4314E+00, 3.1632E-01, -1.8627E+00, -3.6351E+00, -4.4550E+00,
			-4.2141E+00, -2.9314E+00, 5.0400E+00, 4.3879E+00, 2.7515E+00,
			3.5369E-01, -2.0707E+00, -4.0057E+00, -4.9700E+00, -4.6823E+00,
			-3.2382E+00, 5.5050E+00, 4.8367E+00, 2.9717E+00, 3.8505E-01,
			-2.2888E+00, -4.4033E+00, -5.4450E+00, -5.1405E+00, -3.5950E+00,
			6.0000E+00, 5.2755E+00, 3.2418E+00, 4.2442E-01, -2.4769E+00,
			-4.8169E+00, -5.9300E+00, -5.6387E+00, -3.9319E+00}	
	
	start = Nag_Cold;
	s = 0.1;

	nag_2d_spline_fit_grid(start, mx, x, my, y, f, s, NXEST, NYEST,
						&fp, &warmstartinf, &spline);
	nx = spline.nx;
	ny = spline.ny;
	printf("\nCalling with smoothing factor s = %11.4e:	spline.nx = %2ld, spline.ny = %2ld.\n\n",s,nx,ny);
	printf("Distinct knots in x direction located at\n");
	for (j=3; j<spline.nx-3; j++)
	{
		printf("%12.4f",spline.lamda[j]);
		if((j-3)%5==4 || j==spline.nx-4)
			printf("\N");
	}
	
	printf("\nDistinct knots in y direction located at\n");
	for (j=3; j<spline.ny-3; j++)
	{
		printf("%12.4f",spline.mu[j]);
		if((j-3)%5==4 || j==spline.ny-4)
			printf("\n");
	}
	printf("\nThe B-spline coefficients:\n\n");
	for (i=0; i<ny-4; i++)
	{
		for (j=0; j<nx-4; j++)
			printf("%9.4f",spline.c[i+j*(ny-4)]);
		printf("\n");
	}
	printf("\nSum of squared residuals fp = %11.4e\n",fp);
	if (fp==0.0)
		printf("\nThe spline is an interpolating spline\n");
	if (nx==8 && ny==8)
		printf("\nThe spline is the least-squares bi-cubic polynomial\n");

	npx = 6;
	xlo = 0.0;
	xhi = 5.0;
	npy = 5;
	ylo = 0.0;
	yhi = 4.0;
	delta = (xhi-xlo) / (npx-1);
	for (i=0; i<npx; i++)
	{
		if(xlo+i*delta > xhi)
			px[i] = xhi;
		else
			px[i] =	xlo+i*delta; 		
	}
	for (i=0; i<npy; i++)
	{
		if(ylo+i*delta > yhi)
			py[i] = yhi;
		else
			py[i] =	ylo+i*delta; 		
	}
	nag_2d_spline_eval_rect(npx, npy, px, py, fg, &spline);
	printf("\nValues of computed spline:\n");
	printf("\n x");
	for (i=0; i<npx; i++)
		printf("%7.2f ",px[i]);
	printf("\n y\n");
	for (i=npy-1; i>=0; i--)
	{
		printf("%7.2f ",py[i]);
		for (j=0; j<npx; ++j)
			printf("%8.2f ",fg[npy*j+i]);
		printf("\n");
	}
	nag_free(spline.mu);
	nag_free(spline.c);
	nag_free(spline.lamda);
	nag_free(warmstartinf.nag_w);
	nag_free(warmstartinf.nag_iw);
}

	The output is following:
	
	Calling with smoothing factor s = 1.0000e-01: spline.nx = 10, spline.ny = 13.
	
	Distinct knots in x direction located at
	
	0.0000 1.5000 2.5000 5.0000
	
	Distinct knots in y direction located at
	
	0.0000 1.0000 2.0000 2.5000 3.0000	3.5000 4.0000

	The B-spline coefficients:

	 0.9918  1.5381  2.3913  3.9845  5.2138  5.9965
	 1.0546  1.5270  2.2441  4.2217  5.0860  6.0821
	 0.6098  0.9557  1.5587  2.3458  3.3860  3.7716
	-0.2915 -0.4199 -0.7399 -1.1763 -1.5527 -1.7775
	-0.8476 -1.3296 -1.8521 -3.3468 -4.3628 -5.0085
	-1.0168 -1.5952 -2.4022 -3.9390 -5.4680 -6.1656
	-0.9529 -1.3381 -2.2844 -3.9559 -5.0032 -5.8709
	-0.7711 -1.0914 -1.8488 -3.2549 -3.9444 -4.7297
	-0.6476 -1.0373 -1.5936 -2.5887 -3.3485 -3.9330
	
	Sum of squared residuals fp = 1.0004e-01

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -