www.pudn.com > Image_segment.rar > Core.h


//Copyright (c) 2004-2005, Baris Sumengen 
//All rights reserved. 
// 
// CIMPL Matrix Performance Library 
// 
//Redistribution and use in source and binary 
//forms, with or without modification, are 
//permitted provided that the following 
//conditions are met: 
// 
//    * No commercial use is allowed.  
//    This software can only be used 
//    for non-commercial purposes. This  
//    distribution is mainly intended for 
//    academic research and teaching. 
//    * Redistributions of source code must 
//    retain the above copyright notice, this 
//    list of conditions and the following 
//    disclaimer. 
//    * Redistributions of binary form must 
//    mention the above copyright notice, this 
//    list of conditions and the following 
//    disclaimer in a clearly visible part  
//    in associated product manual,  
//    readme, and web site of the redistributed  
//    software. 
//    * Redistributions in binary form must 
//    reproduce the above copyright notice, 
//    this list of conditions and the 
//    following disclaimer in the 
//    documentation and/or other materials 
//    provided with the distribution. 
//    * The name of Baris Sumengen may not be 
//    used to endorse or promote products 
//    derived from this software without 
//    specific prior written permission. 
// 
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
//HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
//EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
//NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
//MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
//PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
//CONTRIBUTORS BE LIABLE FOR ANY 
//DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
//EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
//(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
//OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
//DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
//HOWEVER CAUSED AND ON ANY THEORY OF 
//LIABILITY, WHETHER IN CONTRACT, STRICT 
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
//OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
//OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
//POSSIBILITY OF SUCH DAMAGE. 
 
#pragma once 
#ifndef MATHCORE_CORE_H 
#define MATHCORE_CORE_H 
 
 
#include "cimpl.h" 
using namespace CIMPL; 
 
 
#include  
#include  
 
#define PI 3.141592653589793115997963468544185161590576171875 
 
#define SQR(X)  ((X)*(X)) 
#define ROUND(X)  floor((X)+0.5) 
 
 
 
namespace MathCore 
{ 
 
	// Create class specializations 
 
 
	// Eye() goes into the classes... 
	//Eye(int N); 
 
 
	 
	 
	// Core functions 
	 
	 
	template< class T > 
	void Plot(Vector& v, int height = 30); 
 
	template  
	Vector Find(Vector& m); 
	template  
	Vector Find(Matrix& m); 
	template  
	void Find(Matrix& m, Vector& I, Vector& J); 
	 
	void Ind2Sub(int rows, int cols, Vector& ind, Vector& I, Vector& J); 
	 
	Vector Sub2Ind(int rows, int cols, Vector& I, Vector& J); 
	 
	template  
	Vector Cross(Vector& x, Vector& y); 
	template  
	Matrix Cross(Matrix& x, Matrix& y);  
	template  
	Matrix Cross(Matrix& x, Matrix& y, int dimension);  
	 
	template  
	Vector CumSum(Vector& m); 
	template  
	Matrix CumSum(Matrix& m); 
	template  
	Matrix CumSum(Matrix& m, int dimension); 
	template  
	Vector& CumSumI(Vector& m); 
	template  
	Matrix& CumSumI(Matrix& m); 
	template  
	Matrix& CumSumI(Matrix& m, int dimension); 
 
	template  
	Vector CumProd(Vector& m); 
	template  
	Matrix CumProd(Matrix& m); 
	template  
	Matrix CumProd(Matrix& m, int dimension); 
	template  
	Vector& CumProdI(Vector& m); 
	template  
	Matrix& CumProdI(Matrix& m); 
	template  
	Matrix& CumProdI(Matrix& m, int dimension); 
 
	template  
	Matrix Diag(Vector& m); 
	template  
	Matrix Diag(Vector& m, int k); 
	template  
	Vector Diag(Matrix& m); 
	template  
	Vector Diag(Matrix& m, int k); 
 
	template  
	Matrix FlipLR(Matrix& m); 
	template  
	Matrix& FlipLRI(Matrix& m); 
 
	template  
	Matrix FlipUD(Matrix& m); 
	template  
	Matrix& FlipUDI(Matrix& m); 
 
	template  
	Vector Reverse(Vector& m); 
	template  
	Vector& ReverseI(Vector& m); 
 
	template  
	Matrix Rot90(Matrix& m); 
 
	template  
	Matrix Rot90(Matrix& m, int k); 
 
	//Kron(); 
 
	template  
	Vector Maximum(Matrix& m); 
	template  
	T Maximum(Vector& m); 
	 
	template  
	Vector Minimum(Matrix& m); 
	template  
	T Minimum(Vector& m); 
 
	template  
	Vector Mean(Matrix& m); 
	template  
	double Mean(Vector& m); 
	 
