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



[函数名称]

图像Sobel边缘检测函数SobelEdgeProcess(WriteableBitmap
src)

[函数代码]

       ///<summary>

       ///
Sobel edge detection.

       ///</summary>

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

       ///<returns></returns>

       publicstaticWriteableBitmap
SobelEdgeProcess(WriteableBitmap src)////12
Sobel边缘检测

       {

           if(src!=null
)

           {

           int
w = src.PixelWidth;

           int
h = src.PixelHeight;

           WriteableBitmap
sobelImage =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
- 4 + (j - 1) * w * 4] + 2 * tempMask[i - 4 + j * w * 4] + tempMask[i - 4 + (j + 1) * w * 4] - tempMask[i + 4 + (j - 1) * w * 4]

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

                           + tempMask[i + 4 + (j - 1) * w * 4] - tempMask[i - 4 + (j + 1)
* w * 4] - 2 * tempMask[i + (j + 1) * w * 4] - tempMask[i + 4 + (j + 1) * w * 4]);

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

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

                          + tempMask[i + 4 + 1 + (j - 1) * w * 4] - tempMask[i - 4 + 1 +
(j + 1) * w * 4] - 2 * tempMask[i + 1 + (j + 1) * w * 4] - tempMask[i + 1 + 4 + (j + 1) * w * 4]);

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

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

                          + tempMask[i + 4 + 2 + (j - 1) * w * 4] - tempMask[i - 4 + 2 +
(j + 1) * w * 4] - 2 * tempMask[i + 2 + (j + 1) * w * 4] - tempMask[i + 2 + 4 + (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 = sobelImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

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

           return
sobelImage;

           }

           else

           {

               returnnull;

           }  

       }


Win8Metro(C#)数字图像处理--2.12Sobel边缘检测的更多相关文章

  1. Win8Metro(C#)数字图像处理--2.14Prewitt 边缘检测

    原文:Win8Metro(C#)数字图像处理--2.14Prewitt 边缘检测  [函数名称] 图像Prewitt边缘检测函数PrewittEdgeProcess(WriteableBitmap ...

  2. Win8Metro(C#)数字图像处理--2.13Roberts边缘检测

    原文:Win8Metro(C#)数字图像处理--2.13Roberts边缘检测  [函数名称] 图像Roberts边缘检测函数RobertEdgeProcess(WriteableBitmap s ...

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

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

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

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

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

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

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

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

  7. Win8Metro(C#)数字图像处理--2.32图像曝光算法

    原文:Win8Metro(C#)数字图像处理--2.32图像曝光算法  [函数名称] 图像曝光函数ExposureProcess(WriteableBitmap src,int exposureV ...

  8. Win8Metro(C#)数字图像处理--2.27图像加法运算

    原文:Win8Metro(C#)数字图像处理--2.27图像加法运算  [函数名称] 图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap a ...

  9. Win8Metro(C#)数字图像处理--2.28图像乘法运算

    原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算  [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...

随机推荐

  1. Android应用程序文件缓存getCacheDir()和getExternalCacheDir()

    如果Android引用程序需要缓存临时文件,系统提供了一个可管理的“内部缓存”和一个不可管理的“外部缓存”,分别调用getCacheDir()和getExternalCacheDir()方法,可以从当 ...

  2. C++网络编程方面的开源项目

    Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力. ...

  3. 实现上拉加载更多的SwipeRefreshLayout

    转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/49992269 本文出自:[江清清的博客] (一).前言: [好消息] ...

  4. 回顾Oracle几个用到的基本语句

    create table t_name(id number,name varchar2(10)); drop table t_name; select * from table_name where ...

  5. Ubuntu 安装 SSH server 并配置 SSH 无密码登录

    https://hinine.com/install-and-configure-ssh-server-on-ubuntu/ Ubuntu 安装 SSH server 并配置 SSH 无密码登录 发表 ...

  6. MySQL实现类似Oracle中的nextval和currval

    CREATE TABLE `sequence` ( `seq_name` varchar(50) NOT NULL, `current_val` int(11) NOT NULL, `incremen ...

  7. tap code —— 两个一位数字编码一个字母

    5 * 5 的矩阵(表格)编码 26 个字母 单词中如果出现 K,就用 C 代替,所以其实也可视为表中无 K 这个字母(据说拉丁文中 K 都是用 C 来代替的): 在<疑犯追踪>(POI, ...

  8. 配置文件——App.config文件读取和修改

    作为普通的xml文件读取的话,首先就要知道怎么寻找文件的路径.我们知道一般配置文件就在跟可执行exe文件在同一目录下,且仅仅在名称后面添加了一个.config 因此,可以用Application.Ex ...

  9. iText 制作PDF

    前言 由于在MVC项目中需要使用PDF,所以自己抽空也来看看itext,以便于丰富自己的知识吧.在此也简单的记录一下,说不定以后可能还用的到. 在此您可以下载你想使用的版本http://sourcef ...

  10. SpringBoot、Groovy

    Java——搭建自己的RESTful API服务器(SpringBoot.Groovy)   这又是一篇JavaWeb相关的博客,内容涉及: SpringBoot:微框架,提供快速构建服务的功能 Sp ...