有没有关于图像处理中的细化的算法代码,或者书集

wanzi7 2003-06-21 11:12:48
代码或者书都可以,请发到wanzi7@etang.com
谢谢!!
...全文
53 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
duwenyong 2003-06-30
  • 打赏
  • 举报
回复
bool CManage::ThingDIB()

{


int erasetable[256]=
{
0,0,1,1,0,0,1,1,
1,1,0,1,1,1,0,1,
1,1,0,0,1,1,1,1,
0,0,0,0,0,0,0,1,

0,0,1,1,0,0,1,1,
1,1,0,1,1,1,0,1,
1,1,0,0,1,1,1,1,
0,0,0,0,0,0,0,1,

1,1,0,0,1,1,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,

1,1,0,0,1,1,0,0,
1,1,0,1,1,1,0,1,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,

0,0,1,1,0,0,1,1,
1,1,0,1,1,1,0,1,
1,1,0,0,1,1,1,1,
0,0,0,0,0,0,0,1,

0,0,1,1,0,0,1,1,
1,1,0,1,1,1,0,1,
1,1,0,0,1,1,1,1,
0,0,0,0,0,0,0,0,

1,1,0,0,1,1,0,0,
0,0,0,0,0,0,0,0,
1,1,0,0,1,1,1,1,
0,0,0,0,0,0,0,0,

1,1,0,0,1,1,0,0,
1,1,0,1,1,1,0,0,
1,1,0,0,1,1,1,0,
1,1,0,0,1,0,0,0
};

unsigned char * upSrc;//指向图像数据的指针
LONG x,y;
BYTE num;
//当前点的八邻点
int nDownLeftPixel,nDownPixel,nDownRightPixel,nLeftPixel,nRightPixel,nUpLeftPixel,nUpPixel,nUpRightPixel;
BOOL Finished=FALSE;
while(!Finished)
{
Finished=TRUE;
for (y=1;y<m_lHeight-1;y++)
for(x=1;x<m_lWidth-1;x++)
{
upSrc=(unsigned char *)m_lpDIBBits+m_lLineBytes*y+x;
if(*upSrc==0)
{
nLeftPixel=*(upSrc-1);
nRightPixel=*(upSrc+1);
if( (nLeftPixel==255)|| (nRightPixel==255))
{
nDownLeftPixel=*(upSrc+m_lLineBytes-1);
nDownPixel=*(upSrc+m_lLineBytes);
nDownRightPixel=*(upSrc+m_lLineBytes+1);
nUpLeftPixel=*(upSrc-m_lLineBytes-1);
nUpPixel=*(upSrc-m_lLineBytes);
nUpRightPixel=*(upSrc-m_lLineBytes+1);
num=nDownLeftPixel/255+nDownPixel/255*2+nDownRightPixel/255*4+nLeftPixel/255*8+nRightPixel/255*16+nUpLeftPixel/255*32+nUpPixel/255*64+nUpRightPixel/255*128;
if(erasetable[num]==1)
{
*upSrc=255;
Finished=FALSE;
x++;
}
}
}

}

for (x=1;x<m_lWidth-1;x++)
for(y=1;y<m_lHeight;y++)
{

upSrc=(unsigned char *)m_lpDIBBits+m_lLineBytes*y+x;
if(*upSrc==0)
{
nDownPixel=*(upSrc+m_lLineBytes);
nUpPixel=*(upSrc-m_lLineBytes);
if( (nDownPixel==255)|| (nUpPixel==255))
{
nDownLeftPixel=*(upSrc+m_lLineBytes-1);
nDownRightPixel=*(upSrc+m_lLineBytes+1);
nLeftPixel=*(upSrc-1);
nRightPixel=*(upSrc+1);
nUpLeftPixel=*(upSrc-m_lLineBytes-1);
nUpRightPixel=*(upSrc-m_lLineBytes+1);
num=nDownLeftPixel/255+nDownPixel/255*2+nDownRightPixel/255*4+nLeftPixel/255*8+nRightPixel/255*16+nUpLeftPixel/255*32+nUpPixel/255*64+nUpRightPixel/255*128;
if(erasetable[num]==1)
{
*upSrc=255;
Finished=FALSE;
y++;
}
}
}

}
}

return TRUE;

}
duwenyong 2003-06-30
  • 打赏
  • 举报
