vc图像处理,指针无法改变图像数据,边缘检测
下面的代码是我读取灰度图像数据并将灰度值为255的点置零,但是效果并不明显,几乎没有将图像中的白色点去掉,似乎指针没有改变数据中的值。调试发现,if (*lpDstT ==(byte)255)没有执行,直接跳过了,所以无法改变数据,弄了三天了,还没解决这问题,求大大们答疑解惑!
void FindCircle(LPSTR lpDIBBits,LONG lWidth, LONG lHeight, int *pnCirclePixelCoordX, int *pnCirclePixelCoordY)
{
//循环变量
int i,j,k=0;
int Direction[8][2]={{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0}};
Point CurrentPoint;
int BeginDirect=0;
byte tempPixel =0;
LPSTR lpSrc;
LPSTR lpSrcT;
HLOCAL hSrcDIBBits;
LPSTR lpDst;
LPSTR lpDstT;
LPSTR lpDesT2;
HLOCAL hNewDIBBits;
hSrcDIBBits=::LocalAlloc(LHND,lWidth*lHeight);
lpSrc=(char*)LocalLock((HLOCAL)hSrcDIBBits);
lpSrcT=lpSrc;
memcpy(lpSrc,lpDIBBits,lWidth*lHeight);
hNewDIBBits=::LocalAlloc(LHND,lWidth*lHeight);
lpDst=(char*)LocalLock((HLOCAL)hNewDIBBits);
lpDstT=lpDst;
lpDesT2=lpDst;
memcpy(lpDst,lpDIBBits,lWidth*lHeight);
//首先图像边界杂质点清除
for (i = 0; i< 100; i++)//下边缘100个像素内清零
{
for (j =0; j< lWidth; j++)
{
lpDstT = (char*)lpDst + i*lWidth + j;
*lpDstT = (byte)0;
}
}
for (i= lHeight-30; i< lHeight; i++)//上边缘30个像素清零
{
for (j=0; j< lWidth; j++)
{
lpDstT = (char*)lpDst+i*lWidth + j;
*lpDstT = (byte)0;
}
}
for (i=0; i< lHeight; i++)//左边缘30个像素清零
{
for (j=0; j<30; j++)
{
lpDstT = (char*)lpDst+i*lWidth + j;
*lpDstT = (byte)0;
}
}
for (i=0; i<lHeight; i++)//右边缘80个像素清零
{
for (j = lWidth-80; j <lWidth; j++)
{
lpDstT = (char*)lpDst+i*lWidth + j;
*lpDstT = (byte)0;
}
}
//切线法找内圆
for (i =0; i< lHeight; i++)
{
for (j =0; j < lWidth; j++)
{
BeginDirect=0;
lpDstT = (char*)lpDst + lWidth *i + j;
if (*lpDstT ==(byte)255)
{
CurrentPoint.Height = i;
CurrentPoint.Width = j;
*lpDstT = (byte)0;
while(BeginDirect < 8)
{
lpDstT=(char*)lpDst + lWidth* (CurrentPoint.Height+Direction[BeginDirect][1])+(CurrentPoint.Width+Direction[BeginDirect][0]);
if (*lpDstT == (byte)255)
{
*lpDstT = (BYTE)0;
}
BeginDirect ++;
}
}
}
}
memcpy(lpDIBBits,lpDst,lWidth*lHeight);
}
换成:
if (BYTE(*lpDstT) == 255)
腐蚀或者计算连通域去掉面积较小者