原文:Win8Metro(C#)数字图像处理--2.22二值图像膨胀



[函数名称]

二值图像膨胀函数DilationProcess(WriteableBitmap
src)

[算法说明]

 膨胀算法也是属于形态学算法的范畴,前一节已经简单介绍了形态学,这里不再累赘。

 我们这里介绍的膨胀算法依旧采用上一节腐蚀中的结构元素S,则算法过程如下:

 用通俗的话讲就是,用结构元素作为模板在原始二值图像种平滑一遍,扫描图像的每一个像素,用结构元素中的每一个元素与其覆盖的二值图像做“或”操作(假设结构元素都为1),如果结果为1,则二值图像中对应结构元素原点位置的像素值为1,否则为0。

[函数代码]

       ///<summary>

       ///
Dilation process.

       ///</summary>

       ///<param
name="src">The source image(It should be the binary image).</param>

       ///<returns></returns>

       publicstaticWriteableBitmap
DilationProcess(WriteableBitmap src)////22图像膨胀运算

       {

           if
(src !=null)

           {

               int
w = src.PixelWidth;

               int
h = src.PixelHeight;

               WriteableBitmap
dilationImage =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 = dilationImage.PixelBuffer.AsStream();

               sTemp.Seek(0,
SeekOrigin.Begin);

               sTemp.Write(temp, 0, w * 4 * h);

               return
dilationImage;

           }

           else

           {

               returnnull;

           }

       }

[图像效果]

Win8Metro(C#)数字图像处理--2.22二值图像膨胀的更多相关文章

  1. Win8Metro(C#)数字图像处理--2.24二值图像闭运算

    原文:Win8Metro(C#)数字图像处理--2.24二值图像闭运算  [函数名称] 二值图像闭运算函数CloseOperateProcess(WriteableBitmap src) [算法说 ...

  2. Win8Metro(C#)数字图像处理--2.23二值图像开运算

    原文:Win8Metro(C#)数字图像处理--2.23二值图像开运算  [函数名称] 二值图像开运算函数OpenOperateProcess(WriteableBitmap src) [算法说明 ...

  3. Win8Metro(C#)数字图像处理--2.21二值图像腐蚀

    原文:Win8Metro(C#)数字图像处理--2.21二值图像腐蚀  [函数名称] 二值图像腐蚀函数CorrosionProcess(WriteableBitmap src) [算法说明] 二值 ...

  4. Win8Metro(C#)数字图像处理--2.25二值图像距离变换

    原文:Win8Metro(C#)数字图像处理--2.25二值图像距离变换  [函数名称] 二值图像距离变换函数DistanceTransformProcess(WriteableBitmap sr ...

  5. Win8Metro(C#)数字图像处理--2.40二值图像轮廓提取

    http://dongtingyueh.blog.163.com/blog/static/4619453201271481335630/ [函数名称] 二值图像轮廓提取         Contour ...

  6. Win8Metro(C#)数字图像处理--2.33图像非线性变换

    原文:Win8Metro(C#)数字图像处理--2.33图像非线性变换  [函数名称] 图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src ...

  7. Win8Metro(C#)数字图像处理--2.34直方图规定化

    原文:Win8Metro(C#)数字图像处理--2.34直方图规定化  [函数名称] WriteableBitmap HistogramSpecificateProcess(WriteableBi ...

  8. Win8Metro(C#)数字图像处理--2.30直方图均衡化

    原文:Win8Metro(C#)数字图像处理--2.30直方图均衡化 [函数名称] 直方图均衡化函数HistogramEqualProcess(WriteableBitmap src) [算法说明] ...

  9. Win8Metro(C#)数字图像处理--2.31灰度拉伸算法

    原文:Win8Metro(C#)数字图像处理--2.31灰度拉伸算法  [函数名称] 灰度拉伸函数GrayStretchProcess(WriteableBitmap src) [算法说明]    ...

随机推荐

  1. 静态编译ltrace

    ltrace可以跟踪进程的库函数调用,它会显现出哪个库函数被调用,而strace则是跟踪程序的每一个系统调用. 有时候只使用strace还是不够的,须要ltrace配合才干找出问题出在哪里. 假设在b ...

  2. Qt for Automation

    Automation, Automotive, and other industries In addition to improving the generic product offering a ...

  3. TensorFlow 辨异 —— tf.add(a, b) 与 a+b(tf.assign 与 =)、tf.nn.bias_add 与 tf.add

    1. tf.add(a, b) 与 a+b 在神经网络前向传播的过程中,经常可见如下两种形式的代码: tf.add(tf.matmul(x, w), b) tf.matmul(x, w) + b 简而 ...

  4. 【codeforces 765D】Artsem and Saunders

    [题目链接]:http://codeforces.com/contest/765/problem/D [题意] 给你一个函数f(x); 要让你求2个函数g[x]和h[x],使得g[h[x]] = x对 ...

  5. 在视图上创建ListCtrl的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 今天介绍下如何在一个视图上动态创建一个ListCtrl. 1.新建一个MFC的单文档工程,这里暂定名字为ListDem ...

  6. 【27.34%】【codeforces 611D】New Year and Ancient Prophecy

    time limit per test2.5 seconds memory limit per test512 megabytes inputstandard input outputstandard ...

  7. QT5.8.0+MSVC2015安装以及环境配置(不需要安装VS2015)

    原文:QT5.8.0+MSVC2015安装以及环境配置(不需要安装VS2015) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/snow_rain_ ...

  8. C#7

    C#7 阅读目录 out变量 元组(Tuples) 模式匹配(Pattern matching) 本地引用和返回(Ref locals and returns) 本地函数(Local function ...

  9. Entity Framework加载数据的三种方式。

    MSDN文章Loading Related Entities 有 Eagerly Loading Lazy Loading Explicitly Loading 三种方式. 而看到查询中包含Inclu ...

  10. bash实现多进程运行

    之前一段时间,发现线上日志服务器总是会突然丢失日志,碰到问题时搞的很被动.联系运维同学,又总是被往后推(后来看了一下日志归档脚本,运维同学写的bug).索性自己写了一个脚本,添加到crontab任务中 ...