www.pudn.com > Imagepro.rar > ImgProlib.H


// ****************************************************************************** 
// *                图象处理算法库 
// * ---------------------------------------------------------------------------- 
#ifndef IMGPRO2D_H
#define IMGPRO2D_H 
// * ---------------------------------------------------------------------------- 
// * C++ File:       imgprolib.cpp 
// * Header File:	 imgProlib.h 
// * 
// * Description:     
// *     The class of "IMAGE2D" has several operations curently:  
// * 
// *	   ReadPGM2D()          -- read the binary PGM 2D image file 
// * 
// *       GaussSmooth()        -- smooth the image with Gaussian smoothing filter 
// *       FlattenHistogram()   -- equalize the hisrogram of the input image 
// * 
// *    Edge Detector  
// *	   SobelEdgeDetector()  -- Edge detection with Sobel operator 
// *       CannyEdgeDetector()  -- The first drivative of Guaussian edge detector 
// * 
// *    Thresholding   
// *       SimpleThresholding() -- One threshold is given as an input parameter 
// *       SimpleDoubleThresholding() -- Up and down thresholds are given as two input parameters 
// *       GlobalThresholding() -- Threshold is selected by top P% of the pixels 
// * 
// *       Thinning()           -- Thin the edges after thresholding 
// *       HoughTransform()     -- Hough transform with polar form of the line 
// *       LineFitting()        -- Line fitting (Peak fitting) 
// * 
// *   Image tools          
// *       ClearImage()         -- Clear image to be 0 
// *       NegativeImage()      -- Make the image to be negative image 
// *       FlipImage()          -- Filp the image along the X axis  
// *       CopyImage()          -- Copy one image to another image    
// *       BlendImage()         -- Combine two images into one image 
// ****************************************************************************** 

#define PI           3.1415926 
#define e            2.7182818
#define ZOOMIN       100      // For saving space so convert float to int
#define _INT_SQRT(a, b)    (int)(sqrt((double)(a * a + b * b)) + 0.5f)  // For saving space

#define LinePixel 255
#define BackgdPixel 0
#define _DT(data, i, j)    data[(i) * width + (j)] 
//结构体的定义 
enum DIRECTION {eLEFTtoRIGHT,eTOPtoBOTTOM}; 
//搜索窗口的参数设置 
typedef struct SCOUTWNDPARMS 
{ 
    BOOL fMakeUserHitOKToScout;//用户搜索初始化标志,如果其数值是TRUE,利用对话框初始化搜索窗口,其缺省值是FALSE。  
	int iWindowWidth;//搜索窗口的宽度(inpixels) 
	int iWindowHeight;//搜索窗口的高度(inpixels) 
	DIRECTION diScout;//搜索窗口的滑动方向,缺省值为left-right,top-bottom 
}m_Parms;//定义搜索窗口参数; 
////搜索窗口的状态参数设置 
typedef struct SCOUTSTATUS 
{ 
	//int iBasDolWidthMx; //BasicDollar width max,inpixels。 
    //int iBasDolWidthMi; //BasicDollar width min,inpixels。 
	//BOOL iBasDolWidthMxIs;//基元的搜索尺寸最大的状态判断 
    //BOOL iBasDolWidthMiIs;//基元的搜索尺寸最小的状态判断 
    int x;  
	int y; //窗口的左上角的坐标位置,相对影像的其左上角点的x,y坐标 
	int nHistogramType;//0表示灰度梯度方向直方图,1表示灰度直方图,2表示灰度梯度幅度直方图 
    BOOL fBeginScout;//开始搜索标记 
	//BOOL fScoutGDHistogram;//搜索到有两个主峰的灰度梯度方向直方图的标记,TRUE表明搜索到此类直方图,为缺省值 
	//BOOL fScoutGrayHistogram;//搜索到有一个主峰的灰度直方图的标记,TRUE表明已搜到,为缺省值 
	//BOOL fScoutGAHistogram;//搜索到有一个非零主峰的灰度梯度幅度直方图的标记。TRUE表明已搜到,为缺省值 
    BOOL fScoutBasicDollar;//搜索到基元的标记,TRUE表明搜索到基元,为缺省值。 
    UINT wNumPixelsAllocated;//分配像素缓存 
}m_ScoStatus;//SCOUTSTATUS结构,定义搜索窗口当前状态; 
 
 
//--- CLASS IMAGE2D -----
class IMAGE2D
{
public: 
	BOOL Write(CFile* pFile); 
	 
	void RoadEdgeAffirm(unsigned char *SlipWinData); 
 
	IMAGE2D() {input_data = NULL; output_data = NULL; } 
	~IMAGE2D()   		   // De-allocate IMAGE2D.
		{
			delete input_data;
			delete output_data;
		}
   //公共变量
    int width;
	int height;
	int gray_level; 
 
	unsigned int * histogram; 
    unsigned char * input_data; 
	unsigned char * output_data; 
	int *GrayLevel; 
	unsigned char *gray; 
	double *x; 
	double *y; 
	int m;//直方图峰顶的个数 
	int graylevel,gray_level1,gray_level2;//直方图背景的灰度级最大值和目标的灰度级最小值 
    int ScoutWndWidth,ScoutWndHeight;//搜索窗口的宽度和高度 
 
	//灰度直方图对应的变量 
 
	int low0,high0; 
	double p1,p2;//p1,p2分别表示背景和目标占图像总面积的百分比,0 dmax) 
        dmax = a[i]; 
        return dmax; 
	} 
	 
	double min_element(double *a, int n) 
	{ 
		int i;//,i_dmin 
        double dmin = a[0]; 
        for( i = 1; i < n; i++) 
        if (a[i] < dmin) 
        dmin = a[i]; 
        return dmin; 
	//	return i_dmin; 
	} 
	//数组元素求和 
 
    double sum_element( double *A, int n )    
	{ 
		double sum=0, C=0, Y, T; 
        for (int i=0; i