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

📄 matrixdata.h

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

	/**
			Get a subset of this matrix specified by 0 based column and row indices.
		Example:
			matrix m1, m2;
			m1.SetSize( 10, 10 );
			m1.GetSubMatrix( m2, 5, -1, 5 ); // Copy lower right quarter of matrix m1 into matrix m2
			ASSERT( m2.GetNumCols()==5 );
			ASSERT( m2.GetNumRows()==5 );
		Parameters: 
			mbTarget=Matixbase derived object containing returned matrixbase subset
			c1=Begining column index, default is 0 (0 based offset) 
			c2=Ending column index, (inclusive) default -1 is GetNumCols -1 (0 based offset) 
			r1=Begining row index, default is 0 (0 based offset) 
			r2=Ending row index, (inclusive) default -1 is GetNumRows -1 (0 based offset)
		Return:
		 	Returns TRUE on successful exit and FALSE on failure.
	*/
	BOOL	GetSubMatrix( matrixbase& mbTarget, int c1 = 0, int c2 = -1, int r1 = 0, int r2 = -1); // -1 means to last col/row

	/**
			Set a subset of this matrix specified by 0 based column and row indices. The source
			and target matrices can have different types and different dimensions but the target
			matrix is never resized even if the source matrix is larger than the target.
		Example:
			Matrix mat1("Matrix1");
			Matrix mat2("Matrix2");			
			mat2.SetSubMatrix(mat1, 10, 10);
			
			matrix<double> mtxSrc = { {1.1,2.1}, {3.1,4.2} };
			matrix<int> mtxDest = 	 { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
									   
			mtxDest.SetSubMatrix(mtxSrc, 0, 0);
		
			ASSERT(mtxDest[0][0] == 1);
			ASSERT(mtxDest[0][1] == 2);
			ASSERT(mtxDest[0][2] == 0);
			ASSERT(mtxDest[0][3] == 0);
			
			ASSERT(mtxDest[1][0] == 3);
			ASSERT(mtxDest[1][1] == 4);
			ASSERT(mtxDest[1][2] == 0);
			ASSERT(mtxDest[1][3] == 0);
		
			ASSERT(mtxDest[2][0] == 0);
			ASSERT(mtxDest[2][1] == 0);
			ASSERT(mtxDest[2][2] == 0);
			ASSERT(mtxDest[2][3] == 0);
		
			ASSERT(mtxDest[3][0] == 0);
			ASSERT(mtxDest[3][1] == 0);
			ASSERT(mtxDest[3][2] == 0);
			ASSERT(mtxDest[3][3] == 0);
		Parameters: 
			mbSource = matixbase oject containing the subset to set
			c1 = Begining column index in the target matrix, default is 0 (0 based offset) 
			r1 = Begining row index in the target matrix, default is 0 (0 based offset) 
		Return:
		 	Returns TRUE on successful exit and FALSE on failure.
	*/
	BOOL	SetSubMatrix(matrixbase& mbSource, int c1 = 0, int r1 = 0);
	
	/**
			Copies a specified range from a worksheet to a matrix dynamically
			resizing the matrix as needed.
		Example:
			// Assumes Data1 worksheet and Matrix1 matrix exist in Origin
			Worksheet wks("Data1");
			Matrix mat1("Matrix1");
			BOOL bRet = TRUE;
			if(mat1 && wks)
				bRet = mat1.CopyFromWks(wks); //Copies the whole wks to m1
		Parameters: 
			wksSource=Source worksheet from which data is copied
			c1=Begining column index, default is 0 (0 based offset) 
			c2=Ending column index, (inclusive) default -1 is GetNumCols -1 (0 based offset) 
			r1=Begining row index, default is 0 (0 based offset) 
			r2=Ending row index, (inclusive) default -1 is GetNumRows -1 (0 based offset)
		Return:
		 	Returns TRUE on successful exit and FALSE on failure.
	*/
	BOOL	CopyFromWks(Worksheet & wksSource, int c1 = 0, int c2 = -1, int r1 = 0, int r2 = -1); // Copies a specified range from a worksheet to a matrix.

	
	
	
	/**
			Threshold replace for a matrix.
		Example:
			// Assumes Matrix1 exists in Origin and contains some missing values (NANUM)
			Matrix mat1("Matrix1");
			// Change all missing values (NANUM) in Matrix1 to 0 and all other values to missing values
			mat1.Replace( NANUM, 0, MATREPL_TEST_EQUAL | MATREPL_SET_TO_MISSING_VALUE_WHEN_TEST_RESULT_IS_FALSE );
		Parameters: 
			dThresholdVal=Threshold value to compare to cells in matrix
			dReplaceVal=Replacement value to use when decision passes
			wBitwiseOption=Combination of the following bits
				Bit Value Meaning 	                              Group
				0    1    Use Less Than in testing                TEST
				1    2    Use Equal in testing                    TEST
				2    4    Use Greater Than in testing             TEST
				3    8    Use Absolute values in testing          TEST
				4    16   Keep original sign when test is TRUE    ACTION
				5    32   Set to missing value when test is FALSE ACTION
			
			The following are also defined in the header file \OriginC\system\OC_const.h
					MATREPL_TEST_LESSTHAN	= 1,
					MATREPL_TEST_EQUAL		= 2,
					MATREPL_TEST_GREATER	= 4,
					MATREPL_USE_ABSOLUTE_VALUE_IN_TEST	= 8,
					MATREPL_KEEP_ORIGINAL_SIGN_WHEN_TEST_RESULT_IS_TRUE		= 16,
					MATREPL_SET_TO_MISSING_VALUE_WHEN_TEST_RESULT_IS_FALSE	= 32
		Return:
			Returns TRUE on successful exit and FALSE on failure.
	*/
	BOOL	Replace( double dThresholdVal, double dReplaceVal = 0, uint wBitwiseOption = 0 );

	/**
			Get the Real part of a Complex matrix. Causes a runtime error if the
			underlying base type of the matrix is not Complex.
		Examples:
			matrix<complex> mComplex = { 1+2i, 3+4i };
			matrix mReal1, mReal2;
			mComplex.GetReal( mReal1 );  // mReal1 = { 1, 3 };
			printf( "mReal1[0][0]=%g\nmReal1[0][1]=%g", mReal1[0][0], mReal1[0][1] );
			mReal1.GetReal( mReal2 );    // Causes runtime error
		Parameters:
			mReal=Output matrix containing the Real part of this Complex matrix
		Return:
			Returns TRUE on successful exit and FALSE on failure.
		SeeAlso:
			matrixbase::GetImaginary, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex 
	*/
	BOOL	GetReal( matrix &mReal ); // Get the Real part of a Complex matrix.

	/**
			Get the Imaginary part of a Complex matrix. Causes a runtime error if
			the underlying base type of the matrix is not Complex.
		Examples:
			matrix<complex> mComplex = { 1+2i, 3+4i };
			matrix mImag1, mImag2;
			mComplex.GetImaginary( mImag1 );      // mImag1 = { 2, 4 };
			printf( "mImag1[0][0]=%g\nmImag1[0][1]=%g", mImag1[0][0], mImag1[0][1] );
			mImag1.GetImaginary( mImag2 );        // Causes runtime error
		Parameters:
			mImag=Output matrix containing the Imaginary part of this Complex matrix
		Return:
			Returns TRUE on successful exit and FALSE on failure.
		SeeAlso:
			matrixbase::GetReal, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex
	*/
	BOOL	GetImaginary( matrix &mImag ); // Get the Imaginary part of a Complex matrix. 
	
	/**
			Get the phase angle matrix, in radians, of the Complex matrix. Causes
			a runtime error if the underlying base type of the matrix is not Complex.
		Examples:
			matrix<complex> mComplex = { 1+2i, 3+4i };
			matrix mPhase1, mPhase2, mReal = { 1, 3 };
			mComplex.GetPhase( mPhase1 );
			printf( "mPhase1[0][0]=%g\nmPhase1[0][1]=%g", mPhase1[0][0], mPhase1[0][1] );
			mReal.GetPhase( mPhase2 ); // Causes runtime error
		Parameters:
			mPhase=Output matrix containing the phase angle matrix for this Complex matrix
		Return:
			Returns TRUE on successful exit and FALSE on failure.
		SeeAlso:
			matrixbase::GetReal, matrixbase::GetImaginary, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex
	*/
	BOOL	GetPhase( matrix& mPhase ); // Get the phase angle matrix, in radians, of the Complex matrix.

	/**
			Get the amplitude(modulus) of the Complex matrix. Causes a runtime
			error if the underlying base type of the matrix is not Complex.
		Examples:
			matrix<complex> mComplex = { 1+2i, 3+4i };
			matrix mAmplitude1, mAmplitude2, mReal = { 1, 3 };
			mComplex.GetAmplitude( mAmplitude1 );
			printf( "mAmplitude1[0][0]=%g\nmAmplitude1[0][1]=%g", mAmplitude1[0][0], mAmplitude1[0][1] );
			mReal.GetAmplitude( mAmplitude2 ); // Causes runtime error
		Parameters:
			mAmplitude=Output matrix containing amplitude(modulus) matrix for this Complex matrix
		Return:
			Returns TRUE on successful exit and FALSE on failure.
		SeeAlso:
			matrixbase::GetReal, matrixbase::GetImaginary, matrixbase::GetPhase, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex
	*/
	BOOL	GetAmplitude( matrix& mAmplitude ); // Get the amplitude(modulus) of the Complex matrix.

	/**
			Replace this matrix with the Inverse of this matrix. An error is 
			returned if the underlying base type of the matrix is not double.
		Example:
			matrix<double> mA(2,2), mB(2,2), mI(2,2);
			mA[0][0]= 3; mA[0][1]=-2;
			mA[1][0]=-1; mA[1][1]= 1;
			mB = mA;

			mA.Inverse();
		
			// Show mA x mB = mI = | 1 0 |
			//                     | 0 1 |
			mI[0][0]=mA[0][0]*mB[0][0]+mA[0][1]*mB[1][0];
			mI[0][1]=mA[0][0]*mB[0][1]+mA[0][1]*mB[1][1];
			mI[1][0]=mA[1][0]*mB[0][0]+mA[1][1]*mB[1][0];
			mI[1][1]=mA[1][0]*mB[0][1]+mA[1][1]*mB[1][1];
			
			printf( "mA\t\tx\t\tmB\t\t=\t\tmI\n" );
			printf( "| %g %g |\t\t\t| %g %g |\t\t\t| %g %g |\n", mA[0][0], mA[0][1], mB[0][0], mB[0][1], mI[0][0], mI[0][1] );
			printf( "| %g %g |\t\t\t| %g %g |\t\t\t| %g %g |\n", mA[1][0], mA[1][1], mB[1][0], mB[1][1], mI[1][0], mI[1][1] );
		Return:
			Returns 0 on success or one of the following error codes on failure:
				-1=Matrix is not N x N
				-2=Underlying type of matrix is not double
				-3=Can not find the function in the Nag DLL
			Nag Errors:
				11=The column or row size of the matrix is less than 1
				73=System failed to allocate memory
				357=Matrix is singular (it has no inverse)
		SeeAlso:
			matrixbase::GetReal, matrixbase::GetImaginary, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::MakeComplex
	*/
	int		Inverse(); // Replace this matrix with the Inverse of this matrix.

	/**
			Replace this matrix with the Conjugate of this matrix. A runtime error 
			occurs if the underlying base type of this matrix is not double or Complex.
		Example:
			matrix<complex> mA(2,2);
			mA[0][0] = 1+2i; mA[0][1] = 3;
			mA[1][0] = 4-1i; mA[1][1] = -2+2i;
			mA.Conjugate();
			for(int ii = 0; ii < 2; ii++)
			{
				for(int jj = 0; jj < 2; jj++)
					printf("%g + %gi, ",mA[ii][jj].m_re, mA[ii][jj].m_im);
				printf("\n");
				
			}
		Return:
			Returns 0 on success and -1 on failure which occurs if the matrix is empty.	
		SeeAlso:
			matrixbase::GetReal, matrixbase::GetImaginary, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex
	*/
	int		Conjugate(); // Replace this matrix with the Conjugate of this matrix.

	/**
			Make a Complex matrix from two Real matrices (which must have the same
			dimensions).
		Example:
			matrix mA(2,2), mB(2,2);
			matrix<complex> mC(2,2);

			mA[0][0] = 1;			mB[0][0] = -2;
			mA[0][1] = -3;			mB[0][1] = 1;
			mA[1][0] = 4;			mB[1][0] =2;
			mA[1][1] = 5;			mB[1][1] = -3;

			mC.MakeComplex(mA,mB);

			for(int ii = 0; ii < 2; ii++)
				for(int jj = 0; jj < 2; jj++)
					printf("%g + %gi\n",mC[ii][jj].m_re,mC[ii][jj].m_im);
		Parameters:
			mbReal=The matrix containing the Real part
			mbImag=The matrix containing the Imaginary part
		Return:
			Returns 0 on success and -1 on failure.
		SeeAlso:
			matrixbase::CastToInteger, matrixbase::CastToDouble, matrixbase::GetReal, matrixbase::GetImaginary, matrixbase::GetPhase, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse
	*/
	int		MakeComplex(matrixbase & mbReal, matrixbase & mbImag); // Make a Complex matrix from two Real matrices.

	/**
			Sum the columns of this matrix placing the result in a vector. The
			underlying base type of the vector must not be less than the underlying
			base type of the matrix.
		Example:
			matrix<complex> mC = { {1+2i,2+1i,3-5i},
			                       {1+2i,2+2i,7-3i} };
			vector<complex> vC(2);
			mC.SumColumns(vC);
			for(int ii = 0; ii < 3; ii++)
				printf("\t%g+%gi",vC[ii].m_re,vC[ii].m_im);
		Parameters:
			vbSum=Output vector containing the summed columns
		Return:
			Returns 0 on success and -1 on failure.
	*/	    
	int		SumColumns(vectorbase & vbSum); // Sum the columns of this matrix placing the result in a vector.
   
	/**
			Concatenate a matrix to this matrix placing the results in a third
			matrix. Matrices can be concatenated row wise or column wise. All
			three matrices must have the same underlying base type or a runtime
			error will be generated.
		Example:
			int ii, jj, nCols, nRows;
			matrix mSource1 = { {1,2,3}, {4,5,6}, {7,8,9} };
			matrix mSource2 = { {10,11,12}, {12,14,15} };
			matrix mSource3 = { {1,2}, {1,2}, {1,2} };
			matrix mResult;

			mSource1.Concatenate( 1, mSource2, mResult );

			nCols = mResult.GetNumCols();
			nRows = mResult.GetNumRows();
			for(ii = 0; ii < nRows; ii++)
			{
				for(jj = 0; jj < nCols; jj++)
					printf("%g\t", mResult[ii][jj]);
				printf("\n");
			}
			printf("\n\n");
			
			mSource1.Concatenate( 2, mSource3, mResult);

			nCols = mResult.GetNumCols();
			nRows = mResult.GetNumRows();
			for(ii = 0; ii < nRows; ii++)
			{
				for(jj = 0; jj < nCols; jj++)
					printf("%g\t", mResult[ii][jj]);
				printf("\n");
			}
		Parameters:
			nDim=Specifies whether the matrices are concatenated row wise (nDim=1) or column wise (nDim=2)
			mSource=Source matrix that is concatenated to this matrix
			mResult=The matrix resulting from the concatenation
		Return:
			Returns 0 on success or one of the following error codes on failure.
				-1=nDim is not 1 or 2
				-2=The source matrices do not have the same number of columns (when concatenating row wise)
					or rows (when concatenating column wise)
	*/
	int		Concatenate(int nDim, matrixbase & mSource, matrixbase & mResult ); // Concatenate a matrix to this matrix placing the results in a third matrix. 

	/**
			Shift this matrix placing the result in the matrix passed as an argument.
			Shifts can occur row wise or relative to the first dimension (nDim=1),
			column wise or relative to the second dimension (nDim=2), or relative
			to both or the first dimension and then the second dimension (nDim=-1
			default). The result matrix and this matrix can be the same
			(i.e. m1.FFTShift(m1);).
		Example:
			matrix mSource = {{1,2,3},{4,5,6},{7,8,9}};
			matrix mShifted;
			int ii, jj;
			printf("Before shifting:\n");
			for(ii = 0; ii < mSource.GetNumRows(); ii++)
			{
				for(jj = 0; jj < mSource.GetNumCols(); jj++)
					printf("%g\t",mSource[ii][jj]);
				printf("\n");
			}

			mSource.FFTShift(mShifted);
			printf("After shifting for FFT:\n");
			for(ii = 0; ii < mShifted.GetNumRows(); ii++)
			{
				for(jj = 0; jj < mShifted.GetNumCols(); jj++)
					printf("%g\t",mShifted[ii][jj]);
				printf("\n");
			}

			mSource.FFTShift(mShifted, 1);
			printf("After shifting relative to first dimension:\n");

⌨️ 快捷键说明

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