/*************************************************************************
*
* 函数名称:
* RobertDIB()
*
* 参数:
* LPSTR lpDIBBits - 指向源DIB图像指针
* LONG lWidth - 源图像宽度(象素数,必须是4的倍数)
* LONG lHeight - 源图像高度(象素数)
* 返回值:
* BOOL - 边缘检测成功返回TRUE,否则返回FALSE。
*
* 说明:
* 该函数用Robert边缘检测算子对图像进行边缘检测运算。
*
* 要求目标图像为灰度图像。
************************************************************************/ BOOL WINAPI RobertDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)
{ // 指向源图像的指针
LPSTR lpSrc; // 指向缓存图像的指针
LPSTR lpDst; // 指向缓存DIB图像的指针
LPSTR lpNewDIBBits;
HLOCAL hNewDIBBits; //循环变量
long i;
long j; //像素值
double result;
unsigned char pixel[4]; // 暂时分配内存,以保存新图像
hNewDIBBits = LocalAlloc(LHND, lWidth * lHeight); if (hNewDIBBits == NULL)
{
// 分配内存失败
return FALSE;
} // 锁定内存
lpNewDIBBits = (char * )LocalLock(hNewDIBBits); // 初始化新分配的内存,设定初始值为255
lpDst = (char *)lpNewDIBBits;
memset(lpDst, (BYTE)255, lWidth * lHeight);
//使用水平方向的结构元素进行腐蚀
for(j = lHeight-1; j > 0; j--)
{
for(i = 0;i <lWidth-1; i++)
{
//由于使用2×2的模板,为防止越界,所以不处理最下边和最右边的两列像素 // 指向源图像第j行,第i个象素的指针
lpSrc = (char *)lpDIBBits + lWidth * j + i; // 指向目标图像第j行,第i个象素的指针
lpDst = (char *)lpNewDIBBits + lWidth * j + i; //取得当前指针处2*2区域的像素值,注意要转换为unsigned char型
pixel[0] = (unsigned char)*lpSrc;
pixel[1] = (unsigned char)*(lpSrc + 1);
pixel[2] = (unsigned char)*(lpSrc - lWidth);
pixel[3] = (unsigned char)*(lpSrc - lWidth + 1); [/color][/color]//计算目标图像中的当前点
result = sqrt(( pixel[0] - pixel[3] )*( pixel[0] - pixel[3] ) + \
( pixel[1] - pixel[2] )*( pixel[1] - pixel[2] ));
*lpDst = (unsigned char)result; }
} // 复制腐蚀后的图像
memcpy(lpDIBBits, lpNewDIBBits, lWidth * lHeight); // 释放内存
LocalUnlock(hNewDIBBits);
LocalFree(hNewDIBBits); // 返回
return TRUE;
}
中的
pixel[0] = (unsigned char)*lpSrc;
pixel[1] = (unsigned char)*(lpSrc + 1);
pixel[2] = (unsigned char)*(lpSrc - lWidth);
pixel[3] = (unsigned char)*(lpSrc - lWidth + 1);
这几句话,看不明白,pixel[0],pixel[1]我明白,但是下面的两个pixel[2],pixel[3]怎么解释啊?
*
* 函数名称:
* RobertDIB()
*
* 参数:
* LPSTR lpDIBBits - 指向源DIB图像指针
* LONG lWidth - 源图像宽度(象素数,必须是4的倍数)
* LONG lHeight - 源图像高度(象素数)
* 返回值:
* BOOL - 边缘检测成功返回TRUE,否则返回FALSE。
*
* 说明:
* 该函数用Robert边缘检测算子对图像进行边缘检测运算。
*
* 要求目标图像为灰度图像。
************************************************************************/ BOOL WINAPI RobertDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)
{ // 指向源图像的指针
LPSTR lpSrc; // 指向缓存图像的指针
LPSTR lpDst; // 指向缓存DIB图像的指针
LPSTR lpNewDIBBits;
HLOCAL hNewDIBBits; //循环变量
long i;
long j; //像素值
double result;
unsigned char pixel[4]; // 暂时分配内存,以保存新图像
hNewDIBBits = LocalAlloc(LHND, lWidth * lHeight); if (hNewDIBBits == NULL)
{
// 分配内存失败
return FALSE;
} // 锁定内存
lpNewDIBBits = (char * )LocalLock(hNewDIBBits); // 初始化新分配的内存,设定初始值为255
lpDst = (char *)lpNewDIBBits;
memset(lpDst, (BYTE)255, lWidth * lHeight);
//使用水平方向的结构元素进行腐蚀
for(j = lHeight-1; j > 0; j--)
{
for(i = 0;i <lWidth-1; i++)
{
//由于使用2×2的模板,为防止越界,所以不处理最下边和最右边的两列像素 // 指向源图像第j行,第i个象素的指针
lpSrc = (char *)lpDIBBits + lWidth * j + i; // 指向目标图像第j行,第i个象素的指针
lpDst = (char *)lpNewDIBBits + lWidth * j + i; //取得当前指针处2*2区域的像素值,注意要转换为unsigned char型
pixel[0] = (unsigned char)*lpSrc;
pixel[1] = (unsigned char)*(lpSrc + 1);
pixel[2] = (unsigned char)*(lpSrc - lWidth);
pixel[3] = (unsigned char)*(lpSrc - lWidth + 1); [/color][/color]//计算目标图像中的当前点
result = sqrt(( pixel[0] - pixel[3] )*( pixel[0] - pixel[3] ) + \
( pixel[1] - pixel[2] )*( pixel[1] - pixel[2] ));
*lpDst = (unsigned char)result; }
} // 复制腐蚀后的图像
memcpy(lpDIBBits, lpNewDIBBits, lWidth * lHeight); // 释放内存
LocalUnlock(hNewDIBBits);
LocalFree(hNewDIBBits); // 返回
return TRUE;
}
中的
pixel[0] = (unsigned char)*lpSrc;
pixel[1] = (unsigned char)*(lpSrc + 1);
pixel[2] = (unsigned char)*(lpSrc - lWidth);
pixel[3] = (unsigned char)*(lpSrc - lWidth + 1);
这几句话,看不明白,pixel[0],pixel[1]我明白,但是下面的两个pixel[2],pixel[3]怎么解释啊?
解决方案 »
- 紧急求救!!!对话框关闭总是出现异常
- 拷贝构造函数可不可以调用?在线等...
- 简单问题---关于 windows消息机制 !
- classwizard 里没有的消息怎么加响应函数?
- wawaku(挣钱啦挣钱啦 娶个媳妇盖房啦),请进!
- ADO读取int数据,类型转换问题,非常急,请帮忙.
- ******100分请教高手最简单的界面问题,超级简单,拿分太容易了,谢谢帮助******
- 消息传递中如何传递字符串的信息!!!急!急!
- 请问大家,我已知一个位图句柄或一个DC句柄,如何将它回写到一个位图文件中呢?就是把显示的内容保存在位图文件中。
- 关于USB7325采集卡的端口使用问题
- 动态库的一点疑问
- vc7的插件在哪里添加啊?
所以前两个
pixel[2],pixel[3]应该是pixel[0],pixel[1]所在行的上一行对应的两个像素
┗2 3┛
(BMP是按照行倒序存放的,所以下一行存储在前面)不过一般都是奇数模板,你这???