public void testSingleFile() throws IOException { CEDD c = new CEDD(); BufferedImage img = ImageIO.read(new File("C:\\Java\\Projects\\LireSVN\\testdata\\wang-1000\\652.jpg")); c.extract(img); String s = Arrays.toString(c.getDoubleHistogram()); System.out.println("s = " + s); byte[] b = c.getByteArrayRepresentation(); CEDD d = new CEDD(); d.setByteArrayRepresentation(b); System.out.println(d.getDistance(c)); }
public void tttestGetDistribution() throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter("data.csv")); IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexPath))); // get the first document: // if (!IndexReader.indexExists(reader.directory())) // throw new FileNotFoundException("No index found at this specific location."); CEDD cedd1 = new CEDD(); FCTH fcth1 = new FCTH(); CEDD cedd2 = new CEDD(); FCTH fcth2 = new FCTH(); JCD jcd1 = new JCD(); JCD jcd2 = new JCD(); String[] cls; // Needed for check whether the document is deleted. Bits liveDocs = MultiFields.getLiveDocs(reader); int docs = reader.numDocs(); for (int i = 0; i < docs; i++) { if (reader.hasDeletions() && !liveDocs.get(i)) continue; // if it is deleted, just ignore it. Document doc = reader.document(i); cls = doc.getValues(DocumentBuilder.FIELD_NAME_CEDD); if (cls != null && cls.length > 0) cedd1.setStringRepresentation(cls[0]); cls = doc.getValues(DocumentBuilder.FIELD_NAME_FCTH); if (cls != null && cls.length > 0) fcth1.setStringRepresentation(cls[0]); for (int j = i + 1; j < docs; j++) { if (reader.hasDeletions() && !liveDocs.get(i)) continue; // if it is deleted, just ignore it. Document doc2 = reader.document(j); cls = doc2.getValues(DocumentBuilder.FIELD_NAME_CEDD); if (cls != null && cls.length > 0) cedd2.setStringRepresentation(cls[0]); cls = doc2.getValues(DocumentBuilder.FIELD_NAME_FCTH); if (cls != null && cls.length > 0) fcth2.setStringRepresentation(cls[0]); jcd1.init(cedd1, fcth1); jcd2.init(cedd2, fcth2); bw.write( cedd1.getDistance(cedd2) + ";" + fcth1.getDistance(fcth2) + ";" + jcd1.getDistance(jcd2) + "\n"); } if (i % 100 == 0) System.out.println(i + " entries processed ... "); } bw.close(); }
public void testSerialization() throws IOException { int bytes = 0; int sum = 0; ArrayList<File> files = FileUtils.getAllImageFiles(new File("testdata/ferrari"), true); for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) { File next = iterator.next(); BufferedImage image = ImageIO.read(next); CEDD f1 = new CEDD(); CEDD f2 = new CEDD(); f1.extract(image); // System.out.println(Arrays.toString(f1.getDoubleHistogram())); bytes += f1.getByteArrayRepresentation().length; sum += 144 / 2; f2.setByteArrayRepresentation(f1.getByteArrayRepresentation()); // System.out.println(Arrays.toString(f2.getDoubleHistogram())); double[] h = f2.getDoubleHistogram(); int pos = -1; for (int i = 0; i < h.length; i++) { double v = h[i]; if (pos == -1) { if (v == 0) pos = i; } else if (pos > -1) { if (v != 0) pos = -1; } } System.out.println("save = " + (144 - pos)); // bytes += (168 - pos); assertTrue(f2.getDistance(f1) == 0); boolean isSame = true; // for (int i = 0; i < f2.getFieldName().length; i++) { // if (f1.data[i] != f2.data[i]) isSame = false; // } assertTrue(isSame); } double save = 1d - (double) bytes / (double) sum; System.out.println(save * 100 + "% saved"); }