	template  
	inline void Swap(T& a, T& b)
	{
		T temp = a;
		a = b;
		b = temp;
	}
 
	template  
	Vector Median(Matrix& m); 
	template  
	T Median(Vector& m); 
 
	template  
	Vector Std(Matrix& m); 
	template  
	double Std(Vector& m); 
 
	template  
	Vector Var(Matrix& m); 
	template  
	double Var(Vector& m); 
 
 
	template  
	Vector Sum(Matrix& m); 
	template  
	Vector Sum(Matrix& m, int dimension); 
	template  
	T Sum(Vector& m); 
 
	 
	template  
	Vector Prod(Matrix& m); 
	template  
	Vector Prod(Matrix& m, int dimension); 
	template  
	T Prod(Vector& m); 
 
	template  
	Vector Diff(Vector& m); 
	template  
	Matrix Diff(Matrix& m); 
 
	template  
	Matrix RepMat(Matrix& m, int M, int N); 
	 
	template  
	Matrix Reshape(Matrix& m, int M, int N); 
	template  
	Matrix Reshape(Vector& m, int M, int N); 
	 
	template  
	Vector& QuickSort(Vector& m); 
	 
	template  
	Vector Sort(Vector& m); 
	template  
	Matrix Sort(Matrix& m, int dimension); 
	template  
	Matrix Sort(Matrix& m); 
	template  
	Vector& SortI(Vector& m); 
	template  
	Matrix& SortI(Matrix& m, int dimension); 
	template  
	Matrix& SortI(Matrix& m); 
	//SortRows(); needed... 
	// 
	// 
	//FreqSpace(); 
	Vector LinSpace(double x, double y, int N); 
	Vector LinSpace(double x, double y); 
 
	Vector LogSpace(double x, double y, int N); 
	Vector LogSpace(double x, double y); 
 
	template  
	void MeshGrid(Vector& x, Vector& y, Matrix& X, Matrix& Y); 
	 
	 
	Matrix& RandN(Matrix& m); 
	Vector& RandN(Vector& m); 
	Matrix& RandN(Matrix& m); 
	Vector& RandN(Vector& m); 
 
 
 
 
	int NextPow2(int n); 
	 
 
	template  
	Vector Abs(Vector& m); 
	template  
	Vector& AbsI(Vector& m); 
 
	template  
	Matrix Abs(Matrix& m); 
	template  
	Matrix& AbsI(Matrix& m); 
	 
	//Abs(); 
	//Angle(); 
 
	// OTHER 
	 
	template  
	Vector Floor(Vector& m); 
	template  
	Matrix Floor(Matrix& m); 
 
	template  
	Vector Ceil(Vector& m); 
	template  
	Matrix Ceil(Matrix& m); 
	 
	template  
	Vector Fix(Vector& m); 
	template  
	Matrix Fix(Matrix& m); 
 
	template  
	Vector Round(Vector& m); 
	template  
	Matrix Round(Matrix& m); 
 
	//template  
	//Vector Mod(Vector& m); 
	//template  
	//Matrix Mod(Matrix& m); 
 
	//template  
	//Vector Rem(Vector& m); 
	//template  
	//Matrix Rem(Matrix& m); 
 
 
	template  
	Vector UnitScale(Vector& m); 
	template  
	Matrix UnitScale(Matrix& m); 
	 
	template  
	Vector& UnitScaleI(Vector& m); 
	template  
	Matrix& UnitScaleI(Matrix& m); 
 
	template  
	Vector ImageScale(Vector& m); 
	template  
	Matrix ImageScale(Matrix& m); 
 
	template  
	Vector& ImageScaleI(Vector& m); 
	template  
	Matrix& ImageScaleI(Matrix& m); 
 
	 
 
 
	template  
	Vector Sign(Vector& m); 
	template  
	Matrix Sign(Matrix& m); 
	 
	template  
	Vector Gradient(Vector& m); 
	template  
	void Gradient(Matrix& m, Matrix& X, Matrix& Y); 
 
	template  
	Matrix Divergence(Matrix& u, Matrix& v); 
 
	template  
	Vector Del2(Vector& m); 
	template  
	Matrix Del2(Matrix& m); 
 
	 
	template  
	Vector CircShift(Vector& m, int shift); 
	template  
	Matrix CircShift(Matrix& m, int rshift, int cshift); 
 
	template  
	Vector FFTShift(Vector& m); 
	template  
	Matrix FFTShift(Matrix& m); 
	 
 
	template  
	Vector IFFTShift(Vector& m); 
	template  
	Matrix IFFTShift(Matrix& m); 
 
 
	 
	 
	 
	 
	 
	 
	 
	 
};	 
	 
	 
	 
	 
#include "Core.inl" 
 
 
 
 
 
 
 
 
 
 
#endif