影象邊緣檢測—sobel運算元(灰度影象,彩色影象)
阿新 • • 發佈:2019-01-05
void CShowPicView::Ontwodimension() { CShowPicDoc* pDoc = GetDocument(); CDC* pDC=GetDC(); // 字串 CString str; int x,y; int i,n; x=intHeight; y=intWidth; int **g1,**g2,**g3; g1 = new int*[x]; //行 //申請行的空間 g2 = new int*[x]; g3 = new int*[x]; //每行的列申請空間 for(i=0; ipic[y+1][x-1][0]+2*pDoc->pic[y+1][x][0]+pDoc->pic[y+1][x+1][0] - pDoc->pic[y-1][x-1][0]-2*pDoc->pic[y-1][x][0]-pDoc->pic[y-1][x+1][0]; gy1=pDoc->pic[y-1][x-1][0]+2*pDoc->pic[y][x-1][0]+pDoc->pic[y+1][x-1][0] - pDoc->pic[y-1][x+1][0]-2*pDoc->pic[y][x+1][0]-pDoc->pic[y+1][x+1][0]; if(sqrt(gx1*gx1+gy1*gy1)>255) g1[y][x]=255; else g1[y][x]=sqrt(gx1*gx1+gy1*gy1); gx2=pDoc->pic[y+1][x-1][1]+2*pDoc->pic[y+1][x][1]+pDoc->pic[y+1][x+1][1] - pDoc->pic[y-1][x-1][1]-2*pDoc->pic[y-1][x][1]-pDoc->pic[y-1][x+1][1]; gy2=pDoc->pic[y-1][x-1][1]+2*pDoc->pic[y][x-1][1]+pDoc->pic[y+1][x-1][1] - pDoc->pic[y-1][x+1][1]-2*pDoc->pic[y][x+1][1]-pDoc->pic[y+1][x+1][1]; if(sqrt(gx2*gx2+gy2*gy2)>255) g2[y][x]=255; else g2[y][x]=sqrt(gx2*gx2+gy2*gy2); gx3=pDoc->pic[y+1][x-1][2]+2*pDoc->pic[y+1][x][2]+pDoc->pic[y+1][x+1][2] - pDoc->pic[y-1][x-1][2]-2*pDoc->pic[y-1][x][2]-pDoc->pic[y-1][x+1][2]; gy3=pDoc->pic[y-1][x-1][2]+2*pDoc->pic[y][x-1][2]+pDoc->pic[y+1][x-1][2] - pDoc->pic[y-1][x+1][2]-2*pDoc->pic[y][x+1][2]-pDoc->pic[y+1][x+1][2]; if(sqrt(gx3*gx3+gy3*gy3)>255) g3[y][x]=255; else g3[y][x]=sqrt(gx3*gx3+gy3*gy3); pDC->SetPixel(x+1*intWidth+30,y,RGB(g1[y][x],g2[y][x],g3[y][x])); } } for(i=0;i