1

I want to display histogram of image color channels. At first my reading of pixels looks like:

   for(int i=0; i<width; i++)
        for(int j=0; j<height; j++) {
          data=writeableRaster.getDataElements(i, j, null);
          red=colorModel.getRed(data);
          green=colorModel.getGreen(data);
          blue=colorModel.getBlue(data);
          rgb=(red+green+blue)/3;
          ++redL[red];
          ++greenL[green];
          ++blueL[blue];
          ++rgbL[rgb];
        }
    }

I also have additional method for creating chart with given channel colors table:

        int number = channelHistogram.length;
        HistogramDataset dataset = new HistogramDataset();
        dataset.setType(HistogramType.RELATIVE_FREQUENCY);
        dataset.addSeries("Hist",channelHistogram,number);
        String plotTitle = "Hist"; 
        String xaxis = "number";
        String yaxis = "value"; 
        PlotOrientation orientation = PlotOrientation.VERTICAL; 
        boolean show = false; 
        boolean toolTips = false;
        boolean urls = false; 
        JFreeChart chart = ChartFactory.createHistogram( plotTitle, xaxis, yaxis, 
                 dataset, orientation, show, toolTips, urls);

But chart is wrong displayed. It means at Y axis there are "low" values (from ~ 0 - 0.09) and at X axis there aren't values from scope 0 - 255. Any help?

bontade
  • 3,194
  • 6
  • 48
  • 75

1 Answers1

1
dataset.setType(HistogramType.RELATIVE_FREQUENCY);

Can you try setting different options here and see if it helps? Also if you can show what channelHistogram field contains that may be helpful to debug.

Ashwinee K Jha
  • 9,187
  • 2
  • 25
  • 19
  • Inside method checked that size of array is equal 256. Values looks like: `7545.0 2939.0 3570.0 3266.0 2861.0 2525.0`. I tried use other other HistogramType options but there was similar effect. – bontade Oct 22 '11 at 10:54
  • 1
    Lets say you provide the double array as {1,5,9,3,5} The histogram dataset interprets it as 1-5 frequency 4 5-10 frequency 1 and it will accordingly show two bars with corresponding heights. If you instead want to plot bars with heights 1,5,9... etc as per the array then using a bar chart with each point added as new series. – Ashwinee K Jha Oct 22 '11 at 11:48
  • Thanks @AKJ. Now I'm using BarChart – bontade Oct 22 '11 at 16:36