19,469
社区成员
发帖
与我相关
我的任务
分享
int i,j;
UCHAR *c1,*c2,v;
c1 = NULL;
unsigned char pixel[4];
for(i=1;i<image_hei-1;i++)
for(j=1;j<image_wid-1;j++)
{
pixel[0] = (unsigned char)(*(tbuf+i*image_wid+j));
pixel[1] = (unsigned char)(*(tbuf+(i+1)*image_wid+j));
pixel[2] = (unsigned char)(*(tbuf+i*image_wid+j+1));
pixel[3] = (unsigned char)(*(tbuf+(i+1)*image_wid+j+1));
c2=(UCHAR *)(rbuf+i*image_wid+j);
v = (unsigned char)(sqrt(( pixel[0] - pixel[3] )*( pixel[0] - pixel[3] ) + \
( pixel[1] - pixel[2] )*( pixel[1] - pixel[2] )));
c2[0]=v; c2[1]=v; c2[2]=v; c2[3]=255;
}
int i,j;
UCHAR *c1,*c2;
unsigned char n,e,s,w,ne,se,nw,sw;
unsigned char pixel;
for(i=1;i<image_hei-1;i++)
for(j=1;j<image_wid-1;j++)
{
c1=(UCHAR *)(vbuf+i*image_wid+j);
c2=(UCHAR *)(kbuf+i*image_wid+j);
pixel = *c1;
if(pixel == 0)
{
//*c2 = (unsigned char)0;
c2[0]=0; c2[1]=0; c2[2]=0; c2[3]=255;
nw = (unsigned char)*(c1 + (sizeof(UINT))*(image_wid-1));
n = (unsigned char)*(c1 + (sizeof(UINT))*image_wid );
ne = (unsigned char)*(c1 + (sizeof(UINT))*(image_wid +1));
w = (unsigned char)*(c1 - (sizeof(UINT))*1);
e = (unsigned char)*(c1 + (sizeof(UINT))*1);
sw = (unsigned char)*(c1 - (sizeof(UINT))*(image_wid -1));
s = (unsigned char)*(c1 - (sizeof(UINT))*image_wid );
se = (unsigned char)*(c1 - (sizeof(UINT))*(image_wid +1));
//如果相邻的八个点都是黑点
if ((nw==n) && (n==ne) && (ne==w) && (w==e) && (e==sw) & (sw==s) && (s==se) && (se==nw))
{
//*c2 = (unsigned char)255;
c2[0]=255; c2[1]=255; c2[2]=255; c2[3]=255;
}
}
else
{
c2[0]=255; c2[1]=255; c2[2]=255; c2[3]=255;
}
}