/*************************************************************************
* 函数名称:
* ThinDIB()
* 参数:
* LPSTR lpDIBBits - 指向源DIB图像指针
* LONG lWidth - 源图像宽度(象素数,必须是4的倍数)
* LONG lHeight - 源图像高度(象素数)
* 返回值:
* BOOL - 闭运算成功返回TRUE,否则返回FALSE。
* 说明:
* 该函数用于对图像进行细化运算。要求目标图像为只有0和255两个灰度值的灰度图像。
************************************************************************/
BOOL CDibImage::ThiningDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)
{
LPSTR lpSrc; // 指向源图像的指针
LPSTR lpDst; // 指向缓存图像的指针
LPSTR lpNewDIBBits; // 指向缓存DIB图像的指针
HLOCAL hNewDIBBits;
BOOL bModified; //脏标记
long i,j,m,n; //循环变量
//四个条件
BOOL bCondition1;
BOOL bCondition2;
BOOL bCondition3;
BOOL bCondition4;
unsigned char nCount; //计数器
unsigned char pixel; //像素值
unsigned char neighbour[5][5]; //5×5相邻区域像素值
// 暂时分配内存,以保存新图像
hNewDIBBits = LocalAlloc(LHND, lWidth * lHeight);
if (hNewDIBBits == NULL)
{
return FALSE;
}
lpNewDIBBits = (char * )LocalLock(hNewDIBBits);
// 初始化新分配的内存,设定初始值为255
lpDst = (char *)lpNewDIBBits;
memset(lpDst, (BYTE)255, lWidth * lHeight);
bModified = TRUE;
while(bModified)
{
bModified = FALSE;
// 初始化新分配的内存,设定初始值为255
lpDst = (char *)lpNewDIBBits;
memset(lpDst, (BYTE)255, lWidth * lHeight);
for(j = 2; j <lHeight-2; j++)
{
for(i = 2;i <lWidth-2; i++)
{
bCondition1 = FALSE;
bCondition2 = FALSE;
bCondition3 = FALSE;
bCondition4 = FALSE;