马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
:@) #define EXTRA_NAME "@sobeledge."
#include "loadbmp.h"
#define Point(x,y) lpPoints[(x)+(y)*nWidth]
#define Point1(x,y) lpPoints1[(x)+(y)*nWidth]
void Sobel()
{
int x,y,x1,y1,i;
BYTE *lpPoints=new BYTE[nWidth*nHeight];
BYTE *lpPoints1=new BYTE[nWidth*nHeight];
memset(lpPoints1,0,nWidth*nHeight);
GetPoints(lpPoints);
int d,max;
static s[8][9]={
{-1,-2,-1,0,0,0,1,2,1},
{0,-1,-2,1,0,-1,2,1,0},
{1,0,-1,2,0,-2,1,0,-1},
{2,1,0,1,0,-1,0,-1,-2},
{1,2,1,0,0,0,-1,-2,-1},
{0,1,2,-1,0,1,-2,-1,0},
{-1,0,1,-2,0,2,-1,0,1},
{-2,-1,0,-1,0,1,0,1,2}
};
for(y=1;y<nHeight-1;y++)
{
for(x=1;x<nWidth-1;x++)
{
max=0;
for(i=0;i<8;i++)
{
d=0;
for(y1=0;y1<3;y1++)
for(x1=0;x1<3;x1++)
{
d+=s[x1+y1*3]*Point(x+x1-1,y+y1-1);
}
if (d>max) max=d;
}
if (max>255) max=255;
Point1(x,y)=(BYTE)max;
}
}
PutPoints(lpPoints1);
delete lpPoints;
delete lpPoints1;
}
[ 本帖最后由 eight 于 2007-5-31 20:20 编辑 ] |