二值图像上的腐蚀是腐蚀最典型的运用,但是腐蚀操作同样可以运用于灰度图像。二值图像腐蚀操作最基本的效果是腐蚀图像中前景色区域的边缘。使得前景图像区域变小,前景图像内部的背景区域被放大。
Bool IMG_erode(Uint8 * pImg,Uint32 w,Uint32 h,
Uint8 * pMatrix,Uint32 col,Uint32 raw)
{
Uint32 i,j,x,y;
Uint8 * restrict p1;
Uint8 * restrict p2;
Uint8 * restrict p3;
Uint8 match;
if(col > w)
return FALSE;
if(raw > h)
return FALSE;
for(i=0;i<(h-raw);i++)
{
p1 = pImg+i*w;
for(j=0;j<(w-col);j++)
{
match = 1;
p3 = pMatrix;
for(y=0;y<raw;y++)
{
p2 = pImg+(i+y)*w+j;
for(x=0;x<col;x++)
{
if(((*p3) != 0)&&((*p2) == 0))
{
match = 0;
break;
}
p3++;
p2++;
}
if(match == 0)
break;
}
*p1++ = match;
}
}
return TRUE;
}