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

C# 如何生成彩色图像的直方图?,c#,colors,histogram,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

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

这可能会为您提供一个起点:

    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]);
        }
    }
private void直方图()
{
//在位图中获取图像;这是如何从picturebox中获取图像
位图bm=(位图)pictureBox1.Image;
//将直方图存储在字典中
字典历史=新字典();
对于(int x=0;x
所以这不是一个“为我写这篇文章”的网站。你需要缩小你的问题范围,展示你的工作,并包括你收到的任何错误。使用
位图。GetPixel
{R,G,B}
颜色的值来开始…所发布的只是一个程序描述。然而,我们需要你去。我们不能确定你想从我们这里得到什么。请编辑您的帖子,以包含我们可以回答的有效问题。提醒:请确保您知道,要求我们为您编写程序和建议是离题的。如果您有Scilab,这是让算法部分工作的一个很好的方法,并且它具有内置的图形功能,那么您可以将算法翻译成C#或其他语言。几乎是我要写的内容+1.