Win8 Metro(C#)数字图像处理--2.65形态学轮廓提取算法

简介: 原文:Win8 Metro(C#)数字图像处理--2.65形态学轮廓提取算法  [函数名称]   形态学轮廓提取函数       WriteableBitmap MorcontourextractionPr...
原文: Win8 Metro(C#)数字图像处理--2.65形态学轮廓提取算法



[函数名称]

  形态学轮廓提取函数

      WriteableBitmap MorcontourextractionProcess(WriteableBitmap src)

       /// <summary>
        /// Morgraphy contour extraction process.
        /// </summary>
        /// <param name="src">The source image.</param>
        /// <returns></returns>
         public static WriteableBitmap MorcontourextractionProcess(WriteableBitmap src)////形态学轮廓提取
         {
             if (src != null)
             {
                 int w = src.PixelWidth;
                 int h = src.PixelHeight;
                 WriteableBitmap corrosionImage = new WriteableBitmap(w, h);
                 byte[] temp = src.PixelBuffer.ToArray();
                 byte[] tempMask = (byte[])temp.Clone();
                 for (int j = 0; j < h; j++)
                 {
                     for (int i = 0; i < w; i++)
                     {
                         if (i == 0 || i == w - 1 || j == 0 || j == h - 1)
                         {
                             temp[i * 4 + j * w * 4] = (byte)255;
                             temp[i * 4 + 1 + j * w * 4] = (byte)255;
                             temp[i * 4 + 2 + j * w * 4] = (byte)255;
                         }
                         else
                         {
                             if (tempMask[i * 4 - 4 + j * w * 4] == 255 && tempMask[i * 4 + j * w * 4] == 255 && tempMask[i * 4 + 4 + j * w * 4] == 255
                                 && tempMask[i * 4 + (j - 1) * w * 4] == 255 && tempMask[i * 4 + (j + 1) * w * 4] == 255)
                             {
                                 temp[i * 4 + j * w * 4] = (byte)255;
                                 temp[i * 4 + 1 + j * w * 4] = (byte)255;
                                 temp[i * 4 + 2 + j * w * 4] = (byte)255;
                             }
                             else
                             {
                                 temp[i * 4 + j * w * 4] = 0;
                                 temp[i * 4 + 1 + j * w * 4] = 0;
                                 temp[i * 4 + 2 + j * w * 4] = 0;
                             }
                         }
                     }
                 }
                 for (int i = 0; i < temp.Length; i++)
                 {
                     temp[i] = (byte)(tempMask[i]-temp[i]);
                 }
                 Stream sTemp = corrosionImage.PixelBuffer.AsStream();
                 sTemp.Seek(0, SeekOrigin.Begin);
                 sTemp.Write(temp, 0, w * 4 * h);
                 return corrosionImage;
             }
             else
             {
                 return null;
             }
         }

最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:

目录
相关文章
|
5天前
|
算法
基于图像形态学处理的路面裂缝检测算法matlab仿真
基于图像形态学处理的路面裂缝检测算法matlab仿真
|
5天前
|
搜索推荐 算法 C#
【Unity 3D】C#中冒泡排序、选择排序、插入排序等算法的详解(附源码 超详细)
【Unity 3D】C#中冒泡排序、选择排序、插入排序等算法的详解(附源码 超详细)
58 1
|
5月前
|
存储 资源调度 算法
基于图像形态学处理和边缘提取算法的路面裂痕检测matlab仿真
基于图像形态学处理和边缘提取算法的路面裂痕检测matlab仿真
|
8月前
|
算法 计算机视觉
基于图像形态学处理的目标几何形状检测算法matlab仿真
基于图像形态学处理的目标几何形状检测算法matlab仿真
|
8月前
|
机器学习/深度学习 算法 计算机视觉
基于机器视觉工具箱和形态学处理的视频中目标形状检测算法matlab仿真
基于机器视觉工具箱和形态学处理的视频中目标形状检测算法matlab仿真
|
9月前
|
机器学习/深度学习 算法 计算机视觉
基于形态学处理的条形码数字分割和识别算法MATLAB仿真
基于形态学处理的条形码数字分割和识别算法MATLAB仿真
|
9月前
|
算法 安全 机器人
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的Pow伽马变换算法增强(C#)
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的Pow伽马变换算法增强(C#)
45 0
|
9月前
|
算法 安全 机器人
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的线性灰度变换Emphasize 算法增强(C#)
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的线性灰度变换Emphasize 算法增强(C#)
54 0
|
9月前
|
算法 安全 机器人
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的线性灰度变换ScaleImage算法增强(C#)
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的线性灰度变换ScaleImage算法增强(C#)
56 0
|
9月前
|
算法 安全 机器人
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的直方图算法增强(C#)
Baumer工业相机堡盟工业相机如何联合BGAPISDK和Halcon实现图像的直方图算法增强(C#)
62 0