我在java中编写了一个函数,它根据灰度直方图计算2D图像的熵。 现在我想检查它是否正常工作。如何创建具有已知熵的图像?
public static int[] computeHistogram2D(Grid2D grid, int bins, int width, int heigth) {
int[] histo = new int[bins];
double[] histof = new double[bins];
float val = 0;
float max = -Float.MAX_VALUE;
float min = Float.MAX_VALUE;
//maxVal: -3.4028235E38 .. minVal: 3.4028235E38
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;
}
}
}
for (int i = 0; i < width; i++) {
for (int j = 0 ; j < heigth; j++) {
val = grid.getAtIndex(i, j);
int b = (int)val;
histo[b]++;
histof[b]++;
}
}
System.out.println("maxValgrid2D: " +max + " minValGrid2D: " + min);
VisualizationUtil.createPlot(histof, "histogram2D", "intensity", "count").show();
return histo;
}
static double computeEntropy2D(Grid2D grid, int width, int height) {
System.out.println("width:" +width + "height " + height);
double[] entropyArray = new double[40];
double entropy = 0.0;
int bins = 40;
int sizeX = width;
int sizeY = height;
int sizeZ = 1 ;
int size = sizeX * sizeY * sizeZ; //Total pixels
System.out.println("size: " + size);
int[] histo = computeHistogram2D(grid, bins, sizeX, sizeY);
for (int i = 0; i < bins; i++) {
double val = (double) histo[i] / (double) size; //Normalized Histogram
entropy = entropy + (-(val * Math.log (val + 0.00001)));
entropyArray[i] = entropy;
//System.out.println("maxValgrid2D: " +max + " minValGrid2D: " + min);
}
VisualizationUtil.createPlot(entropyArray, "entPlot", "tX", "Entropy").show();
System.out.println("entropy2D: " + entropy);
return entropy;
}
我正在研究我的硕士论文,当我写这篇文章时,我的超级名称说你必须用一些已知熵的图像检查你的代码,你必须使用已知的熵创建图像...我搜索了很多但是无法找到任何可以帮助我的东西...