Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package azgracompress.cli.functions;
import azgracompress.cli.CustomFunctionBase;
import azgracompress.cli.ParsedCliOptions;
import azgracompress.data.ImageU16;
import azgracompress.io.RawDataIO;
import azgracompress.utilities.Utils;
import java.io.IOException;
public class EntropyCalculation extends CustomFunctionBase {
/**
* Base constructor with parsed CLI options.
*
* @param options Parsed cli options.
*/
public EntropyCalculation(ParsedCliOptions options) {
super(options);
}
@Override
public boolean run() {
ImageU16 plane = null;
System.out.println(String.format("Input file: %s", options.getInputFile()));
for (int planeIndex = 0; planeIndex < options.getImageDimension().getZ(); planeIndex++) {
try {
plane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
planeIndex);
} catch (IOException e) {
e.printStackTrace();
return false;
}
final double planeEntropy = Utils.calculateEntropy(plane.getData());
System.out.println(String.format("%d\t%.4f", planeIndex, planeEntropy));
}
return true;
}
}