Win8 Metro(C#)數字圖像處理--2.65形態學輪廓提取算法

原文: Win8 Metro(C#)數字圖像處理--2.65形態學輪廓提取算法



[函數名稱]php

  形態學輪廓提取函數html

      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;
             }
         }

最後,分享一個專業的圖像處理網站(微像素),裏面有不少源代碼下載:
相關文章
相關標籤/搜索