@Test public void testEqual() throws IOException { BufferedImage png = ImageIO.read(getClass().getResource("/sample/IMG_1548.png")); String[] resources = new String[]{ "/sample/IMG_1548.jpg", "/sample/IMG_1548_crayon.jpe", "/sample/IMG_1548_scaled.jpe", "/sample/IMG_1548_cropped.jpe", }; ImageHashAlgorithm algorithm = new DCTImageHashAlgorithm(); OpenBitSet pnghash = algorithm.getHash(png); double max = 0; for (String resource : resources) { BufferedImage jpg = ImageIO.read(getClass().getResource(resource)); OpenBitSet jpghash = algorithm.getHash(jpg); jpghash.xor(pnghash); double distance = jpghash.cardinality(); System.out.printf("Distance for %s = %f\n", resource, distance); if (distance > max) max = distance; assertThat(distance, lessThanOrEqualTo(DEFAULT_THRESHOLD)); } System.out.println("Maxiumum distance:" + Double.valueOf(max)); }
@Override public OpenBitSet getHash(BufferedImage image) { final BufferedImage smallSize; if (image.getWidth() == INTERNAL_SIZE && image.getHeight() == INTERNAL_SIZE && image.getType() == INTERNAL_IMAGE_TYPE) { smallSize = image; } else { smallSize = createResizedCopy(image); } DenseMatrix64F imageMatrix = getImageMatrix(smallSize); return doHash(imageMatrix); }
DCTImageHashAlgorithm implements ImageHashAlgorithm { @Override public OpenBitSet getHash(BufferedImage image) { final BufferedImage smallSize; if (image.getWidth() == INTERNAL_SIZE && image.getHeight() == INTERNAL_SIZE && image.getType() == INTERNAL_IMAGE_TYPE) { smallSize = image; } else { smallSize = createResizedCopy(image); } DenseMatrix64F imageMatrix = getImageMatrix(smallSize); return doHash(imageMatrix); } }
DCTImageHashAlgorithm implements ImageHashAlgorithm { @Override public OpenBitSet getHash(BufferedImage image) { final BufferedImage smallSize; if (image.getWidth() == INTERNAL_SIZE && image.getHeight() == INTERNAL_SIZE && image.getType() == INTERNAL_IMAGE_TYPE) { smallSize = image; } else { smallSize = createResizedCopy(image); } DenseMatrix64F imageMatrix = getImageMatrix(smallSize); return doHash(imageMatrix); }  }
DCTImageHashAlgorithm implements ImageHashAlgorithm { @Override public OpenBitSet getHash(BufferedImage image) { final BufferedImage smallSize; if (image.getWidth() == INTERNAL_SIZE && image.getHeight() == INTERNAL_SIZE && image.getType() == INTERNAL_IMAGE_TYPE) { smallSize = image; } else { smallSize = createResizedCopy(image); } DenseMatrix64F imageMatrix = getImageMatrix(smallSize); return doHash(imageMatrix); }  @Override BufferedImage createResizedCopy(BufferedImage originalImage); @Override OpenBitSet getHash(BufferedImage image); @Override OpenBitSet getHash(double[][] imageMatrix); }
DCTImageHashAlgorithm implements ImageHashAlgorithm { @Override public OpenBitSet getHash(BufferedImage image) { final BufferedImage smallSize; if (image.getWidth() == INTERNAL_SIZE && image.getHeight() == INTERNAL_SIZE && image.getType() == INTERNAL_IMAGE_TYPE) { smallSize = image; } else { smallSize = createResizedCopy(image); } DenseMatrix64F imageMatrix = getImageMatrix(smallSize); return doHash(imageMatrix); }  @Override BufferedImage createResizedCopy(BufferedImage originalImage); @Override OpenBitSet getHash(BufferedImage image); @Override OpenBitSet getHash(double[][] imageMatrix); static final int INTERNAL_SIZE; static final int INTERNAL_IMAGE_TYPE; }