public void testExtraction() throws IOException { CEDD sch = new CEDD(); BufferedImage image = ImageIO.read(new FileInputStream(testFilesPath + testFiles[0])); System.out.println("image = " + image.getWidth() + " x " + image.getHeight()); sch.extract(image); System.out.println("sch = " + sch.getStringRepresentation()); }
public void extract(BufferedImage bimg) { CEDD c = new CEDD(); c.extract(bimg); FCTH f = new FCTH(); f.extract(bimg); init(c, f); }
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(); }
/** * Storing zeros run length coded: one zero is "8", two zeros are "9", ... etc. * * @throws IOException */ public void testRLE() throws IOException { ArrayList<File> files = FileUtils.getAllImageFiles(new File("testdata/ferrari"), true); int sum = 0, saved = 0; for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) { File next = iterator.next(); BufferedImage image = ImageIO.read(next); CEDD f1 = new CEDD(); f1.extract(image); double[] hist = f1.getDoubleHistogram(); int[] rep = new int[hist.length]; int actualLength = 0; for (int i = 0; i < hist.length; i++) { // hist[i]; if (hist[i] == 0) { int count = 0; while (i + count < hist.length && hist[i + count] == 0 && count < 8) count++; if (count == 0) rep[actualLength] = 0; else { rep[actualLength] = 7 + count; i += count - 1; } } else { rep[actualLength] = (int) hist[i]; } actualLength++; } for (int i = 0; i < actualLength; i++) { System.out.print(rep[i] + " "); } System.out.println(); // decoding ... double[] hist2 = new double[144]; int pos = 0; for (int i = 0; i < actualLength; i++) { if (rep[i] < 8) { hist2[pos] = rep[i]; pos++; } else { for (int j = 7; j < rep[i]; j++) { hist2[pos] = 0; pos++; } } } sum += 144; saved += actualLength; assertTrue(Arrays.equals(hist2, f1.getDoubleHistogram())); } System.out.println("sum of dimensions = " + sum); System.out.println("actual dimensions = " + saved); }
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 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"); }