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

📄 ocn_c06.h

📁 图像处理的压缩算法
💻 H
📖 第 1 页 / 共 5 页
字号:
/*------------------------------------------------------------------------------*
 * File Name: OCN_c01.h															*
 * Creation: TCZ 5/22/2001														*
 * Purpose: Origin C Header for NAG functions									*
 * Copyright (c) OriginLab Corp.	2001										*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *------------------------------------------------------------------------------*/

#ifndef _O_NAG_C06_H
#define _O_NAG_C06_H

//#importdll "ONAG" // NAG DLL prepared by OriginLab
#pragma dll(ONAG)

#include <NAG\nag_types.h>

/*	begin proto */

/**	c06eac
		calculates the discrete Fourier transforms of a sequence of n real data values.

Example1:
	This piece of code reads in a sequence of real data values from a worksheet column, and
	prints their discrete Fourier transform (as computed by nag fft real), after expanding
	it from Hermitian form into a full complex sequence.
	Assume "Data1" Worksheet has 3 columns, the first column contain 7 data, and we want to 
	put result complex form real part in the second column and imag part in the third column.
	
	int n = 7, j, success, n2, nj;
	//Attach two Datasets to these 2 columns
	Dataset xx("data1",0);
	Dataset aa("data1",1);
	Dataset bb("data1",2);
	//Because Dataset cannot be the parameter of function, but vector can be.
	vector x = xx, a = aa, b = bb;
	success = nag_fft_real(n, x);
	
	if(success == 0)
	{
		a[0] = x[0];
		b[0] = 0.0;
		n2 = (n-1)/2;
		for (j = 1; j<=n2; j++)
		{
			nj = n - j;
			a[j] = x[j];
			a[nj] = x[j];
			b[j] = x[nj];
			b[nj] = -x[nj];
		}
		if (n % 2==0)
		{
			a[n2+1] = x[n2+1];
			b[n2+1] = 0.0;
		}
	}
	//write the result to worksheet.
	aa = a;
	bb = b;
	
		
Example2:
	This program reads in a sequence of real data values, and prints their discrete 
	Fourier transform (as computed by nag fft real), after expanding it from 
	Hermitian form into a full complex sequence.  It then performs an inverse 
	transform using nag conjugate hermitian (c06gbc) and nag fft hermitian (c06ebc), 
	and prints the sequence so obtained alongside the original data values.
	
void test_nag_fft_real()
{

	int j, n = 7, n2, nj;
	double a[20], b[20], xx[20];
	double x[20] = {0.34907, 0.54890, 0.74776, 0.94459, 1.13850, 1.32850, 1.51370};
	int success;
	
	for (j = 0; j<n; j++)
		xx[j] = x[j];
	
	success = nag_fft_real(n, x);
	if(success == 0)
	{
		a[0] = x[0];
		b[0] = 0.0;
		n2 = (n-1)/2;
		for (j = 1; j<=n2; j++)
		{
			nj = n - j;
			a[j] = x[j];
			a[nj] = x[j];
			b[j] = x[nj];
			b[nj] = -x[nj];
		}
		if (n % 2==0)
		{
			a[n2+1] = x[n2+1];
			b[n2+1] = 0.0;
		}
		printf("\nComponents of discrete Fourier transform\n");
		printf("\n Real Imag \n\n");
		for (j = 0; j<n; j++)
			printf("%3ld %10.5f %10.5f\n", j, a[j], b[j]);
		
		nag_conjugate_hermitian(n, x);
		nag_fft_hermitian(n, x);
		printf("\nOriginal sequence as restored by inverse transform\n");
		printf("\n Original Restored\n\n");
		for (j = 0; j<n; j++)
			printf("%3ld %10.5f %10.5f\n", j, xx[j], x[j]);
	}
	else
	printf("Function c06eac has some problems.");
}

	The output is following:
	
	Components of discrete Fourier transform

		 	 Real 		 Imag
		 
	0 		 2.48361 	 0.00000
	1 		-0.26599 	 0.53090
	2 		-0.25768 	 0.20298
	3 		-0.25636 	 0.05806
	4 		-0.25636 	-0.05806
	5 		-0.25768 	-0.20298
	6 		-0.26599 	-0.53090

	Original sequence as restored by inverse transform

			Original 		Restored

	0 		0.34907 		0.34907
	1 		0.54890 		0.54890
	2 		0.74776 		0.74776
	3 		0.94459 		0.94459
	4 		1.13850 		1.13850
	5 		1.32850 		1.32850
	6 		1.51370 		1.51370	
	
Return:
	The function returns NAG error code or 0 if no error.
	
	137: At least one of the prime factors of n is greater than 19.
	138: n has more than 20 prime factors.
	12:  On entry, n must not be less than or equal to 1: n = _value_.

	successfully call of the nag_fft_real function.	
*/

	int nag_fft_real(
		int n, 	//the number of data values.
		double x[] // Input: contained in x[j], for j = 0, 1, . . . , n - 1.  Output: the discrete Fourier transform stored in Hermitian form. 
  ); // Given a sequence of n real data values xj, for j = 0, 1, . . . , n - 1, this function calculates their discrete Fourier transform.


