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

📄 ocn_e02.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 4 页
字号:
	
	Values of computed spline:
	
	x 	0.00 1.00 2.00 3.00 4.00 5.00
	
	y
	4.00 -0.65 -1.36 -1.99 -2.61 -3.25 -3.93
	3.00 -0.98 -1.97 -2.91 -3.91 -4.97 -5.92
	2.00 -0.42 -0.83 -1.24 -1.66 -2.08 -2.48
	1.00  0.54  1.09  1.61  2.14  2.71  3.24
	0.00  0.99  2.04  3.03  4.01  5.02  6.00

Return:
	This function returns NAG error code, 0 if no error.

	70: On entry, parameter start had an illegal value.
	11: On entry, mx must not be less than 4: mx = _value_.  On entry, my must not be less than 4: my = _value_.  On entry, nxest must not be less than 8: nxest = _value_.  On entry, nyest must not be less than 8: nyest = _value_.
	5: On entry, s must not be less than 0.0: s = _value_.
	268: On entry, s = _value_, nxest = _value_, mx = _value_. Constraint: nxest = mx+4 when s = 0.0.  On entry, s = _value_, nyest = _value_, my = _value_. Constraint: nyest = mx+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 .rst call.
	63: The sequence x is not strictly increasing: x[_value_] = _value_, x[_value_] = _value_.  The sequence y is not strictly increasing: y[_value_] = _value_, y[_value_] = _value_.
	261: The number of knots required is greater than allowed by nxest or nyest, nxest = _value_, nyest = _value_. Possibly s is too small, especially if nxest, nyest > mx/2, my/2. s = _value_, mx = _value_, my = _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 NUM KNOTS 2D GT RECT or NE SPLINE COEFF CONV, then 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_2d_spline_fit_grid function.
*/
	
	int nag_2d_spline_fit_grid(
		Nag_Start start, // start must be set to Nag Cold or Nag Warm.
		int mx, // the number of grid points along the x axis
		const double x[],//the x co-ordinate of the qth grid point along the x axis, for q = 1, 2, . . .,mx.
		int my, //the number of grid points along the y axis.
		const double y[], // the y co-ordinate of the rth grid point along the y axis, for r = 1, 2, . . .,my.
		const double f[],// contain the data value fq,r, for q = 1, 2, . . .,mx and r = 1, 2, . . .,my.
		double s, // the smoothing factor
		int nxest,
		int nyest, // an upper bound for the number of knots nx and ny required in the x and y directions respectively.
		double *fp, // the sum of squared residuals of the computed spline approximation
		Nag_Comm *warmstartinf, // Pointer to structure of type Nag_Comm
		Nag_2dSpline *spline // Pointer to structure of type Nag_2dSpline
);// Least-squares bicubic spline fit with automatic knot placement, two variables (rectangular grid).


