當前位置: 首頁>>代碼示例>>C#>>正文


C# Bitmap.GetGrayscaleBytes方法代碼示例

本文整理匯總了C#中System.Drawing.Bitmap.GetGrayscaleBytes方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.GetGrayscaleBytes方法的具體用法?C# Bitmap.GetGrayscaleBytes怎麽用?C# Bitmap.GetGrayscaleBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.GetGrayscaleBytes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DetectEdges

 public static Bitmap DetectEdges(Bitmap original, ExchangeMask maskType)
 {
     var mask = masks[(int)maskType];
     var current = new Bitmap(original.Width, original.Height);
     var gsBytes = original.GetGrayscaleBytes();
     for (var i = 0; i < current.Width; i++)
         for (var j = 0; j < current.Height; j++) {
             var newVal = GetSiblings(gsBytes, i, j)
                 .Zip(mask, (a, b) => a * b)
                 .Sum();
             newVal = (newVal > limit) ? 255 : 0;
             current.SetPixel(i, j, Color.FromArgb(255, newVal, newVal, newVal));
         }
     return current;
 }
開發者ID:mtratsiuk,項目名稱:Labs,代碼行數:15,代碼來源:EdgeDetection.cs

示例2: Equalize

        public static Bitmap Equalize(Bitmap original)
        {
            var current = new Bitmap(original.Width, original.Height);
            var oldLevels = original.GetGrayscaleBytes();
            var newLevels = GetNewBrightnessLevels(oldLevels.Get1dArray());
            for (var i = 0; i < original.Width; i++) {
                for (var j = 0; j < original.Height; j++) {
                    var oldLevel = oldLevels[i, j];
                    var newLevel = newLevels[oldLevel];
                    current.SetPixel(i, j, Color.FromArgb(255, newLevel, newLevel, newLevel));
                }
            }

            return current;
        }
開發者ID:mtratsiuk,項目名稱:Labs,代碼行數:15,代碼來源:Equalization.cs

示例3: Normalize

        public static Bitmap Normalize(Bitmap original)
        {
            var current = new Bitmap(original.Width, original.Height);
            var gsBytes = original.GetGrayscaleBytes();
            var gsBytesArr = gsBytes.Get1dArray();
            var oldMin = gsBytesArr.Min();
            var oldMax = gsBytesArr.Max();
            var newMin = 0;
            var newMax = 255;

            for (var i = 0; i < current.Width; i++) {
                for (var j = 0; j < current.Height; j++) {
                    var oldVal = gsBytes[i, j];
                    var newVal = (oldVal - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin;
                    current.SetPixel(i, j, Color.FromArgb(255, newVal, newVal, newVal));
                }
            }

            return current;
        }
開發者ID:mtratsiuk,項目名稱:Labs,代碼行數:20,代碼來源:Normalization.cs

示例4: Process

        public static Bitmap Process(Bitmap image)
        {
            var current = new Bitmap(image.Width, image.Height);
            var currentBin = new Bitmap(image.Width, image.Height);

            var gs = image.GetGrayscaleBytes();
            var binarized = Binarize(gs);

            for (var i = 0; i < currentBin.Width; i++) {
                for (var j = 0; j < currentBin.Height; j++) {
                    var tmp = binarized[i, j] == 1 ? Color.White : Color.Black;
                    currentBin.SetPixel(i, j, tmp);
                }
            }

            var scanned = Scan(binarized);
            var curColor = 0;
            var colorsDict = new Dictionary<int, Color>();

            for (var i = 0; i < current.Width; i++) {
                for (var j = 0; j < current.Height; j++) {
                    var mark = scanned[i, j];
                    if (mark == 0) current.SetPixel(i, j, Color.White);
                    if (mark >= 2) {
                        Color tmpCol;
                        if (colorsDict.ContainsKey(mark)) tmpCol = colorsDict[mark];
                        else {
                            curColor = (curColor == colors.Count() - 1) ? 0 : curColor + 1;
                            colorsDict.Add(mark, colors[curColor]);
                            tmpCol = colors[curColor];
                        }
                        current.SetPixel(i, j, tmpCol);
                    }
                }
            }

            currentBin.Save("SAVEDBIN.bmp");
            current.Save("SAVED.bmp");
            return current;
        }
開發者ID:mtratsiuk,項目名稱:Labs,代碼行數:40,代碼來源:CV.cs


注:本文中的System.Drawing.Bitmap.GetGrayscaleBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。