Win8Metro(C#)数字图像处理--2.21二值图像腐蚀
原文:Win8Metro(C#)数字图像处理--2.21二值图像腐蚀
[函数名称]
二值图像腐蚀函数CorrosionProcess(WriteableBitmap src)
[算法说明]
二值图像腐蚀操作属于图像形态学的范畴,形态学运算是只针对二值图像进行,并依据数学形态学(Mathermatical
Morphogy)集合论方法发展起来的数字图像处理方法,它主要包括腐蚀,膨胀,开,闭,击中,击不中等。
图像形态学运算,要使用结构元素,所谓结构元素是指具有某种确定形状的基本结构,它的选择一般要求其具有旋转不变性或者镜像不变性,即:结构元素的原点在其几何中心处,周围像素关于原点对称。
在这里我们选取如下的结构元素:
其中,F为二值图像原图,X为结构元素原点所在的二值图像中的连通域。
假设F中目标像素为255(白色),非目标为0(黑色),当结构元素S原点移动到点(x,y)时,如果S中所有点均包含在X中(X中对应在S中所有点的位置均为255),则在腐蚀后的二值图像中,对应于S原点的位置为255(白色),否则为0(黑色)。
用通俗的话来说就是:用结构元素作为模板在原始二值图像种平滑一遍,扫描图像的每一个像素,用结构元素中的每一个元素与其覆盖的二值图像做“与”操作(假设结构元素都为1),如果结果都为1,则二值图像中对应结构元素原点位置的像素值为1,否则为0。
[函数代码]
///<summary>
///
Corrosion process.
///</summary>
///<param
name="src">The source image(It should be the binary image).</param>
///<returns></returns>
publicstaticWriteableBitmap
CorrosionProcess(WriteableBitmap src)////21图像腐蚀运算
{
if
(src !=null)
{
int
w = src.PixelWidth;
int
h = src.PixelHeight;
WriteableBitmap
corrosionImage =newWriteableBitmap(w,
h);
byte[]
temp = src.PixelBuffer.ToArray();
byte[]
tempMask = (byte[])temp.Clone();
for
(int j = 0; j < h; j++)
{
for
(int i = 0; i < w ; i ++)
{
if
(i == 0 || i == w - 1 || j == 0 || j == h - 1)
{
temp[i * 4 + j * w * 4] = (byte)255;
temp[i * 4 + 1 + j * w * 4] = (byte)255;
temp[i * 4 + 2 + j * w * 4] = (byte)255;
}
else
{
if
(tempMask[i * 4 - 4 + j * w * 4] == 255 && tempMask[i * 4 + j * w * 4] == 255 && tempMask[i * 4 + 4 + j * w * 4] == 255
&& tempMask[i * 4 + (j - 1) * w * 4] == 255 && tempMask[i
* 4 + (j + 1) * w * 4] == 255)
{
temp[i * 4 + j * w * 4] = (byte)255;
temp[i * 4 + 1 + j * w * 4] = (byte)255;
temp[i * 4 + 2 + j * w * 4] = (byte)255;
}
else
{
temp[i * 4 + j * w * 4] = 0;
temp[i * 4 + 1 + j * w * 4] = 0;
temp[i * 4 + 2 + j * w * 4] = 0;
}
}
}
}
Stream
sTemp = corrosionImage.PixelBuffer.AsStream();
sTemp.Seek(0,
SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return
corrosionImage;
}
else
{
returnnull;
}
}
[图像效果]
最新文章
- Laravel5.0学习--03 Artisan命令
- 连接到CentOS(Linux)服务器ssh、mysql缓慢
- codeforces 425C
- 手工搭建Openvpn
- 3-WebPack
- CSS--开篇
- UNIX环境高级编程——线程与进程区别
- Angular6 用户自定义标签开发
- ATL右键文件菜单
- 前端持久化--evercookie
- ios外部链接或者app唤起自己的app
- 分布式架构的基石.简单的 RPC 框架实现(JAVA)
- debian中完全删除mysql
- 用D3.js画的人物关系demo
- Unity Mathf/Math数学运算函数说明全集(Chinar总结)
- django 表单常用field
- Yii实战中8个必备常用的扩展,模块和widget
- ini_set的用法介绍
- Java多线程(九)之ReentrantLock与Condition
- lua的table的删除操作
热门文章
- phpStudy的localhost不能访问怎么解决(相关性)
- js把其他类型转化成字符串
- 找不到头文件xxxxx.h file not found
- Graphics processing architecture employing a unified shader
- CocoaPods详解之(一)----使用篇
- Java 中StringBuffer与StringBuilder区别(转)及String类的一些基本操作代码
- cocos2d-x创建第一个项目
- Array.prototype.forEach()&;&;Array.prototype.map()
- java中 8进制 10进制 2进制 16进制 相互转换
- 抛砖引玉 【镜像控件】 WPF实现毛玻璃控件不要太简单