原文:Win8Metro(C#)数字图像处理--2.13Roberts边缘检测



[函数名称]

图像Roberts边缘检测函数RobertEdgeProcess(WriteableBitmap
src)

[函数代码]

       ///<summary>

       ///
Roberts edge detection.

       ///</summary>

       ///<param
name="src">Source image.</param>

       ///<returns></returns>

       publicstaticWriteableBitmap
RobertEdgeProcess(WriteableBitmap src)////13
Robert边缘检测

       {

           if(src!=null
)

           {

           int
w = src.PixelWidth;

           int
h = src.PixelHeight;

           WriteableBitmap
robertImage =newWriteableBitmap(w,h);

           byte[]
temp = src.PixelBuffer.ToArray();

           byte[]
tempMask = (byte[])temp.Clone();

           int
b = 0, g = 0, r = 0;

           for
(int j = 1; j < h - 1; j++)

           {

               for
(int i = 4; i < w * 4 - 4; i += 4)

               {

                   if
(i == 0 || i == w - 4 || j == 0 || j == h - 1)

                   {

                       temp[i + j * w * 4] = (byte)0;

                       temp[i + 1 + j * w * 4] = (byte)0;

                       temp[i + 2 + j * w * 4] = (byte)0;

                   }

                   else

                   {

                       b =Math.Abs(tempMask[i
+ j * w * 4] - tempMask[i - 4 + (j+1) * w * 4]) + Math.Abs(tempMask[i
- 4 + j * w * 4] - tempMask[i + (j + 1) * w * 4]);

                       g =Math.Abs(tempMask[i
+ 1 + j * w * 4] - tempMask[i - 4 + 1 + (j + 1) * w * 4]) + Math.Abs(tempMask[i
- 4 + 1 + j * w * 4] - tempMask[i + 1 + (j + 1) * w * 4]);

                       r =Math.Abs(tempMask[i
+ 2 + j * w * 4] - tempMask[i - 4 + 2 + (j + 1) * w * 4]) + Math.Abs(tempMask[i
- 4 + 2 + j * w * 4] - tempMask[i + 2 + (j + 1) * w * 4]);

                       temp[i + j * w * 4] = (byte)(b
> 0 ? (b < 255 ? b : 255) : 0);

                       temp[i + 1 + j * w * 4] = (byte)(g
> 0 ? (g < 255 ? g : 255) : 0);

                       temp[i + 2 + j * w * 4] = (byte)(r
> 0 ? (r < 255 ? r : 255) : 0);

                   }

                   b = 0; g = 0; r = 0;

               }

           }

           Stream
sTemp = robertImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

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

           return
robertImage;

           }

           else

           {

               returnnull;

           }  

       }

[图像效果]

最新文章

  1. 俄罗斯方块(Win32实现,Codeblocks+GCC编译)
  2. 【活动】监控宝惹火Docker监控,开放试用中
  3. 阅读《LEARNING HARD C#学习笔记》知识点总结与摘要三
  4. Microsoft Azure 的负载平衡器的Session Sticky
  5. 使用SFTP工具下载文件
  6. PowerDesigner连接Oracle数据库生成数据模型【本地连接方式】
  7. 精妙SQL语句收集
  8. Win7 x64下进程保护与文件保护(ObRegisterCallbacks)
  9. flashback table恢复数据
  10. 第一个felx项目的创建
  11. 【转】Java中字符串中子串的查找共有四种方法(indexof())
  12. HDU 4628 多校第三场1008 dp
  13. Java字符串的10大热点问题,你都懂吗?
  14. sublime text 3 插件:package control
  15. jQuery extend函数详解
  16. 理解Hibernate事务机制,首先需要搞清楚的6个问题
  17. ajax的嵌套需要注意的问题
  18. RxJS简介
  19. 和嗲妹妹面试python,是种什么体验?
  20. 20155206《网络对抗》Web安全基础实践

热门文章

  1. .gitignore 设置忽略上传的文件
  2. spring mvc redirect 重定向 跳转并传递参数
  3. 2015年工作中遇到的问题:71-80,Tomcat-Redis-浮点数-HTTPS
  4. 《图说VR》——HTC Vive控制器按键事件解耦使用
  5. amazeui时间组件测试
  6. Vue中import &#39;@...&#39;是什么
  7. 【35.56%】【727A】Transformation: from A to B
  8. spring-boot-quartz, 依赖spring-boot-parent good
  9. 使用JScript编译指定目录下所有工程
  10. 分布式缓存技术PK:选择Redis还是Memcached?