Image histogram generated by JFreeChart

不羁岁月 提交于 2019-12-24 17:59:11

问题


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?


回答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.



来源:https://stackoverflow.com/questions/7858411/image-histogram-generated-by-jfreechart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!