/** e02ddc
		computes a bicubic spline approximation to a set of scattered data.
		
Example:
	This example program reads in a value of m, followed by a set of m data 
	points (xr, yr, fr) and their weights wr. It then calls nag 2d spline fit scat 
	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_scat()
{
	double  weights[30], fg[49],px[7], py[7];
	int i, j, m, rank, nx, ny, npx, npy, nxest, nyest;
	double s, delta, fp, xhi, yhi, xlo, ylo;
	Nag_Start start;
	Nag_2dSpline spline;
	double warmstartinf;
	double x[] ={11.16,12.85,19.85,19.72,15.91,0.00,20.87,3.45,14.26,17.43,22.80,
			7.58,25.00,0.00,9.66,5.22,17.25,25.00,12.13,22.23,11.52,15.20,7.54,
			17.32,2.14,0.51,22.69,5.47,21.67,3.31}
	double y[] ={1.24,3.06,10.72,1.39,7.74,20.00,20.00,12.78,17.87,3.46,12.39,1.98,
			11.87,0.00,20.00,14.66,19.57,3.87,10.79,6.21,8.53,0.00,10.69,13.78,
			15.03,8.37,19.63,17.13,14.36,0.33};
	double f[] ={22.15,22.11,7.97,16.83,15.30, 34.60,5.74,41.24,10.74,18.60,5.47,
			29.87, 4.40,58.20,4.73,40.36, 6.43,8.74, 13.71,10.25, 15.74,21.60,
			19.31,12.11,53.10,49.43,3.25,28.63,5.52,44.08};
			
	nxest = 14;
	nyest = 14;			
	for(i = 0; i < 30; i++)
		weights[i] = 1.00;
	m = 30;
	start = Nag_Cold;
	s = 10.0;
	
	nag_2d_spline_fit_scat(start, m, x, y, f, weights, s, nxest, nyest, 
							&fp,&rank, &warmstartinf, &spline);
	
	nx= spline.nx;
	ny = spline.ny;
	printf("\nCalling with smoothing factor s = %11.4e, nx= %1ld,ny = %1ld\n",s,nx,ny);
	printf("rank deficiency = %1ld\n\n",(nx-4)*(ny-4)-rank);
	printf("Distinct knots in xdirection 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.2f",spline.c[i+j*(ny-4)]);
		printf("\n");
	}
	printf("\n Sum of squared residuals fp = %11.4e\n",fp);
	if (nx==8 && ny==8)
		printf("The spline is the least-squares bi-cubic polynomial\n");
	
	npx = 7;
	xlo = 3.0;
	xhi = 21.0;

	npy = 6;
	ylo = 2.0;
	yhi = 17.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\n");
	printf(" x");
	for (i=0; i< npx;  i++)
		printf("%8.2f ",px[i]);
	printf("\n y\n");
	for (i=npy-1; i>=0; i--)
	{
		printf("%8.2f ",py[i]);
		for (j=0; j < npx; ++j)
			printf("%8.2f ",fg[npy*j+i]);
		printf("\n");
	}
	nag_free(spline.lamda);
	nag_free(spline.c);
	nag_free(spline.mu);
}


	The output is following:
	
	
	Calling with smoothing factor s = 1.0000e+01, nx= 10, ny = 9 rank deficiency = 0
	
	Distinct knots in xdirection located at
	
	0.0000 9.7575 18.2582 25.0000
	
	Distinct knots in y direction located at
	
	0.0000 9.0008 20.0000
	
	The B-spline coefficients:
	
	58.16  46.31  6.01  32.00  5.86 -23.78
	63.78  46.74 33.37  18.30 14.36  15.95
	40.84 -33.79  5.17  13.10 -4.13  19.37
	75.44 111.92  6.94  17.33  7.09 -13.24
	34.61 -42.61 25.20  -1.96 10.37  -9.09
	
	Sum of squared residuals fp = 1.0002e+01
	
	Values of computed spline:
	
	x	3.00 6.00 9.00 12.00 15.00 18.00 21.00
	
	y
	
	17.00 40.74 28.62 19.84 14.29 11.21 9.46 7.09
	14.00 48.34 33.97 21.56 14.71 12.32 10.82 7.15
	11.00 37.26 24.46 17.21 14.14 13.02 11.23 7.29
	8.00 30.25 19.66 16.90 16.28 15.21 12.71 8.99
	5.00 36.64 26.75 23.07 21.13 18.97 15.90 11.98
	2.00 45.04 33.70 26.25 22.88 21.62 19.39 13.40


Return:
	This function returns NAG error code, 0 if no error.
	
	70: On entry, parameter start had an illegal value.
	11: On entry, nxest must not be less than 8: nxest = _value_.  On entry, nyest must not be less than 8: nyest = _value_.
	5: On entry, s must not be less than or equal to 0.0: s = _value_.
	270: On entry, the number of data points with non-zero weights = _value_. Constraint: the number of non-zero weights = 16.
	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 .rst call.
	260: On entry, all the values in the array x must not be equal.  On entry, all the values in the array y must not be equal.
	262: The number of knots required is greater than allowed by nxest or nyest, nxest = _value_, nyest = _value_. Possibly s is too small, especially if nxest, nyest > 5 + 併m. s = _value_, m = _value_.
	263: No more knots can be added because the number of B-spline coe.cients already exceeds m.  Either m or s is probably too small: m = _value_, s = _value_.
	265: No more knots added; the additional knot would coincide with an old one. Possibly an inaccurate data point has too large a weight, or 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 NUM KNOTS 2D GT SCAT, NE NUM COEFF GT, NE NO ADDITIONAL KNOTS or NE SPLINE COEFF CONV, then a spline approximation is returned, but it fails to satisfy the setting criterion (see (2) and (3) in Section 3) - perhaps by only a small amount, however. 
		
	successfully call of the  nag_1d_cheb_fit function.	
*/
	
int  nag_2d_spline_fit_scat(
		Nag_Start start, 
		int m,
		const double x[],
		const double y[],
		const double f[],
		const double weights[], 
		double s,
		int nxest,
		int nyest,
		double *fp,
		int *rank,
		double *warmstartinf, 
		Nag_2dSpline *spline);