/** c06ebc
		calculates the discrete Fourier transforms of a Hermitian sequence of n.

Example1:
	Assume "Data1" Worksheet has 2 columns, the first column contain 7 data.  This piece of code reads
	in a sequence of first column data values and we want to put the result which is the discrete 
	Fourier transforms of a Hermitian sequence of nin the second column.
	
	int n = 7, success;
	//Attach two Datasets to these 2 columns
	Dataset xx("data1",0);
	Dataset aa("data1",1);
	//Because Dataset cannot be the parameter of function, but vector can be.
	vector x = xx;
	success = nag_fft_hermitian(n, x);
	//put the result, the discrete Fourier transforms to "data1" second column.
	if(success == 0)
		aa = x;
	
	
Example2:
	This program reads in a sequence of real data values which is assumed to be a Hermitian sequence of
	complex data values stored in Hermitian form. The input sequence is expanded into a full complex
	sequence and printed alongside the original sequence. The discrete Fourier transform (as computed
	by nag_fft_hermitian) is printed out.  The program then performs an inverse transform using 
	nag_fft_real (c06eac) and nag_conjugate_hermitian (c06gbc), and prints the sequence so obtained 
	alongside the original data values.

void test_nag_fft_hermitian()
{
	int j, n, n2, nj;
	double u[20], v[20], xx[20];
	double x[20] = {0.34907, 0.54890, 0.74776, 0.94459, 1.13850, 1.32850, 1.51370};
	int success;
	n  = 7;
	
	for (j = 0; j<n; j++)
		xx[j] = x[j];

	u[0] = x[0];
	v[0] = 0.0;
	n2 = (n-1)/2;
	for (j = 1; j<=n2; j++)
	{
		nj = n - j;
		u[j] = x[j];
		u[nj] = x[j];
		v[j] = x[nj];
		v[nj] = -x[nj];
	}
	if (n % 2==0)
	{
		u[n2+1] = x[n2+1];
		v[n2+1] = 0.0;
	}
	
	printf("\nOriginal and corresponding complex sequence\n");
	printf("\n Data Real Imag \n\n");
	for (j = 0; j<n; j++)
		printf("%3ld %10.5f %10.5f %10.5f\n", j, x[j], u[j], v[j]);
		
	success = nag_fft_hermitian(n, x);
	
	if(success == 0)
	{
		printf("\nComponents of discrete Fourier transform\n\n");
		for (j = 0; j<n; j++)
			printf("%3ld %10.5f\n", j, x[j]);
			
		nag_fft_real(n, x);
		
		nag_conjugate_hermitian(n, x);
		
		printf("\nOriginal sequence as restored by inverse transform\n");
		printf("\n Original Restored\n\n");
		for (j = 0; j<n; j++)
			printf("%3ld %10.5f %10.5f\n", j, xx[j], x[j]);
	}
	else
		printf("function c06ebc has some problem\n");
}	
	
	The output is following:
	
	Original and corresponding complex sequence

		Data 		Real 		 Imag

	0 	0.34907 	0.34907 	 0.00000
	1 	0.54890 	0.54890 	 1.51370
	2 	0.74776 	0.74776 	 1.32850
	3 	0.94459 	0.94459  	 1.13850
	4 	1.13850	 	0.94459 	-1.13850
	5 	1.32850 	0.74776 	-1.32850
	6 	1.51370 	0.54890 	-1.51370

	Components of discrete Fourier transform

	0	 1.82616
	1 	 1.86862
	2 	-0.01750
	3 	 0.50200
	4 	-0.59873
	5 	-0.03144
	6 	-2.62557

	Original sequence as restored by inverse transform

		Original 	Restored
		
	0 	0.34907 	0.34907
	1 	0.54890 	0.54890
	2 	0.74776 	0.74776
	3 	0.94459 	0.94459
	4 	1.13850 	1.13850
	5 	1.32850 	1.32850
	6 	1.51370 	1.51370


Return:
	The function returns NAG error code or 0 if no error.

	137: At least one of the prime factors of n is greater than 19.
	138: n has more than 20 prime factors.
	12:  On entry, n must not be less than or equal to 1: n = _value_.

	successfully call of the function nag_fft_hermitian function.
	
*/

	int nag_fft_hermitian(
		int n,	// the number of data values.
		double x[] // Input:the number of data values.  Output: the components of the discrete Fourier transforms. 
  ); // Given a Hermitian sequence of n complex data values z[j] (i.e., a sequence such that z0 is real and z(n-j) is the complex conjugate of z[j], for j = 1, 2, . . . , (n - 1), this function calculates their discrete Fourier transform.


