我使用Conrad开源软件,并且我想计算图像的直方图。为此,我准确地根据此链接https://www2.southeastern.edu/Academics/Faculty/dgurney/Math241/StatTopics/HistGen.htm
找到了图像值的最小值和最大值以及range = max-min,然后找到了下限和上限现在我的问题是程序如何根据bin-Width划分范围,如何将每个图像值分配给每个bin-width(类)。
public static int[] computeHistogram2D(Grid2D grid, int bins, int width, int heigth) {
float val = 0;
float max = -Float.MAX_VALUE;
float min = Float.MAX_VALUE;
for (int i = 0; i < width; i++) {
for (int j = 0 ; j < heigth; j++) {
val = grid.getAtIndex(i, j);
if (val > max) {
max = val;
}
if (val < min) {
min = val;
}
}
}
int[] histo = new int[bins];
double[] histof = new double[bins];
float range = max - min;
float lowerLimit = range/(float)bins;
float upperBound = range / (float) (bins -1);
//float binWidth =( upperBound - lowerLimit)/bins;
for (int i = 0; i < width; i++) {
for (int j = 0 ; j < heigth; j++) {
val = grid.getAtIndex(i, j);
int b = (int) ((val - min) / upperBound);
histo[b]++;
histof[b]++;
System.out.println(" intervals " + b );
}
}
System.out.println("maxValgrid2D: " +max + " minValGrid2D: " + min + " binWidth "+ upperBound);
VisualizationUtil.createPlot(histof, "Histogram2D", "intensity", "count").show();
return histo;
}
This is what I got as a result,which seems to be wrong because the max-value of my pic is 21.12