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



[函数名称]

图像Prewitt边缘检测函数PrewittEdgeProcess(WriteableBitmap
src)

[函数代码]

       ///<summary>

       ///
Smooth edge detection.

       ///</summary>

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

       ///<returns></returns>

       publicstaticWriteableBitmap
PrewittEdgeProcess(WriteableBitmap src)////14
Prewitt边缘检测

       {

           if(src!=null
)

           {

           int
w = src.PixelWidth;

           int
h = src.PixelHeight;

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

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

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

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

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

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

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

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

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

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

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

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

           sTemp.Seek(0,SeekOrigin.Begin);

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

           return
smoothImage;

           }

           else

           {

               returnnull;

           }  

       }


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

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

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

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

    原文:Win8Metro(C#)数字图像处理--2.12Sobel边缘检测  [函数名称] 图像Sobel边缘检测函数SobelEdgeProcess(WriteableBitmap src) [ ...

  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. IT增值服务客户案例(二):河南郑州大四实习生,职业规划和项目开发指导

    客户整体情况,河南郑州大四在校学生,目前在企业实习,从事Java开发工作.有一定的项目开发经验,对Java周边技术有基本的理解. 客户购买的是"拜师学艺"服务,按月付款. 经过多次 ...

  2. 我的Boss有性能优化强迫症

    我有一个Boss,他曾经在阿里深造,在UC修炼,在一号店奔波. 经过几个月的合作开发和技术交流,我发现他非常在乎程序的性能,但是呢,对于有些地方,我觉得划不来. 比如说, 把数据库中的30多条记录,查 ...

  3. Access control differentiation in trusted computer system

    A trusted computer system that offers Linux® compatibility and supports contemporary hardware speeds ...

  4. storm 经常使用类

    弄 <dependency> <groupId>org.apache.storm</groupId> <artifactId>storm-core< ...

  5. 【38.46%】【codeforces 615E】Hexagons

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  6. Linux常用 bash

    学会Linux常用 bash命令 目录 基本操作1.1. 文件操作1.2. 文本操作1.3. 目录操作1.4. SSH, 系统信息 & 网络操作 基本 Shell 编程2.1. 变量2.2.  ...

  7. VC和matlab混合开发学习

    作者:朱金灿 来源:http://blog.csdn.net/clever101 第一种方式是直接调用Matlab Engine的接口.Matlab Engine 采用Client/Server的方式 ...

  8. windows 下 TensorFlow(GPU 版)的安装

    windows 10 64bit下安装Tensorflow+Keras+VS2015+CUDA8.0 GPU加速 0. 环境 OS:Windows 10,64 bit: 显卡:NVIDIA GeFor ...

  9. python 合并两个排序的链表

    题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则.   样例 给出 1->3->8->11->15->null,2-& ...

  10. 签署 Centennial Program Addendum,使用 Desktop Bridge 将 Win32 应用转制成 UWP

    原文 签署 Centennial Program Addendum,使用 Desktop Bridge 将 Win32 应用转制成 UWP 能上架 Windows 应用商店的并不一定必须是 UWP 应 ...