/**	c06ecc
		calculates the discrete Fourier transforms of a sequence of n complex data values.	

Example1:
	Assume "Data1" Worksheet has 4 columns, the first two columns contain 7 data each.  The first
	column is the real part of the original complex data and second column is the imag part of 
	original complex data.  This piece of code reads in a sequence of these 7 complex data values
	and put the result which is the discrete Fourier transforms of the original complex data values
	to the third and fourth column.  The third column is the real part and the fourth column is the
	imag part.
	
	int n = 7, success;
	//Attach two Datasets to these 2 columns
	Dataset xx("data1",0);
	Dataset yy("data1",1);
	Dataset aa("data1",2);
	Dataset bb("data1",3);
	//Because Dataset cannot be the parameter of function, but vector can be.
	vector x = xx, y = yy;
	success = nag_fft_complex(n, x, y);
	//put the result back to worksheet "data1", the third column and the fourth column.
	aa = x;
	bb = y;
	
	
Example2:
	This program reads in a sequence of complex data values and prints their discrete 
	Fourier transform.  It then performs an inverse transform using nag_conjugate_complex (c06gcc)
	and nag fft complex, and prints the sequence so obtained alongside the original data values.
	
void test_nag_fft_complex()
{	
	#define NMAX 20
	int j, n ;
	int success;
	double xx[20], yy[20];
	double x[20] = {0.34907, 0.54890, 0.74776, 0.94459, 1.13850, 1.32850, 1.51370};
	double y[20] = {-0.37168, -0.35669, -0.31175, -0.23702, -0.13274, 0.00074, 0.16298}; 	
 	n = 7;

	for (j = 0; j<n; ++j)
	{
		xx[j] = x[j];
		yy[j] = y[j];
	}

	success = nag_fft_complex(n, x, y);

	printf("\nComponents of discrete Fourier transforms\n\n");
	printf(" Real Imag\n\n");
	for (j = 0; j<n; ++j)
		printf("%3ld %10.5f %10.5f\n", j, x[j], y[j]);

	nag_conjugate_complex(n, y);

	nag_fft_complex(n, x, y);
	
	nag_conjugate_complex(n, y);
	
	printf("\nOriginal sequence as restored byinverse transform\n");
	printf("\n Original Restored\n");
	printf(" Real Imag Real Imag\n\n");
	for (j = 0; j<n; ++j)
		printf("%3ld %10.5f %10.5f %10.5f %10.5f\n", j, xx[j], yy[j], x[j], y[j]);	
}

	The output is following:
	
	Components of discrete Fourier transform

		 Real 			 Imag
		 
	0 	 2.48361 		-0.47100
	1 	-0.55180 	 	 0.49684
	2 	-0.36711 		 0.09756
	3 	-0.28767 		-0.05865
	4 	-0.22506 		-0.17477
	5 	-0.14825 		-0.30840
	6 	 0.01983 		-0.56496
	
	Original sequence as restored byinverse transform
		     
		      Original 				  Restored
		Real 		  Imag 		  Real 		  Imag
		
	0 	0.34907 	-0.37168 	0.34907 	-0.37168
	1 	0.54890 	-0.35669 	0.54890 	-0.35669
	2 	0.74776 	-0.31175 	0.74776 	-0.31175
	3 	0.94459 	-0.23702 	0.94459 	-0.23702
	4 	1.13850 	-0.13274 	1.13850  	-0.13274
	5 	1.32850 	 0.00074 	1.32850 	 0.00074
	6 	1.51370 	 0.16298 	1.51370 	 0.16298

Return:
	The function returns NAG error code or 0 if no error.
	
	137: At least one of the prime factors of n is greater than 19.
	138: n has more than 20 prime factors.
	
	successfully call of the nag_fft_complex function.	
*/

	int nag_fft_complex(
		int n,	//the number of data values  
		double x[],	// Input:contained in x[j] , the real part of z[j], for j = 0, 1, . . ., n . 1.  Output: the real parts a[k] of the components of the discrete Fourier transform. a[k] is contained in x[k], for k = 0, 1, . . ., n . 1.   
		double y[]	// Input: contain y[j] , the imaginary part of z[j], for j = 0, 1, . . . , n . 1.  Output: the imaginary parts b[k] of the components of the discrete Fourier transform. b[k] is contained in y[k], for k = 0, 1, . . ., n . 1.
  ); // Given a sequence of n complex data values z[j], for j = 0, 1, . . . , n . 1, this function calculates their discrete Fourier transform.

    
/**	c06ekc
		calculates the circular convolution or correlation of two real vectors of period n.
Example1:
	Assume "Data1" Worksheet has 4 columns, the first two columns contain 9 data each.  This piece 
	of code calculates the circular convolution or correlation of two real vectors of period 9 and
	put the result the circular convolution to the third column and correlation to the fourth column.

	int n = 9;
	//Attach four Datasets to these 4 columns
	Dataset dxa("data1",0);
	Dataset dya("data1",1);
	Dataset dxb("data1",2);
	Dataset dyb("data1",3);
	//Dataset cannot be the parameter of function, but vector can be.
	vector xa = dxa, ya = dya, xb = dxa, yb = dya;
	
	nag_convolution_real(NAG_Convolution, n, xa, ya);
	nag_convolution_real(Nag_Correlation, n, xb, yb);
	

⌨️ 快捷键说明

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