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

Disable KDTree for now.

parent 2d25c746
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(planeVectors,
getCodebookSize(),
options.getWorkerCount(),
options.getQuantizationVector());
options.getQuantizationVector(),
true);
final LBGResult vqResult = vqInitializer.findOptimalCodebook();
return new VectorQuantizer(vqResult.getCodebook());
}
......@@ -235,8 +236,8 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
* @return Indices of codebook vectors.
*/
private int[] quantizeVectorsImpl(final VectorQuantizer quantizer, final int[][] srcVectors, final int workerCount) {
if (useKdTree)
return quantizer.quantizeIntoIndicesUsingKDTree(srcVectors, workerCount);
// if (useKdTree)
// return quantizer.quantizeIntoIndicesUsingKDTree(srcVectors, workerCount);
return quantizer.quantizeIntoIndices(srcVectors, workerCount);
}
......@@ -339,9 +340,17 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final LBGVectorQuantizer vqInitializer = new LBGVectorQuantizer(trainingData,
getCodebookSize(),
options.getWorkerCount(),
options.getQuantizationVector());
options.getQuantizationVector(),
false);
reportStatusToListeners("Starting LBG optimization.");
try {
System.out.println("Sleeping for 10 seconds...");
Thread.sleep(10000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
vqInitializer.setStatusListener(this::reportStatusToListeners);
final LBGResult lbgResult = vqInitializer.findOptimalCodebook();
reportStatusToListeners("Learned the optimal codebook.");
......@@ -376,7 +385,9 @@ public class VQImageCompressor extends CompressorDecompressorBase implements IIm
final LBGVectorQuantizer codebookTrainer = new LBGVectorQuantizer(trainingData,
256,
options.getWorkerCount(),
options.getQuantizationVector());
options.getQuantizationVector(),
false);
codebookTrainer.findOptimalCodebook(vqCodebook -> {
try {
assert ((vqCodebook.getCodebookSize() == vqCodebook.getVectors().length) &&
......
package cz.it4i.qcmp.quantization.vector;
import cz.it4i.qcmp.kdtree.KDTree;
import cz.it4i.qcmp.kdtree.KDTreeBuilder;
import cz.it4i.qcmp.utilities.Utils;
public class VectorQuantizer {
......@@ -15,14 +13,14 @@ public class VectorQuantizer {
private final int vectorSize;
private final long[] frequencies;
private final KDTree kdTree;
// private final KDTree kdTree;
public VectorQuantizer(final VQCodebook codebook) {
this.codebookVectors = codebook.getVectors();
this.vectorSize = codebook.getVectors()[0].length;
this.frequencies = codebook.getVectorFrequencies();
kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getVectors());
// kdTree = new KDTreeBuilder(this.vectorSize, 8).buildTree(codebook.getVectors());
}
public int[] quantize(final int[] dataVector) {
......@@ -99,11 +97,11 @@ public class VectorQuantizer {
return indices;
}
public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) {
return quantizeIntoIndicesImpl(dataVectors, maxWorkerCount, (final int[] queryVector) ->
kdTree.findNearestBBF(queryVector, 8));
}
// public int[] quantizeIntoIndicesUsingKDTree(final int[][] dataVectors, final int maxWorkerCount) {
//
// return quantizeIntoIndicesImpl(dataVectors, maxWorkerCount, (final int[] queryVector) ->
// kdTree.findNearestBBF(queryVector, 8));
// }
public int[] quantizeIntoIndices(final int[][] dataVectors, final int maxWorkerCount) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment