原文: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. [Ramda] Refactor to Point Free Functions with Ramda using compose and converge

    In this lesson we'll take some existing code and refactor it using some functions from the Ramda lib ...

  2. [Ramda] Count Words in a String with Ramda's countBy and invert

    You can really unlock the power of ramda (and functional programming in general) when you combine fu ...

  3. 关闭 You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法

    当我的MainActivity继承自v7包中的ActionBarActivity或者AppCompatActivity时,如果在style.xml文件中指定MainActivity所使用的样式如下: ...

  4. Opencv中使用Surf特征实现图像配准及对透视变换矩阵H的平移修正

    图像配准需要将一张测试图片按照第二张基准图片的尺寸.角度等形态信息进行透视(仿射)变换匹配,本例通过Surf特征的定位和匹配实现图像配准. 配准流程: 1. 提取两幅图像的Surf特征 2. 对Sur ...

  5. [转至云风的博客]开发笔记 (2) :redis 数据库结构设计

    接上回,按照我们一期项目的需求,昨天我简单设计了数据库里的数据格式.数据库采用的是 Redis ,我把它看成一个远端的数据结构保存设备.它提供基本的 Key-Value 储存功能,没有层级表.如果需要 ...

  6. Shell脚本实现在Linux系统中自动安装JDK

    A:本脚本运行的机器,Linux B:待安装JDK的机器, Linux 首先在脚本运行的机器A上确定可以ssh无密码登录到待安装jdk的机器B上,然后就可以在A上运行本脚本: 复制代码 代码如下: $ ...

  7. 项目构建之maven篇:6.生命周期与插件

    项目生命周期 清理 初始化 编译 測试 打包 部署 三套生命周期 1.clean pre-clean 运行一些须要在clean之前完毕的工作 clean 移除全部上一次构建生成的文件 post-cle ...

  8. DirectX11学习笔记

    一.假定每种颜色的原始点是不同,表面的这样的原始颜色将被指定为每种颜色用线性内插值传授,这个被称为高洛德着色(Gouraud Shading).也称为平滑阴影: 二.三维图元:Direct3D中.使用 ...

  9. hexo从零配置next全纪录

    1.按照官网按照hexo: 2.下载next(目前使用的是最新发布版本6.4.1),解压后重命名为next,放在hexo工程themes目录下: 3.网站配置文件_config.yml中,改成them ...

  10. Risk Adaptive Information Flow Based Access Control

    Systems and methods are provided to manage risk associated with access to information within a given ...