【问题标题】:How can I produce a histogram of a color image? [closed]如何生成彩色图像的直方图? [关闭]
【发布时间】:2015-01-24 00:37:24
【问题描述】:

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

【问题讨论】:

  • 所以不是“为我写这个!”一种网站。您需要缩小问题范围,展示您的工作并包括您收到的任何错误。
  • 使用 Bitmap.GetPixel{R,G,B} 的值 Color 让您开始...
  • 所有发布的都是程序描述。但是,我们需要您ask a question。我们无法确定您想从我们这里得到什么。请编辑您的帖子以包含我们可以回答的有效问题。提醒:请确保您知道what is on-topic here,请我们为您编写程序,建议是题外话。
  • 如果你有 Scilab,这是让算法部分工作的好方法,它具有内置的图形功能,然后可以将算法翻译成 C# 或其他语言。

标签: c# colors histogram


【解决方案1】:

这可能会给你一个起点:

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

【讨论】:

  • 几乎逐字逐句地写下我要写的内容。 +1
猜你喜欢
  • 2011-06-30
  • 1970-01-01
  • 2014-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-03
相关资源
最近更新 更多