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



[函数名称]

  形态学轮廓提取函数

      WriteableBitmap MorcontourextractionProcess(WriteableBitmap src)

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

       /// 
        /// Morgraphy contour extraction process.
        /// 
        /// The source image.
        /// 
         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;
             }
         }

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

最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:
http://www.zealpixel.com/portal.php

你可能感兴趣的:(Win8,Metro(C#),数字图像处理)