def color_hist(fg, bg)
      img = number_colors > 256 ? quantize(256) : self

      begin
        hist = img.color_histogram
      rescue NotImplementedError
        warn 'The color_histogram method is not supported by this version '\
                     'of ImageMagick/GraphicsMagick'
      else
        pixels = hist.keys.sort_by { |pixel| hist[pixel] }
        scale = HISTOGRAM_ROWS / (hist.values.max * AIR_FACTOR)

        histogram = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) do
          self.background_color = bg
          self.border_color = fg
        end

        x = 0
        pixels.each do |pixel|
          column = Array.new(HISTOGRAM_ROWS).fill { Pixel.new }
          HISTOGRAM_ROWS.times do |y|
            column[y] = pixel if y >= HISTOGRAM_ROWS - (hist[pixel] * scale)
          end
          histogram.store_pixels(x, 0, 1, HISTOGRAM_ROWS, column)
          x = x.succ
        end

        histogram['Label'] = 'Color Frequency'
        return histogram
      end
    end
def color_hist(fg, bg)
      img = number_colors > 256 ? quantize(256) : self

      begin
        hist = img.color_histogram
      rescue NotImplementedError
        warn 'The color_histogram method is not supported by this version '\
                     'of ImageMagick/GraphicsMagick'
      else
        pixels = hist.keys.sort_by { |pixel| hist[pixel] }
        scale = HISTOGRAM_ROWS / (hist.values.max * AIR_FACTOR)

        histogram = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) do
          self.background_color = bg
          self.border_color = fg
        end

        x = 0
        pixels.each do |pixel|
          column = Array.new(HISTOGRAM_ROWS).fill { Pixel.new }
          HISTOGRAM_ROWS.times do |y|
            column[y] = pixel if y >= HISTOGRAM_ROWS - (hist[pixel] * scale)
          end
          histogram.store_pixels(x, 0, 1, HISTOGRAM_ROWS, column)
          x = x.succ
        end

        histogram['Label'] = 'Color Frequency'
        return histogram
      end
    end
Make the color histogram. Quantize the image to 256 colors if necessary.