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

Use special exception types for compression and decompression.

parent 7780766e
No related branches found
No related tags found
No related merge requests found
Showing
with 212 additions and 86 deletions
...@@ -4,12 +4,10 @@ import java.io.DataOutputStream; ...@@ -4,12 +4,10 @@ import java.io.DataOutputStream;
public interface IImageCompressor { public interface IImageCompressor {
// TODO(Moravec): Replace default Exception with better Exception type.
/** /**
* Compress the image planes. * Compress the image planes.
* @param compressStream Compressed data stream. * @param compressStream Compressed data stream.
* @throws Exception when compression fails. * @throws ImageCompressionException when compression fails.
*/ */
void compress(DataOutputStream compressStream) throws Exception; void compress(DataOutputStream compressStream) throws ImageCompressionException;
} }
...@@ -20,10 +20,10 @@ public interface IImageDecompressor { ...@@ -20,10 +20,10 @@ public interface IImageDecompressor {
* @param compressedStream Input stream of compressed data. * @param compressedStream Input stream of compressed data.
* @param decompressStream Output stream for decompressed data. * @param decompressStream Output stream for decompressed data.
* @param header QCMPFile information. * @param header QCMPFile information.
* @throws Exception when decompression fails. * @throws ImageDecompressionException when decompression fails.
*/ */
void decompress(DataInputStream compressedStream, void decompress(DataInputStream compressedStream,
DataOutputStream decompressStream, DataOutputStream decompressStream,
final QCMPFileHeader header) throws Exception; final QCMPFileHeader header) throws ImageDecompressionException;
} }
package azgracompress.compression;
public class ImageCompressionException extends Exception {
private final Exception innerException;
public ImageCompressionException(final String message, final Exception innerException) {
super(message);
this.innerException = innerException;
}
public ImageCompressionException(final String message) {
super(message);
this.innerException = null;
}
@Override
public String getMessage() {
String msg = super.getMessage();
if (msg != null && innerException != null) {
msg += "\nInner exception:\n" + innerException.getMessage();
}
return msg;
}
}
...@@ -62,10 +62,12 @@ public class ImageCompressor extends CompressorDecompressorBase { ...@@ -62,10 +62,12 @@ public class ImageCompressor extends CompressorDecompressorBase {
reportCompressionRatio(header, compressStream.size()); reportCompressionRatio(header, compressStream.size());
} }
} catch (Exception ex) { } catch (ImageCompressionException ex) {
System.err.println(ex.getMessage()); System.err.println(ex.getMessage());
return false; return false;
} catch (Exception e) {
e.printStackTrace();
return false;
} }
return true; return true;
} }
......
package azgracompress.compression;
public class ImageDecompressionException extends Exception {
private final Exception innerException;
public ImageDecompressionException(final String message, final Exception innerException) {
super(message);
this.innerException = innerException;
}
public ImageDecompressionException(final String message) {
super(message);
this.innerException = null;
}
@Override
public String getMessage() {
String msg = super.getMessage();
if (msg != null && innerException != null) {
msg += "\nInner exception:\n" + innerException.getMessage();
}
return msg;
}
}
...@@ -62,8 +62,7 @@ public class ImageDecompressor extends CompressorDecompressorBase { ...@@ -62,8 +62,7 @@ public class ImageDecompressor extends CompressorDecompressorBase {
try (FileInputStream fileInputStream = new FileInputStream(options.getInputFile()); try (FileInputStream fileInputStream = new FileInputStream(options.getInputFile());
DataInputStream dataInputStream = new DataInputStream(fileInputStream)) { DataInputStream dataInputStream = new DataInputStream(fileInputStream)) {
header = readQCMPFileHeader(dataInputStream); header = readQCMPFileHeader(dataInputStream);
} } catch (IOException ioEx) {
catch (IOException ioEx){
ioEx.printStackTrace(); ioEx.printStackTrace();
return ""; return "";
} }
...@@ -154,9 +153,11 @@ public class ImageDecompressor extends CompressorDecompressorBase { ...@@ -154,9 +153,11 @@ public class ImageDecompressor extends CompressorDecompressorBase {
try (FileOutputStream fos = new FileOutputStream(options.getOutputFile(), false); try (FileOutputStream fos = new FileOutputStream(options.getOutputFile(), false);
DataOutputStream decompressStream = new DataOutputStream(fos)) { DataOutputStream decompressStream = new DataOutputStream(fos)) {
imageDecompressor.decompress(dataInputStream, decompressStream, header); imageDecompressor.decompress(dataInputStream, decompressStream, header);
} catch (Exception ex) {
ex.printStackTrace(); } catch (ImageDecompressionException ex) {
System.err.println(ex.getMessage());
return false; return false;
} }
......
...@@ -35,13 +35,17 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -35,13 +35,17 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
* *
* @param quantizer Quantizer used for compression of the image. * @param quantizer Quantizer used for compression of the image.
* @param compressStream Compressed data stream. * @param compressStream Compressed data stream.
* @throws IOException when writing to the stream fails. * @throws ImageCompressionException when writing to the stream fails.
*/ */
private void writeCodebookToOutputStream(final ScalarQuantizer quantizer, private void writeCodebookToOutputStream(final ScalarQuantizer quantizer,
DataOutputStream compressStream) throws IOException { DataOutputStream compressStream) throws ImageCompressionException {
final int[] centroids = quantizer.getCentroids(); final int[] centroids = quantizer.getCentroids();
for (final int quantizationValue : centroids) { try {
compressStream.writeShort(quantizationValue); for (final int quantizationValue : centroids) {
compressStream.writeShort(quantizationValue);
}
} catch (IOException ioEx) {
throw new ImageCompressionException("Unable to write codebook to compress stream.", ioEx);
} }
if (options.isVerbose()) { if (options.isVerbose()) {
Log("Wrote quantization values to compressed stream."); Log("Wrote quantization values to compressed stream.");
...@@ -52,21 +56,29 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -52,21 +56,29 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
* Compress the image file specified by parsed CLI options using scalar quantization. * Compress the image file specified by parsed CLI options using scalar quantization.
* *
* @param compressStream Stream to which compressed data will be written. * @param compressStream Stream to which compressed data will be written.
* @throws Exception When compress process fails. * @throws ImageCompressionException When compress process fails.
*/ */
public void compress(DataOutputStream compressStream) throws Exception { public void compress(DataOutputStream compressStream) throws ImageCompressionException {
ScalarQuantizer quantizer = null; ScalarQuantizer quantizer = null;
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
if (options.hasReferencePlaneIndex()) { if (options.hasReferencePlaneIndex()) {
stopwatch.restart(); stopwatch.restart();
final ImageU16 referencePlane = RawDataIO.loadImageU16(options.getInputFile(), ImageU16 referencePlane = null;
options.getImageDimension(), try {
options.getReferencePlaneIndex()); referencePlane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
options.getReferencePlaneIndex());
} catch (Exception ex) {
throw new ImageCompressionException("Unable to load reference plane data.", ex);
}
Log(String.format("Training scalar quantizer from reference plane %d.", options.getReferencePlaneIndex())); Log(String.format("Training scalar quantizer from reference plane %d.", options.getReferencePlaneIndex()));
quantizer = trainScalarQuantizerFromData(referencePlane.getData()); quantizer = trainScalarQuantizerFromData(referencePlane.getData());
stopwatch.stop(); stopwatch.stop();
writeCodebookToOutputStream(quantizer, compressStream); writeCodebookToOutputStream(quantizer, compressStream);
Log("Reference codebook created in: " + stopwatch.getElapsedTimeString()); Log("Reference codebook created in: " + stopwatch.getElapsedTimeString());
} }
...@@ -74,9 +86,16 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -74,9 +86,16 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
for (final int planeIndex : planeIndices) { for (final int planeIndex : planeIndices) {
stopwatch.restart(); stopwatch.restart();
Log(String.format("Loading plane %d.", planeIndex)); Log(String.format("Loading plane %d.", planeIndex));
final ImageU16 plane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(), ImageU16 plane = null;
planeIndex);
try {
plane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
planeIndex);
} catch (Exception ex) {
throw new ImageCompressionException("Unable to load plane data.", ex);
}
if (!options.hasReferencePlaneIndex()) { if (!options.hasReferencePlaneIndex()) {
Log(String.format("Training scalar quantizer from plane %d.", planeIndex)); Log(String.format("Training scalar quantizer from plane %d.", planeIndex));
...@@ -91,8 +110,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -91,8 +110,8 @@ public class SQImageCompressor extends CompressorDecompressorBase implements IIm
try (OutBitStream outBitStream = new OutBitStream(compressStream, options.getBitsPerPixel(), 2048)) { try (OutBitStream outBitStream = new OutBitStream(compressStream, options.getBitsPerPixel(), 2048)) {
outBitStream.write(indices); outBitStream.write(indices);
} catch (IOException ioEx) { } catch (Exception ex) {
ioEx.printStackTrace(); throw new ImageCompressionException("Unable to write indices to OutBitStream.", ex);
} }
stopwatch.stop(); stopwatch.stop();
Log("Plane time: " + stopwatch.getElapsedTimeString()); Log("Plane time: " + stopwatch.getElapsedTimeString());
......
...@@ -15,10 +15,15 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I ...@@ -15,10 +15,15 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
super(options); super(options);
} }
private int[] readScalarQuantizationValues(DataInputStream compressedStream, final int n) throws IOException { private int[] readScalarQuantizationValues(DataInputStream compressedStream,
final int n) throws ImageDecompressionException {
int[] quantizationValues = new int[n]; int[] quantizationValues = new int[n];
for (int i = 0; i < n; i++) { try {
quantizationValues[i] = compressedStream.readUnsignedShort(); for (int i = 0; i < n; i++) {
quantizationValues[i] = compressedStream.readUnsignedShort();
}
} catch (IOException ioEx) {
throw new ImageDecompressionException("Unable to read quantization values from compressed stream.", ioEx);
} }
return quantizationValues; return quantizationValues;
} }
...@@ -44,7 +49,7 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I ...@@ -44,7 +49,7 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
@Override @Override
public void decompress(DataInputStream compressedStream, public void decompress(DataInputStream compressedStream,
DataOutputStream decompressStream, DataOutputStream decompressStream,
QCMPFileHeader header) throws Exception { QCMPFileHeader header) throws ImageDecompressionException {
final int codebookSize = (int) Math.pow(2, header.getBitsPerPixel()); final int codebookSize = (int) Math.pow(2, header.getBitsPerPixel());
final int planeCountForDecompression = header.getImageSizeZ(); final int planeCountForDecompression = header.getImageSizeZ();
...@@ -68,18 +73,31 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I ...@@ -68,18 +73,31 @@ public class SQImageDecompressor extends CompressorDecompressorBase implements I
assert (quantizationValues != null); assert (quantizationValues != null);
Log(String.format("Decompressing plane %d...", planeIndex)); Log(String.format("Decompressing plane %d...", planeIndex));
InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerPixel(), planeIndicesDataSize); byte[] decompressedPlaneData = null;
inBitStream.readToBuffer(); try (InBitStream inBitStream = new InBitStream(compressedStream,
inBitStream.setAllowReadFromUnderlyingStream(false); header.getBitsPerPixel(),
final int[] indices = inBitStream.readNValues(planePixelCount); planeIndicesDataSize)) {
inBitStream.readToBuffer();
int[] decompressedValues = new int[planePixelCount]; inBitStream.setAllowReadFromUnderlyingStream(false);
for (int i = 0; i < planePixelCount; i++) { final int[] indices = inBitStream.readNValues(planePixelCount);
decompressedValues[i] = quantizationValues[indices[i]];
int[] decompressedValues = new int[planePixelCount];
for (int i = 0; i < planePixelCount; i++) {
decompressedValues[i] = quantizationValues[indices[i]];
}
decompressedPlaneData =
TypeConverter.unsignedShortArrayToByteArray(decompressedValues, false);
} catch (Exception ex) {
throw new ImageDecompressionException("Unable to read indices from InBitStream.", ex);
}
try {
decompressStream.write(decompressedPlaneData);
} catch (IOException e) {
throw new ImageDecompressionException("Unable to write decompressed data to decompress stream.", e);
} }
final byte[] decompressedPlaneData = TypeConverter.unsignedShortArrayToByteArray(decompressedValues, false);
decompressStream.write(decompressedPlaneData);
stopwatch.stop(); stopwatch.stop();
Log(String.format("Decompressed plane %d in %s.", planeIndex, stopwatch.getElapsedTimeString())); Log(String.format("Decompressed plane %d in %s.", planeIndex, stopwatch.getElapsedTimeString()));
} }
......
...@@ -56,16 +56,20 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -56,16 +56,20 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* *
* @param quantizer Quantizer with the codebook. * @param quantizer Quantizer with the codebook.
* @param compressStream Stream with compressed data. * @param compressStream Stream with compressed data.
* @throws IOException When unable to write quantizer. * @throws ImageCompressionException When unable to write quantizer.
*/ */
private void writeQuantizerToCompressStream(final VectorQuantizer quantizer, private void writeQuantizerToCompressStream(final VectorQuantizer quantizer,
DataOutputStream compressStream) throws IOException { DataOutputStream compressStream) throws ImageCompressionException {
final CodebookEntry[] codebook = quantizer.getCodebook(); final CodebookEntry[] codebook = quantizer.getCodebook();
for (final CodebookEntry entry : codebook) { try {
final int[] entryVector = entry.getVector(); for (final CodebookEntry entry : codebook) {
for (final int vecVal : entryVector) { final int[] entryVector = entry.getVector();
compressStream.writeShort(vecVal); for (final int vecVal : entryVector) {
compressStream.writeShort(vecVal);
}
} }
} catch (IOException ioEx) {
throw new ImageCompressionException("Unable to write codebook to compress stream.", ioEx);
} }
if (options.isVerbose()) { if (options.isVerbose()) {
Log("Wrote quantization vectors to compressed stream."); Log("Wrote quantization vectors to compressed stream.");
...@@ -76,16 +80,22 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -76,16 +80,22 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* Compress the image file specified by parsed CLI options using vector quantization. * Compress the image file specified by parsed CLI options using vector quantization.
* *
* @param compressStream Stream to which compressed data will be written. * @param compressStream Stream to which compressed data will be written.
* @throws Exception When compress process fails. * @throws ImageCompressionException When compress process fails.
*/ */
public void compress(DataOutputStream compressStream) throws Exception { public void compress(DataOutputStream compressStream) throws ImageCompressionException {
VectorQuantizer quantizer = null; VectorQuantizer quantizer = null;
Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch = new Stopwatch();
if (options.hasReferencePlaneIndex()) { if (options.hasReferencePlaneIndex()) {
stopwatch.restart(); stopwatch.restart();
final ImageU16 referencePlane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(), ImageU16 referencePlane = null;
options.getReferencePlaneIndex()); try {
referencePlane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
options.getReferencePlaneIndex());
} catch (Exception ex) {
throw new ImageCompressionException("Unable to load reference plane data.", ex);
}
Log(String.format("Training vector quantizer from reference plane %d.", options.getReferencePlaneIndex())); Log(String.format("Training vector quantizer from reference plane %d.", options.getReferencePlaneIndex()));
final int[][] refPlaneVectors = getPlaneVectors(referencePlane); final int[][] refPlaneVectors = getPlaneVectors(referencePlane);
...@@ -101,9 +111,15 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -101,9 +111,15 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
for (final int planeIndex : planeIndices) { for (final int planeIndex : planeIndices) {
stopwatch.restart(); stopwatch.restart();
Log(String.format("Loading plane %d.", planeIndex)); Log(String.format("Loading plane %d.", planeIndex));
final ImageU16 plane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(), ImageU16 plane = null;
planeIndex); try {
plane = RawDataIO.loadImageU16(options.getInputFile(),
options.getImageDimension(),
planeIndex);
} catch (Exception ex) {
throw new ImageCompressionException("Unable to load plane data.", ex);
}
final int[][] planeVectors = getPlaneVectors(plane); final int[][] planeVectors = getPlaneVectors(plane);
...@@ -121,8 +137,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm ...@@ -121,8 +137,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
try (OutBitStream outBitStream = new OutBitStream(compressStream, options.getBitsPerPixel(), 2048)) { try (OutBitStream outBitStream = new OutBitStream(compressStream, options.getBitsPerPixel(), 2048)) {
outBitStream.write(indices); outBitStream.write(indices);
} catch (IOException ioEx) { } catch (Exception ex) {
ioEx.printStackTrace(); throw new ImageCompressionException("Unable to write indices to OutBitStream.", ex);
} }
stopwatch.stop(); stopwatch.stop();
Log("Plane time: " + stopwatch.getElapsedTimeString()); Log("Plane time: " + stopwatch.getElapsedTimeString());
......
...@@ -30,13 +30,17 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I ...@@ -30,13 +30,17 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
private int[][] readCodebookVectors(DataInputStream compressedStream, private int[][] readCodebookVectors(DataInputStream compressedStream,
final int codebookSize, final int codebookSize,
final int vectorSize) throws IOException { final int vectorSize) throws ImageDecompressionException {
int[][] codebook = new int[codebookSize][vectorSize]; int[][] codebook = new int[codebookSize][vectorSize];
for (int codebookIndex = 0; codebookIndex < codebookSize; codebookIndex++) { try {
for (int vecIndex = 0; vecIndex < vectorSize; vecIndex++) { for (int codebookIndex = 0; codebookIndex < codebookSize; codebookIndex++) {
codebook[codebookIndex][vecIndex] = compressedStream.readUnsignedShort(); for (int vecIndex = 0; vecIndex < vectorSize; vecIndex++) {
codebook[codebookIndex][vecIndex] = compressedStream.readUnsignedShort();
}
} }
} catch (IOException ioEx) {
throw new ImageDecompressionException("Unable to read quantization values from compressed stream.", ioEx);
} }
return codebook; return codebook;
} }
...@@ -87,7 +91,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I ...@@ -87,7 +91,7 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
@Override @Override
public void decompress(DataInputStream compressedStream, public void decompress(DataInputStream compressedStream,
DataOutputStream decompressStream, DataOutputStream decompressStream,
QCMPFileHeader header) throws Exception { QCMPFileHeader header) throws ImageDecompressionException {
final int codebookSize = (int) Math.pow(2, header.getBitsPerPixel()); final int codebookSize = (int) Math.pow(2, header.getBitsPerPixel());
assert (header.getVectorSizeZ() == 1); assert (header.getVectorSizeZ() == 1);
final int vectorSize = header.getVectorSizeX() * header.getVectorSizeY() * header.getVectorSizeZ(); final int vectorSize = header.getVectorSizeX() * header.getVectorSizeY() * header.getVectorSizeZ();
...@@ -114,28 +118,43 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I ...@@ -114,28 +118,43 @@ public class VQImageDecompressor extends CompressorDecompressorBase implements I
assert (quantizationVectors != null); assert (quantizationVectors != null);
Log(String.format("Decompressing plane %d...", planeIndex)); Log(String.format("Decompressing plane %d...", planeIndex));
InBitStream inBitStream = new InBitStream(compressedStream, header.getBitsPerPixel(), (int) planeDataSize);
inBitStream.readToBuffer(); byte[] decompressedPlaneData = null;
inBitStream.setAllowReadFromUnderlyingStream(false);
final int[] indices = inBitStream.readNValues((int) planeVectorCount); try (InBitStream inBitStream = new InBitStream(compressedStream,
header.getBitsPerPixel(),
int[][] decompressedVectors = new int[(int) planeVectorCount][vectorSize]; (int) planeDataSize)) {
for (int vecIndex = 0; vecIndex < planeVectorCount; vecIndex++) { inBitStream.readToBuffer();
System.arraycopy(quantizationVectors[indices[vecIndex]], inBitStream.setAllowReadFromUnderlyingStream(false);
0, final int[] indices = inBitStream.readNValues((int) planeVectorCount);
decompressedVectors[vecIndex],
0, int[][] decompressedVectors = new int[(int) planeVectorCount][vectorSize];
vectorSize); for (int vecIndex = 0; vecIndex < planeVectorCount; vecIndex++) {
System.arraycopy(quantizationVectors[indices[vecIndex]],
0,
decompressedVectors[vecIndex],
0,
vectorSize);
}
final ImageU16 decompressedPlane = reconstructImageFromQuantizedVectors(decompressedVectors,
qVector,
header.getImageDims());
decompressedPlaneData =
TypeConverter.unsignedShortArrayToByteArray(decompressedPlane.getData(), false);
} catch (Exception ex) {
throw new ImageDecompressionException("Unable to read indices from InBitStream.", ex);
} }
final ImageU16 decompressedPlane = reconstructImageFromQuantizedVectors(decompressedVectors, try {
qVector, decompressStream.write(decompressedPlaneData);
header.getImageDims()); } catch (IOException e) {
final byte[] decompressedPlaneData = TypeConverter.unsignedShortArrayToByteArray( throw new ImageDecompressionException("Unable to write decompressed data to decompress stream.", e);
decompressedPlane.getData(), }
false);
decompressStream.write(decompressedPlaneData);
stopwatch.stop(); stopwatch.stop();
Log(String.format("Decompressed plane %d in %s.", planeIndex, stopwatch.getElapsedTimeString())); Log(String.format("Decompressed plane %d in %s.", planeIndex, stopwatch.getElapsedTimeString()));
} }
......
...@@ -3,7 +3,7 @@ package azgracompress.io; ...@@ -3,7 +3,7 @@ package azgracompress.io;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class InBitStream { public class InBitStream implements AutoCloseable {
private InputStream inputStream; private InputStream inputStream;
private byte[] buffer; private byte[] buffer;
...@@ -90,4 +90,9 @@ public class InBitStream { ...@@ -90,4 +90,9 @@ public class InBitStream {
} }
@Override
public void close() throws Exception {
bitBufferSize = 0;
bytesAvailable = 0;
}
} }
package azgracompress.quantization.vector; package azgracompress.quantization.vector;
import azgracompress.quantization.QTrainIteration;
public class LBGResult { public class LBGResult {
private final CodebookEntry[] codebook; private final CodebookEntry[] codebook;
private final double averageMse; private final double averageMse;
private final double psnr; private final double psnr;
......
...@@ -28,7 +28,6 @@ public class LBGVectorQuantizer { ...@@ -28,7 +28,6 @@ public class LBGVectorQuantizer {
return findOptimalCodebook(true); return findOptimalCodebook(true);
} }
// TODO(Moravec): Maybe return QTrainIteration somehow?
public LBGResult findOptimalCodebook(boolean verbose) { public LBGResult findOptimalCodebook(boolean verbose) {
ArrayList<LearningCodebookEntry> codebook = initializeCodebook(verbose); ArrayList<LearningCodebookEntry> codebook = initializeCodebook(verbose);
if (verbose) { if (verbose) {
...@@ -118,8 +117,6 @@ public class LBGVectorQuantizer { ...@@ -118,8 +117,6 @@ public class LBGVectorQuantizer {
// Create perturbation vector. // Create perturbation vector.
// TODO(Moravec): Make sure that when we are splitting entry we don't end up creating two same entries.
// The problem happens when we try to split Vector full of zeroes.
// Split each entry in codebook with fixed perturbation vector. // Split each entry in codebook with fixed perturbation vector.
for (final LearningCodebookEntry entryToSplit : codebook) { for (final LearningCodebookEntry entryToSplit : codebook) {
double[] prtV; double[] prtV;
...@@ -142,8 +139,8 @@ public class LBGVectorQuantizer { ...@@ -142,8 +139,8 @@ public class LBGVectorQuantizer {
newCodebook.add(entryToSplit); newCodebook.add(entryToSplit);
ArrayList<Integer> rndEntryValues = new ArrayList<>(prtV.length); ArrayList<Integer> rndEntryValues = new ArrayList<>(prtV.length);
for (int j = 0; j < prtV.length; j++) { for (final double v : prtV) {
final int value = (int) Math.floor(prtV[j]); final int value = (int) Math.floor(v);
assert (value >= 0) : "value is too low!"; assert (value >= 0) : "value is too low!";
assert (value <= U16.Max) : "value is too big!"; assert (value <= U16.Max) : "value is too big!";
rndEntryValues.add(value); rndEntryValues.add(value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment