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

📄 bianyuanjiancedib.cpp

📁 VC++图像处理程程序设计配套光盘的第六章锐化处理及边缘检测程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		Template[5]=-1.0;
		Template[6]=-1.0;
		Template[7]=-1.0;
		Template[8]=-1.0;
		Templat24bit( p_temp1,DibWidth,height,tempH,tempW,tempMX,tempMY,Template,tempC);
		memcpy(p_data,p_temp1,height*DibWidth);  // 复制处理后的图像
	    delete []p_temp1;  //删除暂时分配内存
	}
}

///***************************************************************/           
/*函数名称:Guasslaplacian()                                      
/*函数类型:void                                    
/*功能:用高斯拉普拉斯算子对图像边缘检测。            
/***************************************************************/ 
void BianYuanJianCeDib::Guasslaplacian()
{
	int tempH;  //模板高度
	int tempW;  //模板宽度
	float tempC;  //模板系数
	int tempMY;   //模板中心元素Y坐标
	int tempMX;   //模板中心元素X坐标
	float Template[25];   //模板数组
	LPBYTE  p_data;     //原图数据区指针
	int wide,height;    //原图长、宽
	p_data=this->GetData ();
    wide=this->GetWidth ();
    height=this->GetHeight ();
	if (m_pBitmapInfoHeader->biBitCount<9)		//灰度图像
	{        
		LPBYTE   temp1=new BYTE[wide*height];    //新图像缓冲区
        LPBYTE   temp2=new BYTE[wide*height];    //新图像缓冲区
        //拷贝原图像到缓存图像
		memcpy( temp1,p_data,wide*height);
        memcpy( temp2,p_data,wide*height);
		//设置Guasslaplacian模板参数
		tempW=5;
		tempH=5;
		tempC=0.25;
		tempMY=4;
		tempMX=4;
		Template[0]=-2.0;
        Template[1]=-4.0;
		Template[2]=-4.0;
		Template[3]=-4.0;
		Template[4]=-2.0;
		Template[5]=-4.0;
		Template[6]=0.0;
		Template[7]=8.0;
		Template[8]=0.0;
		Template[9]=-4.0;
		Template[10]=-4.0;
		Template[11]=8.0;
		Template[12]=24.0;
		Template[13]=8.0;
		Template[14]=-4.0;
		Template[15]=-4.0;
		Template[16]=0.0;
		Template[17]=8.0;
		Template[18]=0.0;
		Template[19]=-4.0;
		Template[20]=-2.0;
		Template[21]=-4.0;
		Template[22]=-4.0;
		Template[23]=-4.0;
		Template[24]=-2.0;
		//调用Templat()函数
		Templat( temp1,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        memcpy(p_data, temp1,wide*height);   //复制处理后的图像
		delete  temp1;         //释放内存
		delete  temp2;
	}
	else	//24位彩色
	{
	    int DibWidth;
	    DibWidth=this->GetDibWidthBytes();   //取得原图的每行字节数
        BYTE *p_temp1=new BYTE[height*DibWidth];
		//将缓存中的图像复制到原图数据区
		memcpy(p_temp1,p_data,DibWidth*height);
		//设置Guasslaplacian模板参数
		tempW=5;
		tempH=5;
		tempC=0.25;
		tempMY=4;
		tempMX=4;
		Template[0]=-2.0;
        Template[1]=-4.0;
		Template[2]=-4.0;
		Template[3]=-4.0;
		Template[4]=-2.0;
		Template[5]=-4.0;
		Template[6]=0.0;
		Template[7]=8.0;
		Template[8]=0.0;
		Template[9]=-4.0;
		Template[10]=-4.0;
		Template[11]=8.0;
		Template[12]=24.0;
		Template[13]=8.0;
		Template[14]=-4.0;
		Template[15]=-4.0;
		Template[16]=0.0;
		Template[17]=8.0;
		Template[18]=0.0;
		Template[19]=-4.0;
		Template[20]=-2.0;
		Template[21]=-4.0;
		Template[22]=-4.0;
		Template[23]=-4.0;
		Template[24]=-2.0;
		//调用Templat24bit()函数
		Templat24bit( p_temp1,DibWidth,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        memcpy(p_data,p_temp1,height*DibWidth);  // 复制处理后的图像
	    delete []p_temp1;  //删除暂时分配内存
	}
}

///***************************************************************/           
/*函数名称:Krisch()                                      
/*函数类型:void                                     
/*功能:用克瑞斯算子对图像边缘检测。            
/***************************************************************/ 
void BianYuanJianCeDib::Krisch()
{
	int tempH;  //模板高度
	int tempW;  //模板宽度
	float tempC;  //模板系数
	int tempMY;   //模板中心元素Y坐标
	int tempMX;   //模板中心元素X坐标
	float Template[9];   //模板数组
	LPBYTE  p_data;     //原图数据区指针
	int wide,height;    //原图长、宽 	 
	p_data=this->GetData ();
    wide=this->GetWidth ();
    height=this->GetHeight ();
	if (m_pBitmapInfoHeader->biBitCount<9)		//灰度图像
	{    
		LPBYTE   temp1=new BYTE[wide*height];    //新图像缓冲区
        LPBYTE   temp2=new BYTE[wide*height];    //新图像缓冲区
        //拷贝原图像到缓存图像
		memcpy( temp1,p_data,wide*height);
        memcpy( temp2,p_data,wide*height);
		//设置Kirsch模板1参数
		tempW=3;
		tempH=3;
		tempC=0.5;
		tempMY=1;
		tempMX=1;
		Template[0]=5.0;
        Template[1]=5.0;
		Template[2]=5.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
        //调用Templat()函数
		Templat( temp1,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //设置Kirsch模板2参数
        Template[0]=-3.0;
        Template[1]=5.0;
		Template[2]=5.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=5.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
		//调用Templat()函数
		Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(int j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
		//拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
        //设置Kirsch模板3参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=5.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=5.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=5.0;
		//调用Templat()函数
	    Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
        //拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
        //设置Kirsch模板4参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=5.0;
		Template[6]=-3.0;
		Template[7]=5.0;
		Template[8]=5.0;
		//调用Templat()函数
		Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
		//拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
		//设置Kirsch模板5参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=5.0;
		Template[7]=5.0;
		Template[8]=5.0;
		//调用Templat()函数
		Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
		//拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
		//拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
		//设置Kirsch模板6参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=5.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=5.0;
		Template[7]=5.0;
		Template[8]=-3.0;
		//调用Templat()函数
		Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
		//拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
		//设置Kirsch模板7参数
        Template[0]=5.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=5.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=5.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
		//调用Templat()函数
		Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
		//拷贝原图像到缓存图像2中
        memcpy( temp2,p_data,wide*height);
		//设置Kirsch模板8参数
        Template[0]=5.0;
        Template[1]=5.0;
		Template[2]=-3.0;
		Template[3]=5.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
		//调用Templat()函数
	    Templat( temp2,wide,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<wide;i++)
				if( temp2[j*wide+i]> temp1[j*wide+i])
					 temp1[j*wide+i]= temp2[j*wide+i];
		memcpy(p_data, temp1,wide*height);   //复制处理后的图像
		delete  temp1;
		delete  temp2;
	}
	else	//24位彩色
	{	    
	    int DibWidth;    //原图长、宽    	
	    DibWidth=this->GetDibWidthBytes();   //取得原图的每行字节数
        BYTE *p_temp1=new BYTE[height*DibWidth];
		BYTE *p_temp2=new BYTE[height*DibWidth];
		 //将缓存中的图像复制到原图数据区
		memcpy(p_temp1,p_data,DibWidth*height);
		memcpy(p_temp2,p_data,DibWidth*height);
		//设置Kirsch模板1参数
		tempW=3;
		tempH=3;
		tempC=0.5;
		tempMY=1;
		tempMX=1;
		Template[0]=5.0;
        Template[1]=5.0;
		Template[2]=5.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
		Templat24bit(p_temp1,DibWidth,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //设置Kirsch模板2参数
        Template[0]=-3.0;
        Template[1]=5.0;
		Template[2]=5.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=5.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
		Templat24bit(p_temp2,DibWidth,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(int j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
		//拷贝原图像到缓存图像2中
        memcpy(p_temp2,p_data,DibWidth*height);
        //设置Kirsch模板3参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=5.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=5.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=5.0;
		Templat24bit(p_temp2,DibWidth,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
		//拷贝原图像到缓存图像2中
        memcpy(p_temp2,p_data,DibWidth*height);
        //设置Kirsch模板4参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=5.0;
		Template[6]=-3.0;
		Template[7]=5.0;
		Template[8]=5.0;
		Templat24bit(p_temp2,DibWidth,height,tempH,tempW,tempMX,tempMY,Template,tempC);
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
		//拷贝原图像到缓存图像2中
        memcpy(p_temp2,p_data,DibWidth*height);
		//设置Kirsch模板5参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=-3.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=5.0;
		Template[7]=5.0;
		Template[8]=5.0;
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
		//拷贝原图像到缓存图像2中
        memcpy(p_temp2,p_data,DibWidth*height);
		//设置Kirsch模板6参数
        Template[0]=-3.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=5.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=5.0;
		Template[7]=5.0;
		Template[8]=-3.0;
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
		//拷贝原图像到缓存图像2中
        memcpy(p_temp2,p_data,DibWidth*height);
		//设置Kirsch模板7参数
        Template[0]=5.0;
        Template[1]=-3.0;
		Template[2]=-3.0;
		Template[3]=5.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=5.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
       //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
		//拷贝原图像到缓存图像2中
        memcpy(p_temp2,p_data,DibWidth*height);
		//设置Kirsch模板8参数
        Template[0]=5.0;
        Template[1]=5.0;
		Template[2]=-3.0;
		Template[3]=5.0;
		Template[4]=0.0;
		Template[5]=-3.0;
		Template[6]=-3.0;
		Template[7]=-3.0;
		Template[8]=-3.0;
        //求两幅缓存图像的最大值
		for(j=0;j<height;j++)
			for(int i=0;i<DibWidth;i++)
				if( p_temp2[j*DibWidth+i]> p_temp1[j*DibWidth+i])
					 p_temp1[j*DibWidth+i]= p_temp2[j*DibWidth+i];
	    memcpy(p_data,p_temp1,height*DibWidth);  // 复制处理后的图像
	    delete []p_temp1;  //删除暂时分配内存
	    delete []p_temp2;  //删除暂时分配内存
	}
}

⌨️ 快捷键说明

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