c# - 如何生成彩色图像的直方图?

标签 c# colors histogram

<分区>

如何生成彩色图像的直方图?

最佳答案

这可能会给你一个起点:

    private void HistoGram()
    {
        // Get your image in a bitmap; this is how to get it from a picturebox
        Bitmap bm = (Bitmap) pictureBox1.Image;  
        // Store the histogram in a dictionary          
        Dictionary<Color, int> histo = new Dictionary<Color,int>();
        for (int x = 0; x < bm.Width; x++)
        {
            for (int y = 0; y < bm.Height; y++)
            {
                // Get pixel color 
                Color c = bm.GetPixel(x,y);
                // If it exists in our 'histogram' increment the corresponding value, or add new
                if (histo.ContainsKey(c))
                    histo[c] = histo[c] + 1;
                else
                    histo.Add(c, 1);
            }
        }
        // This outputs the histogram in an output window
        foreach (Color key in histo.Keys)
        {
            Debug.WriteLine(key.ToString() + ": " + histo[key]);
        }
    }

关于c# - 如何生成彩色图像的直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27136360/

相关文章:

c# - 调试 CLR 挂起

java - 如何使用 Java AWT setBackground

bitmap - GNUPLOT 每个直方图条具有不同的颜色

r - 比较两个向量的分布

c# - 在 XML 序列化中包含数组索引

c# - 在C#中打印网页的一部分

c# - 按天数过滤日期列表

具有特定线条颜色的 HTML 文本区域

string - Web Assembly 绘制灰色 Canvas

具有负值的mysql直方图