Skip to content
Snippets Groups Projects
Commit e79d3f27 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Small improvement in EntropyCalculation.

parent 675735d8
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,9 @@ import cz.it4i.qcmp.cli.functions.EntropyCalculation;
import cz.it4i.qcmp.compression.ImageCompressor;
import cz.it4i.qcmp.compression.ImageDecompressor;
import cz.it4i.qcmp.fileformat.FileExtensions;
import cz.it4i.qcmp.utilities.ColorConsole;
import cz.it4i.qcmp.utilities.Stopwatch;
import org.apache.commons.cli.*;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class DataCompressor {
public static void main(final String[] args) {
......@@ -55,23 +52,28 @@ public class DataCompressor {
case Compress: {
final String label =
compressionOptionsCLIParsed.getQuantizationType().toString() + " " + compressionOptionsCLIParsed.getQuantizationVector().toString();
final Stopwatch stopwatch = Stopwatch.startNew();
// final Stopwatch stopwatch = Stopwatch.startNew();
final ImageCompressor compressor = new ImageCompressor(compressionOptionsCLIParsed);
if (!compressor.compress()) {
System.err.println("Errors occurred during compression.");
}
stopwatch.stop();
ColorConsole.printf(ColorConsole.Color.Green, label);
ColorConsole.printf(ColorConsole.Color.Green,
"Compression completed in %d ms.",
stopwatch.getElapsedInUnit(TimeUnit.MILLISECONDS));
// stopwatch.stop();
// ColorConsole.printf(ColorConsole.Color.Green, label);
// ColorConsole.printf(ColorConsole.Color.Green,
// "Compression completed in %d ms.",
// stopwatch.getElapsedInUnit(TimeUnit.MILLISECONDS));
}
break;
case Decompress: {
// final Stopwatch stopwatch = Stopwatch.startNew();
final ImageDecompressor decompressor = new ImageDecompressor(compressionOptionsCLIParsed);
if (!decompressor.decompressToFile()) {
System.err.println("Errors occurred during decompression.");
}
// stopwatch.stop();
// ColorConsole.printf(ColorConsole.Color.Green,
// "Decompression completed in %d ms.",
// stopwatch.getElapsedInUnit(TimeUnit.MILLISECONDS));
}
break;
......@@ -90,8 +92,9 @@ public class DataCompressor {
// NOTE(Moravec): Custom function class here |
// V
//CustomFunctionBase customFunction = new MeasurePlaneErrorFunction(parsedCliOptions);
final CustomFunctionBase customFunction = new EntropyCalculation(compressionOptionsCLIParsed);
if (!customFunction.run()) {
// final CustomFunctionBase customFunction = new EntropyCalculation(compressionOptionsCLIParsed);
final CustomFunctionBase cf = new EntropyCalculation(compressionOptionsCLIParsed);
if (!cf.run()) {
System.err.println("Errors occurred during custom function.");
}
}
......
......@@ -6,7 +6,9 @@ import cz.it4i.qcmp.io.loader.IPlaneLoader;
import cz.it4i.qcmp.io.loader.PlaneLoaderFactory;
import cz.it4i.qcmp.utilities.Utils;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class EntropyCalculation extends CustomFunctionBase {
/**
......@@ -20,6 +22,7 @@ public class EntropyCalculation extends CustomFunctionBase {
@Override
public boolean run() {
System.out.println("Running EntropyCalculation for " + options.getInputDataInfo().getCacheFileName());
final IPlaneLoader loader;
try {
loader = PlaneLoaderFactory.getPlaneLoaderForInputFile(options.getInputDataInfo());
......@@ -28,19 +31,24 @@ public class EntropyCalculation extends CustomFunctionBase {
return false;
}
for (int planeIndex = 0; planeIndex < options.getInputDataInfo().getDimensions().getZ(); planeIndex++) {
final int[] planeData;
try {
planeData = loader.loadPlaneData(planeIndex);
} catch (final IOException e) {
System.err.printf("Failed to load plane %d data. %s", planeIndex, e.getMessage());
return false;
try (final FileOutputStream fos = new FileOutputStream(options.getOutputFilePath(), false);
final OutputStreamWriter reportWriter = new OutputStreamWriter(fos)) {
reportWriter.write("Plane;Entropy\n");
for (int planeIndex = 0; planeIndex < options.getInputDataInfo().getDimensions().getZ(); planeIndex++) {
final int[] planeData = loader.loadPlaneData(planeIndex);
final double planeEntropy = Utils.calculateEntropy(planeData);
reportWriter.write(String.format("%d;%.4f\n", planeIndex, planeEntropy));
}
final double planeEntropy = Utils.calculateEntropy(planeData);
System.out.printf("P: %d\tE: %.4f\n", planeIndex, planeEntropy);
} catch (final IOException e) {
e.printStackTrace();
return false;
}
return true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment