求教Imgcx图像处理在VC环境里边缘检测与边缘跟踪的代码
void CImgcxView::OnSobel() {
// TODO: Add your command handler code here
if(!m_bFileOpen)
{
AfxMessageBox("Please open a grey image!");
return;
}
if(::GetImageType() != 8)
{
AfxMessageBox("Not a grey image!");
return;
}
BYTE *Out_pImage = new BYTE[m_nXSize*m_nYSize];
static int cx[9] //算子x(Roberts)
= { -1, 0, 1,
-2, 0, 2,
-1, 0, 1};
static int cy[9] //算子y(Roberts)
= { 1, 2, 1,
0, 0, 0,
-1, -2, -1};
int d[9];
int i,j,dat;
float xx, yy, zz;
for (j = 1; j < m_nYSize - 1; j++)
{
for (i = 1; i < m_nXSize - 1; i++)
{
d[0] = *(m_pImage + (j-1)*m_nXSize + i-1);
d[1] = *(m_pImage + (j-1)*m_nXSize + i);
d[2] = *(m_pImage + (j-1)*m_nXSize + i+1);
d[3] = *(m_pImage + j*m_nXSize + i-1);
d[4] = *(m_pImage + j*m_nXSize + i);
d[5] = *(m_pImage + j*m_nXSize + i+1);
d[6] = *(m_pImage + (j+1)*m_nXSize + i-1);
d[7] = *(m_pImage + (j+1)*m_nXSize + i);
d[8] = *(m_pImage + (j+1)*m_nXSize + i+1);
xx = (float)(cx[0]*d[0] + cx[1]*d[1] + cx[2]*d[2]
+cx[3]*d[3] + cx[4]*d[4] + cx[5]*d[5]
+cx[6]*d[6] + cx[7]*d[7] + cx[8]*d[8]);
yy = (float)(cy[0]*d[0] + cy[1]*d[1] + cy[2]*d[2]
+cy[3]*d[3] + cy[4]*d[4] + cy[5]*d[5]
+cy[6]*d[6] + cy[7]*d[7] + cy[8]*d[8]);
zz = (float)(1/4*sqrt(xx*xx + yy*yy));
dat = (int)zz;
if (dat > 255) dat = 255;
*(Out_pImage + j*m_nXSize + i) = dat;
}
}
::Disp_image(Out_pImage);
Invalidate();
}
这是边缘检测的代码,为什么图像处理后完全变黑?