原文: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. Kolya and Tandem Repeat

     Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. ios开发视频播放后台下载功能实现 :1,ios播放视频 ,包含基于AVPlayer播放器,2,实现下载,iOS后台下载(多任务同时下载,单任务下载,下载进度,下载百分比,文件大小,下载状态)(真机调试功能正常)

    ABBPlayerKit ios开发视频播放后台下载功能实现 : 代码下载地址:https://github.com/niexiaobo/ABBPlayerKit github资料学习和下载地址:ht ...

  3. android之ContentProvider和Uri具体解释

    一.使用ContentProvider(内容提供者)共享数据 在android中ContentProvider的作用是对外共享数据,就是说能够通过ContentProvider把应用中的数据共享给其它 ...

  4. Spring学习笔记之六(数据源的配置)

    1.前言 上一篇博客分析了,Spring中实现AOP的两种动态代理的机制,以下这篇博客.来解说一下Spring中的数据源的配置.  2.DAO支持的模板类 Spring提供了非常多关于Dao支持的模板 ...

  5. 课堂随笔04--关于string类的一些基本操作

    //定义一个空字符串 string strA = string.Empty; strA = "abcdesabcskkkkk"; //获取字符串的长度 int i = strA.L ...

  6. 理解Java字符串常量池与intern()方法

    String s1 = "Hello"; String s2 = "Hello"; String s3 = "Hel" + "lo ...

  7. drawText文字绘制知识

    drawText(String text, float x, float y, Paint paint) x,y是基于文字基本线的,而不是android坐标系的左上角. 使用staticLayout进 ...

  8. Java入门程序

    JavaC.exe 编译器,编译.java文件 Java.exe 解释器,执行class文件 编译命令  javac HelloWorld.java 编译后 会产生同名的.class文件 javac编 ...

  9. Swift程式语言(中国版)(8.8 %)

    前言 今天Apple宣布了一项新的编程语言Swift.还提供了一个近400页The Swift Programming Language(Swift程式语言). 虽然我没有开发者账户.不能实际锻炼机S ...

  10. WPF 窗体中获取键盘和鼠标无操作时的超时提示

    原文:WPF 窗体中获取键盘和鼠标无操作时的超时提示 通过调用Windows API中的GetLastInputInfo来获取最后一次输入的时间 , , );            timer.Tic ...