/** e02dec
		calculates values of a bicubic spline from its B-spline representation.
		
Example:
	This program reads in knot sets spline.lamda[0],. . . ,spline.lamda[spline.nx-1] 
	and spline.mu[0],. . . ,spline.mu[spline.ny and a set of bicubic spline coefficients cij. 
	Following these are a value for m and the co-ordinates (xr, yr), for r = 1, 2, . . .,m, 
	at which the spline is to be evaluated.

void test_nag_2d_spline_eval()
{
	int i, m = 7;
	double x[20] = {1.0, 1.1, 1.5, 1.6, 1.9, 1.9, 2.0}; 
	double y[20] = {0.0, 0.1, 0.7, 0.4, 0.3, 0.8, 1.0};
	double ff[20];
	Nag_2dSpline spline;
	double lamda[] = {1.0,1.0,1.0,1.0,1.3,1.5,1.6,2.0,2.0,2.0,2.0};
	double mu[] = {0.0,0.0, 0.0, 0.0, 0.4, 0.7, 1.0, 1.0, 1.0, 1.0}; 
	double c[] ={1.0000, 1.1333, 1.3667, 1.7000, 1.9000, 2.0000,
		1.2000, 1.3333, 1.5667, 1.9000, 2.1000, 2.2000,
		1.5833, 1.7167, 1.9500, 2.2833, 2.4833, 2.5833,
		2.1433, 2.2767, 2.5100, 2.8433, 3.0433, 3.1433,
		2.8667, 3.0000, 3.2333, 3.5667, 3.7667, 3.8667,
		3.4667, 3.6000, 3.8333, 4.1667, 4.3667, 4.4667,
		4.0000, 4.1333, 4.3667, 4.7000, 4.9000, 5.0000};
		
	spline.nx = 11;
	spline.ny = 10;
	spline.c = c;
	spline.lamda =lamda;
	spline.mu = mu;

	nag_2d_spline_eval(m, x, y, ff, &spline);

	printf(" i x[i] y[i] ff[i]\n");
	for (i=0; i<m; i++)
		printf("%7ld %11.3f%11.3f%11.3f\n",i,x[i],y[i],ff[i]);
}

	The output is following:
	
	
	i 	x[i] 	y[i] 	ff[i]
	
	0 	1.000 	0.000 	1.000
	1 	1.100 	0.100 	1.310
	2 	1.500 	0.700 	2.950
	3 	1.600 	0.400 	2.960
	4 	1.900 	0.300 	3.910
	5 	1.900 	0.800 	4.410
	6 	2.000 	1.000 	5.000

Return:
	This function returns NAG error code, 0 if no error.
	
	11: On entry, m must not be less than 1: m = _value_.  On entry, spline.nx must not be less than 8: spline.nx = _value_.  On entry, spline.ny must not be less than 8: spline.ny = _value_.  
	73: Memory allocation failed.
	255: On entry, the end knots must satisfy _value_, _value_ = _value_, _value_ = _value_.
	62: The sequence spline.lamda is not increasing: spline.lamda [_value_] = _value_, spline.lamda [_value_] = _value_. The sequence spline.mu is not increasing: spline.mu[_value_] = _value_, spline.mu[_value_] = _value_.
	257: On entry, point (x[_value_] = _value_, y[_value_] = _value_) lies outside the rectangle bounded by spline.lamda[3] = _value_, spline.lamda[_value_] = _value_, spline.mu[3] = _value_, spline.mu[_value_] = _value_.  
		
	successfully call of the nag_2d_spline_eval.	
*/

	int nag_2d_spline_eval(
		int m , // the number of points at which values of the spline are required
		const double x[],
		const double y[], // These are the coordinates of the points at which values of the spline are required
		double ff[], // contains the value of the spline at the point (xr, yr),
		Nag_2dSpline *spline // Pointer to structure of type Nag_2dSpline
  ); // Evaluation of bicubic spline, at a set of points


