原文: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. Erlang基础知识集锦

    http://wenku.baidu.com/link?url=or-8mkUYUM0uVeqCYESGe93YIlh2IDLP7lFOwRlwr8Syf3PeHbwJC5DPCErs4NFrb1p4 ...

  2. Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty

    原文:Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty public class NullToEmptyStringResolver : De ...

  3. php课程 6-20 字符串基础和去除空格和字符串填补函数

    php课程 6-20  字符串基础和去除空格和字符串填补函数 一.总结 一句话总结: 二.字符串 字符串定义:$str='hello world!'; 输出字符串:echo $str;print $s ...

  4. BZOJ 1369 Gem - 树型dp

    传送门 题目大意: 给一棵树上每个点一个正权值,要求父子的权值不同,问该树的最小权值和是多少. 题目分析: 证不出来最少染色数,那就直接信仰用20来dp吧:dp[u][i]表示u节点权值赋为i时u子树 ...

  5. Fiddler快速入门(还有一个功能就是不经过网络,直接模拟一个响应返回给客户端)

    Fiddler是一个免费.强大.跨平台的HTTP抓包工具.Wireshark也是一个强大的抓包工具,不过Wireshark是一个通用的抓包工具,主要精力放在各种协议上了,针对HTTP的特定功能较少.所 ...

  6. android 如何创建配置文件和读配置文件

    因为一些配置信息,多处用到的.且以后可能变更的,我想写个.prorperties配置文件给管理起来.在studio中新建一个Assets文件-->新建一个file文件类型为properties文 ...

  7. ServletContextListener和ContextLoaderListener的区别

    ServletContext 被 Servlet 程序用来与 Web 容器通信.例如写日志,转发请求.每一个 Web 应用程序含有一个Context,被Web应用内的各个程序共享.因为Context可 ...

  8. C# opcode 查询源码

    Add|将两个值相加并将结果推送到计算堆栈上.Add.Ovf|将两个整数相加,执行溢出检查,并且将结果推送到计算堆栈上.Add.Ovf.Un|将两个无符号整数值相加,执行溢出检查,并且将结果推送到计算 ...

  9. Codeforces 39J Spelling Check hash

    主题链接:点击打开链接 意甲冠军: 特定2弦 选择中删除一个字符串的第一个字母,得2个字符串全然同样 问哪些位置能够选 思路: hash求前缀后缀.然后枚举位置 #include <cstdio ...

  10. Android Gallery组件实现循环显示图像

    Gallery组件主要用于横向显示图像列表,只是按常规做法.Gallery组件仅仅能有限地显示指定的图像.也就是说,假设为Gallery组件指定了10张图像,那么当Gallery组件显示到第10张时, ...