Win8 Metro(C#)數字圖像處理--3.1圖像均值計算

原文: Win8 Metro(C#)數字圖像處理--3.1圖像均值計算

/// <summary>
        /// Mean value computing.
        /// </summary>
        /// <param name="src">The source image.</param>
        /// <returns></returns>
        public static double GetMeanProcess(WriteableBitmap src) ////32 圖像均值計算
        {
            if (src != null)
            {
                double mean = 0.0;
                int sum = 0;
                int gray = 0,number=0;
                byte[] temp = src.PixelBuffer.ToArray();
                for (int i = 0; i < temp.Length; i += 4)
                {
                    gray = (int)(temp[i] * 0.114 + temp[i + 1] * 0.587 + temp[i + 2] * 0.299);
                    sum += gray;
                    number++;
                }
                mean =(double)(sum/number);
                return mean;
            }
            else
            {
                return 0;
            }
        }

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