回复
BOOL WINAPI ThiningDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)
{

// 指向源图像的指针
LPSTR lpSrc;

// 指向缓存图像的指针
LPSTR lpDst;

// 指向缓存DIB图像的指针
LPSTR lpNewDIBBits;
HLOCAL hNewDIBBits;
LONG lLineBytes=WIDTHBYTES(lWidth * 8);
//脏标记
BOOL bModified;

//循环变量
long i;
long j;
int n;
int m;

//四个条件
BOOL bCondition1;
BOOL bCondition2;
BOOL bCondition3;
BOOL bCondition4;
bool bNotCondition5;

//计数器
unsigned char nCount;

//像素值
unsigned char pixel;

//5×5相邻区域像素值
unsigned char neighbour[5][5];

// 暂时分配内存,以保存新图像
hNewDIBBits = LocalAlloc(LHND, lLineBytes * lHeight);

if (hNewDIBBits == NULL)
{
// 分配内存失败
return FALSE;
}

// 锁定内存
lpNewDIBBits = (char * )LocalLock(hNewDIBBits);

// 初始化新分配的内存,设定初始值为255
lpDst = (char *)lpNewDIBBits;
memset(lpDst, (BYTE)255,lLineBytes * lHeight);

bModified=TRUE;

while(bModified)
{

bModified = FALSE;
// 初始化新分配的内存,设定初始值为255
lpDst = (char *)lpNewDIBBits;
memset(lpDst, (BYTE)255, lLineBytes* lHeight);

for(j = 2; j <lHeight-2; j++)
{
for(i = 2;i <lWidth-2; i++)
{

bCondition1 = FALSE;
bCondition2 = FALSE;
bCondition3 = FALSE;
bCondition4 = FALSE;
bNotCondition5=true;

//由于使用5×5的结构元素,为防止越界,所以不处理外围的几行和几列像素

// 指向源图像倒数第j行,第i个象素的指针
lpSrc = (char *)lpDIBBits + lLineBytes * j + i;

// 指向目标图像倒数第j行,第i个象素的指针
lpDst = (char *)lpNewDIBBits + lLineBytes * j + i;

//取得当前指针处的像素值,注意要转换为unsigned char型
pixel = (unsigned char)*lpSrc;

//目标图像中含有0和255外的其它灰度值
if(pixel != 255 && *lpSrc != 0)
//return FALSE;
continue;
//如果源图像中当前点为白色,则跳过
else if(pixel == 255)
continue;

//获得当前点相邻的5×5区域内像素值,白色用0代表,黑色用1代表
for (m = 0;m < 5;m++ )
{
for (n = 0;n < 5;n++)
{
neighbour[m][n] =(255 - (unsigned char)*(lpSrc + ((4 - m) - 2)*lLineBytes + n - 2 )) / 255;
}
}
// neighbour[][]
//逐个判断条件。
//判断2<=NZ(P1)<=6
nCount = neighbour[1][1] + neighbour[1][2] + neighbour[1][3] \
+ neighbour[2][1] + neighbour[2][3] + \
+ neighbour[3][1] + neighbour[3][2] + neighbour[3][3];
if ( nCount >= 2 && nCount <=6)
bCondition1 = TRUE;

//判断Z0(P1)=1
nCount = 0;
if (neighbour[1][2] == 0 && neighbour[1][1] == 1)
nCount++;
if (neighbour[1][1] == 0 && neighbour[2][1] == 1)
nCount++;
if (neighbour[2][1] == 0 && neighbour[3][1] == 1)
nCount++;
if (neighbour[3][1] == 0 && neighbour[3][2] == 1)
nCount++;
if (neighbour[3][2] == 0 && neighbour[3][3] == 1)
nCount++;
if (neighbour[3][3] == 0 && neighbour[2][3] == 1)
nCount++;
if (neighbour[2][3] == 0 && neighbour[1][3] == 1)
nCount++;
if (neighbour[1][3] == 0 && neighbour[1][2] == 1)
nCount++;
if (nCount == 1)
bCondition2 = TRUE;
if(neighbour[1][2]+neighbour[1][1]+neighbour[2][1]+
neighbour[3][1]+neighbour[3][2]+neighbour[3][3]+
neighbour[2][3]+neighbour[1][3]==1)
bNotCondition5=false;

//判断P2*P4*P8=0 or Z0(p2)!=1
if (neighbour[1][2]*neighbour[2][1]*neighbour[2][3] == 0)
bCondition3 = TRUE;
else
{
nCount = 0;
if (neighbour[0][2] == 0 && neighbour[0][1] == 1)
nCount++;
if (neighbour[0][1] == 0 && neighbour[1][1] == 1)
nCount++;
if (neighbour[1][1] == 0 && neighbour[2][1] == 1)
nCount++;
if (neighbour[2][1] == 0 && neighbour[2][2] == 1)
nCount++;
if (neighbour[2][2] == 0 && neighbour[2][3] == 1)
nCount++;
if (neighbour[2][3] == 0 && neighbour[1][3] == 1)
nCount++;
if (neighbour[1][3] == 0 && neighbour[0][3] == 1)
nCount++;
if (neighbour[0][3] == 0 && neighbour[0][2] == 1)
nCount++;
if (nCount != 1)
bCondition3 = TRUE;
}

//判断P2*P4*P6=0 or Z0(p4)!=1
if (neighbour[1][2]*neighbour[2][1]*neighbour[3][2] == 0)
bCondition4 = TRUE;
else
{
nCount = 0;
if (neighbour[1][1] == 0 && neighbour[1][0] == 1)
nCount++;
if (neighbour[1][0] == 0 && neighbour[2][0] == 1)
nCount++;
if (neighbour[2][0] == 0 && neighbour[3][0] == 1)
nCount++;
if (neighbour[3][0] == 0 && neighbour[3][1] == 1)
nCount++;
if (neighbour[3][1] == 0 && neighbour[3][2] == 1)
nCount++;
if (neighbour[3][2] == 0 && neighbour[2][2] == 1)
nCount++;
if (neighbour[2][2] == 0 && neighbour[1][2] == 1)
nCount++;
if (neighbour[1][2] == 0 && neighbour[1][1] == 1)
nCount++;
if (nCount != 1)
bCondition4 = TRUE;

}
if(bCondition1 && bCondition2 && bCondition3 && bCondition4&&bNotCondition5)
{
*lpDst = (unsigned char)255;
bModified = TRUE;
}
else
{
*lpDst = (unsigned char)0;
}
}
}
// 复制腐蚀后的图像
memcpy(lpDIBBits, lpNewDIBBits, lLineBytes * lHeight);


}
// 复制腐蚀后的图像
memcpy(lpDIBBits, lpNewDIBBits, lLineBytes * lHeight);

// 释放内存
LocalUnlock(hNewDIBBits);
LocalFree(hNewDIBBits);

// 返回
return TRUE;
}

doze 2003-06-28
  • 打赏
  • 举报
回复
具体算法,看看我手头有没有。
Sportbeuty 2003-06-27
  • 打赏
  • 举报
回复
我发的楼主收到了没有?
autoegg 2003-06-27
  • 打赏
  • 举报
回复
《Visual C++ 数字图像处理》人民邮电出版社,里面有代码和详细说明,现在已经有第二版了。
如果需要的话,我有256色图像的细化代码可以发给你。
bobworld 2003-06-25
  • 打赏
  • 举报
回复
人民邮电出版社数字图像处理的书有。
wygsh 2003-06-25
  • 打赏
  • 举报
回复
吕凤军的《数字图象处理编程入门》中有细化的内容和代码,可以一看。
Sportbeuty 2003-06-25
  • 打赏
  • 举报
回复
发给你了,注意接了、
ljranby 2003-06-21
  • 打赏
  • 举报
回复
我编过一个,不过只能针对二值图像,发给你看看行不行吧

19,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