def histogram(fg = 'white', bg = 'black')
      red   = Array.new(HISTOGRAM_COLS, 0)
      green = Array.new(HISTOGRAM_COLS, 0)
      blue  = Array.new(HISTOGRAM_COLS, 0)
      alpha = Array.new(HISTOGRAM_COLS, 0)
      int   = Array.new(HISTOGRAM_COLS, 0)

      rows.times do |row|
        pixels = get_pixels(0, row, columns, 1)
        pixels.each do |pixel|
          red[pixel.red & MAX_QUANTUM] += 1
          green[pixel.green & MAX_QUANTUM] += 1
          blue[pixel.blue & MAX_QUANTUM] += 1

          # Only count opacity channel if some pixels are not opaque.
          alpha[pixel.opacity & MAX_QUANTUM] += 1 unless opaque?
          v = pixel_intensity(pixel)
          int[v] += 1
        end
      end

      # Scale to chart size. When computing the scale, add some "air" between
      # the max frequency and the top of the histogram. This makes a prettier chart.
      # The RGBA and intensity histograms are all drawn to the same scale.

      max = [red.max, green.max, blue.max, alpha.max, int.max].max
      scale = HISTOGRAM_ROWS / (max * AIR_FACTOR)

      charts = ImageList.new

      # Add the thumbnail.
      thumb = copy
      thumb['Label'] = File.basename(filename)
      charts << thumb

      # Compute the channel and intensity histograms.
      channel_hists = channel_histograms(red, green, blue, int, scale, fg, bg)

      # Add the red, green, and blue histograms to the list
      charts << channel_hists.shift
      charts << channel_hists.shift
      charts << channel_hists.shift

      # Add Alpha channel or image stats
      charts << if !opaque?
                  alpha_hist(alpha, scale, fg, bg)
                else
                  info_text(fg, bg)
                end

      # Add the RGB histogram
      charts << channel_hists.shift

      # Add the intensity histogram.
      charts << intensity_hist(channel_hists.shift)

      # Add the color frequency histogram.
      charts << color_hist(fg, bg)

      # Make a montage.
      histogram = charts.montage do
        self.background_color = bg
        self.stroke = 'transparent'
        self.fill = fg
        self.border_width = 1
        self.tile         = '4x2'
        self.geometry     = "#{HISTOGRAM_COLS}x#{HISTOGRAM_ROWS}+10+10"
      end

      histogram
    end
def histogram(fg = 'white', bg = 'black')
      red   = Array.new(HISTOGRAM_COLS, 0)
      green = Array.new(HISTOGRAM_COLS, 0)
      blue  = Array.new(HISTOGRAM_COLS, 0)
      alpha = Array.new(HISTOGRAM_COLS, 0)
      int   = Array.new(HISTOGRAM_COLS, 0)

      rows.times do |row|
        pixels = get_pixels(0, row, columns, 1)
        pixels.each do |pixel|
          red[pixel.red & MAX_QUANTUM] += 1
          green[pixel.green & MAX_QUANTUM] += 1
          blue[pixel.blue & MAX_QUANTUM] += 1

          # Only count opacity channel if some pixels are not opaque.
          alpha[pixel.opacity & MAX_QUANTUM] += 1 unless opaque?
          v = pixel_intensity(pixel)
          int[v] += 1
        end
      end

      # Scale to chart size. When computing the scale, add some "air" between
      # the max frequency and the top of the histogram. This makes a prettier chart.
      # The RGBA and intensity histograms are all drawn to the same scale.

      max = [red.max, green.max, blue.max, alpha.max, int.max].max
      scale = HISTOGRAM_ROWS / (max * AIR_FACTOR)

      charts = ImageList.new

      # Add the thumbnail.
      thumb = copy
      thumb['Label'] = File.basename(filename)
      charts << thumb

      # Compute the channel and intensity histograms.
      channel_hists = channel_histograms(red, green, blue, int, scale, fg, bg)

      # Add the red, green, and blue histograms to the list
      charts << channel_hists.shift
      charts << channel_hists.shift
      charts << channel_hists.shift

      # Add Alpha channel or image stats
      charts << if !opaque?
                  alpha_hist(alpha, scale, fg, bg)
                else
                  info_text(fg, bg)
                end

      # Add the RGB histogram
      charts << channel_hists.shift

      # Add the intensity histogram.
      charts << intensity_hist(channel_hists.shift)

      # Add the color frequency histogram.
      charts << color_hist(fg, bg)

      # Make a montage.
      histogram = charts.montage do
        self.background_color = bg
        self.stroke = 'transparent'
        self.fill = fg
        self.border_width = 1
        self.tile         = '4x2'
        self.geometry     = "#{HISTOGRAM_COLS}x#{HISTOGRAM_ROWS}+10+10"
      end

      histogram
    end
Create the histogram montage.