/** e02dfc
		calculates values of a bicubic spline from its B-spline representation.
		The spline is evaluated at all points on a rectangular grid.
		
Example:
	This program reads in knot sets spline.lamda[0],. . . ,spline.lamda[spline.nx-1]
	and spline.mu[0],. . ., spline.mu[spline.ny-1], and a set of bicubic spline 
	coefficients cij . Following these are values for mx and the x co-ordinates x[q], 
	for q = 1, 2, . . .,mx, and values for my and the y co-ordinates y[r],
	for r = 1, 2, . . .,my, defining the grid of points on which the spline 
	is to be evaluated.
		
void test_nag_2d_spline_eval_rect()
{
	int i, j, mx = 7, my = 6;
	double x[20] = {1.0, 1.1, 1.3, 1.4, 1.5, 1.7, 2.0};
	double y[20] = {0.0, 0.2, 0.4, 0.6, 0.8, 1.0};
	double ff[400];
	Nag_2dSpline spline;
	double lamda[] = {1.0,1.0,1.0,1.0,1.3,1.5,1.6,2.0,2.0,2.0,2.0};
	double mu[] = {0.0,0.0, 0.0, 0.0, 0.4, 0.7, 1.0, 1.0, 1.0, 1.0}; 
	double c[] ={1.0000, 1.1333, 1.3667, 1.7000, 1.9000, 2.0000,
				 1.2000, 1.3333, 1.5667, 1.9000, 2.1000, 2.2000,
				 1.5833, 1.7167, 1.9500, 2.2833, 2.4833, 2.5833,
				 2.1433, 2.2767, 2.5100, 2.8433, 3.0433, 3.1433,
				 2.8667, 3.0000, 3.2333, 3.5667, 3.7667, 3.8667,
				 3.4667, 3.6000, 3.8333, 4.1667, 4.3667, 4.4667,
				 4.0000, 4.1333, 4.3667, 4.7000, 4.9000, 5.0000};
	
	spline.nx = 11;
	spline.ny = 10;
	spline.c = c;
	spline.lamda =lamda;
	spline.mu = mu;

	nag_2d_spline_eval_rect(mx, my, x, y, ff, &spline);
	
	printf("Spline evaluated on x-y grid (x across, y down):\n   ");
	for(i=0; i<mx; i++)
		printf(" %8.3f ",x[i]);
	printf("\n");
	for (j=0; j<my; j++)
	{
		printf("%2.1f",y[j]);
		for (i=0; i<mx; i++)
		{
			printf(" %8.3f ", ff[my*i+j]);
			if(i%7==6 || i==mx-1) 
				printf("\n");
		}
	}
}

	The output is following:
		
	Spline evaluated on x-y grid (x across, y down):
	
			1.0 	1.1 	1.3 	1.4 	1.5 	1.7 	2.0
	0.0 	1.000 	1.210 	1.690 	1.960 	2.250 	2.890 	4.000
	0.2 	1.200 	1.410 	1.890 	2.160 	2.450 	3.090 	4.200
	0.4 	1.400 	1.610 	2.090 	2.360 	2.650 	3.290 	4.400
	0.6 	1.600 	1.810 	2.290 	2.560 	2.850 	3.490 	4.600
	0.8 	1.800 	2.010 	2.490 	2.760 	3.050 	3.690 	4.800
	1.0 	2.000 	2.210 	2.690 	2.960 	3.250 	3.890 	5.000
	
Return:
	This function returns NAG error code, 0 if no error.
	
	11: On entry, mx must not be less than 1: mx = _value.  On entry, my must not be less than 1: my = _value.  On entry, spline.nx must not be less than 8: spline.nx = _value.  On entry, spline.ny must not be less than 8: spline.ny = _value.
	73: Memory allocation failed.
	255: On entry, the end knots must satisfy _value	, _value	 = _value	, _value	 = _value	.
	62: The sequence spline.lamda is not increasing: spline.lamda[_value	] = _value	, spline.lamda [_value	] = _value	.  The sequence spline.mu is not increasing: spline.mu[_value	] = _value	, spline.mu[_value	] = _value	.  
	256: On entry, the end knots and coordinates must satisfy spline.lamda[3] = x[0] and x[mx]-1] = spline.lamda[spline.nx-4]. spline.lamda[3] = _value	, x[0] = _value	, x[_value	] = _value	, spline.lamda[_value	] = _value	.  On entry, the end knots and coordinates must satisfy spline.mu[3] = y[0] and y[my-1] = spline.mu[spline.ny-4]. spline.mu[3] = _value	, y[0] = _value	, y[_value	] = _value	, spline.mu[_value	] = _value	.
	63: The sequence x is not strictly increasing: x[_value	] = _value	, x[_value	] = _value	.  The sequence y is not strictly increasing: y[_value	] = _value	, y[_value	] = _value	.
		
	successfully call of the nag_2d_spline_eval_rect function.	
*/

	int  nag_2d_spline_eval_rect(
		int mx,
		int my, //the number of points along the x and y axes that define the rectangular grid.
		const double x[],
		const double y[], // These are the x and y co-ordinates that define the rectangular grid of points at which values of the spline are required
		double ff[], // contains the value of the spline at the point (xq, yr),
		Nag_2dSpline *spline // Pointer to structure of type Nag_2dSpline
  ); // Evaluation of bicubic spline, at a mesh of points

⌨️ 快捷键说明

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