本文主要是介绍高斯拉普拉斯锐化(边缘检测)vc实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
高斯拉普拉斯锐化(边缘检测)vc实现 -LoG锐化,边缘检测。
void CSDIELSView::OnSharpeningGaussianAndLaplace(){
//程序编制:李立宗 lilizong@gmail.com
//2012-8-12if(myImage1.IsNull())OnOpenResourceFile();if(!myImage2.IsNull())myImage2.Destroy();if(myImage2.IsNull()){myImage2.Create(myImage1.GetWidth(),myImage1.GetHeight(),24,0);}//COLORREF pixel; int maxY = myImage1.GetHeight();int maxX=myImage1.GetWidth();byte* pRealData;byte* pRealData2;pRealData=(byte*)myImage1.GetBits();pRealData2=(byte*)myImage2.GetBits();int pit=myImage1.GetPitch();int pit2=myImage2.GetPitch();//需要注意,pit和pit2的值并不一样,所以如果使用一个值,会导致不同的结果出现//CString str;//str.Format(TEXT("%d"),pit);//MessageBox(str);//str.Format(TEXT("%d"),pit2);//MessageBox(str);int bitCount=myImage1.GetBPP()/8;int bitCount2=myImage2.GetBPP()/8;int tempR,tempG,tempB;float temp,tempX,tempY;//int M[3][3]={{1,2,1},{2,4,2},{1,2,1}};int M[5][5]={{-2,-4,-4,-4,-2},{-4,0,8,0,-4},{-4,8,24,8,-4},{-4,0,8,0,-4},{-2,-4,-4,-4,-2}};int sum=0;for(int i=0;i<3;i++)for(int j=0;j<3;j++)sum=sum+M[i][j];// tempR=tempG=tempG=0;//说明:将生产的图像作为24位图处理。for (int y=2; y<maxY-2; y++) {for (int x=2; x<maxX-2; x++) {tempR=*(pRealData+pit*(y-2)+(x-2)*bitCount)*M[0][0]+*(pRealData+pit*(y-2)+(x-1)*bitCount)*M[0][1]+*(pRealData+pit*(y-2)+(x)*bitCount)*M[0][2]+*(pRealData+pit*(y-2)+(x+1)*bitCount)*M[0][3]+*(pRealData+pit*(y-2)+(x+2)*bitCount)*M[0][4]+ *(pRealData+pit*(y-1)+(x-2)*bitCount)*M[1][0]+*(pRealData+pit*(y-1)+(x-1)*bitCount)*M[1][1]+*(pRealData+pit*(y-1)+(x)*bitCount)*M[1][2]+*(pRealData+pit*(y-1)+(x+1)*bitCount)*M[1][3]+*(pRealData+pit*(y-1)+(x+2)*bitCount)*M[1][4]+ *(pRealData+pit*(y)+(x-2)*bitCount)*M[2][0]+*(pRealData+pit*(y)+(x-1)*bitCount)*M[2][1]+*(pRealData+pit*(y)+(x)*bitCount)*M[2][2]+*(pRealData+pit*(y)+(x+1)*bitCount)*M[2][3]+*(pRealData+pit*(y)+(x+2)*bitCount)*M[2][4]+*(pRealData+pit*(y+1)+(x-2)*bitCount)*M[3][0]+*(pRealData+pit*(y+1)+(x-1)*bitCount)*M[3][1]+*(pRealData+pit*(y+1)+(x)*bitCount)*M[3][2]+*(pRealData+pit*(y+1)+(x+1)*bitCount)*M[3][3]+*(pRealData+pit*(y+1)+(x+2)*bitCount)*M[3][4] +*(pRealData+pit*(y+2)+(x-2)*bitCount)*M[4][0]+*(pRealData+pit*(y+2)+(x-1)*bitCount)*M[4][1]+*(pRealData+pit*(y+2)+(x)*bitCount)*M[4][2]+*(pRealData+pit*(y+2)+(x+1)*bitCount)*M[4][3]+*(pRealData+pit*(y+2)+(x+2)*bitCount)*M[4][4];tempR=abs(tempR);if(tempR>255)tempR=255;if(bitCount==1){tempG=tempR;tempB=tempR;}else{tempG=*(pRealData+pit*(y-2)+(x-2)*bitCount+1)*M[0][0]+*(pRealData+pit*(y-2)+(x-1)*bitCount+1)*M[0][1]+*(pRealData+pit*(y-2)+(x)*bitCount+1)*M[0][2]+*(pRealData+pit*(y-2)+(x+1)*bitCount+1)*M[0][3]+*(pRealData+pit*(y-2)+(x+2)*bitCount+1)*M[0][4]+ *(pRealData+pit*(y-1)+(x-2)*bitCount+1)*M[1][0]+*(pRealData+pit*(y-1)+(x-1)*bitCount+1)*M[1][1]+*(pRealData+pit*(y-1)+(x)*bitCount+1)*M[1][2]+*(pRealData+pit*(y-1)+(x+1)*bitCount+1)*M[1][3]+*(pRealData+pit*(y-1)+(x+2)*bitCount+1)*M[1][4]+ *(pRealData+pit*(y)+(x-2)*bitCount+1)*M[2][0]+*(pRealData+pit*(y)+(x-1)*bitCount+1)*M[2][1]+*(pRealData+pit*(y)+(x)*bitCount+1)*M[2][2]+*(pRealData+pit*(y)+(x+1)*bitCount+1)*M[2][3]+*(pRealData+pit*(y)+(x+2)*bitCount+1)*M[2][4]+*(pRealData+pit*(y+1)+(x-2)*bitCount+1)*M[3][0]+*(pRealData+pit*(y+1)+(x-1)*bitCount+1)*M[3][1]+*(pRealData+pit*(y+1)+(x)*bitCount+1)*M[3][2]+*(pRealData+pit*(y+1)+(x+1)*bitCount+1)*M[3][3]+*(pRealData+pit*(y+1)+(x+2)*bitCount+1)*M[3][4] +*(pRealData+pit*(y+2)+(x-2)*bitCount+1)*M[4][0]+*(pRealData+pit*(y+2)+(x-1)*bitCount+1)*M[4][1]+*(pRealData+pit*(y+2)+(x)*bitCount+1)*M[4][2]+*(pRealData+pit*(y+2)+(x+1)*bitCount+1)*M[4][3]+*(pRealData+pit*(y+2)+(x+2)*bitCount+1)*M[4][4];tempG=abs(tempG);if(tempG>255)tempG=255;///tempB=*(pRealData+pit*(y-2)+(x-2)*bitCount+2)*M[0][0]+*(pRealData+pit*(y-2)+(x-1)*bitCount+2)*M[0][1]+*(pRealData+pit*(y-2)+(x)*bitCount+2)*M[0][2]+*(pRealData+pit*(y-2)+(x+1)*bitCount+2)*M[0][3]+*(pRealData+pit*(y-2)+(x+2)*bitCount+2)*M[0][4]+ *(pRealData+pit*(y-1)+(x-2)*bitCount+2)*M[1][0]+*(pRealData+pit*(y-1)+(x-1)*bitCount+2)*M[1][1]+*(pRealData+pit*(y-1)+(x)*bitCount+2)*M[1][2]+*(pRealData+pit*(y-1)+(x+1)*bitCount+2)*M[1][3]+*(pRealData+pit*(y-1)+(x+2)*bitCount+2)*M[1][4]+ *(pRealData+pit*(y)+(x-2)*bitCount+2)*M[2][0]+*(pRealData+pit*(y)+(x-1)*bitCount+2)*M[2][1]+*(pRealData+pit*(y)+(x)*bitCount+2)*M[2][2]+*(pRealData+pit*(y)+(x+1)*bitCount+2)*M[2][3]+*(pRealData+pit*(y)+(x+2)*bitCount+2)*M[2][4]+*(pRealData+pit*(y+1)+(x-2)*bitCount+2)*M[3][0]+*(pRealData+pit*(y+1)+(x-1)*bitCount+2)*M[3][1]+*(pRealData+pit*(y+1)+(x)*bitCount+2)*M[3][2]+*(pRealData+pit*(y+1)+(x+1)*bitCount+2)*M[3][3]+*(pRealData+pit*(y+1)+(x+2)*bitCount+2)*M[3][4] +*(pRealData+pit*(y+2)+(x-2)*bitCount+2)*M[4][0]+*(pRealData+pit*(y+2)+(x-1)*bitCount+2)*M[4][1]+*(pRealData+pit*(y+2)+(x)*bitCount+2)*M[4][2]+*(pRealData+pit*(y+2)+(x+1)*bitCount+2)*M[4][3]+*(pRealData+pit*(y+2)+(x+2)*bitCount+2)*M[4][4];tempB=abs(tempB);if(tempB>255)tempB=255;}*(pRealData2+pit2*y+x*bitCount2)=tempR;*(pRealData2+pit2*y+x*bitCount2+1)=tempG;*(pRealData2+pit2*y+x*bitCount2+2)=tempB;}}Invalidate();}
这篇关于高斯拉普拉斯锐化(边缘检测)vc实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!