• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java CEDD类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中net.semanticmetadata.lire.imageanalysis.CEDD的典型用法代码示例。如果您正苦于以下问题:Java CEDD类的具体用法?Java CEDD怎么用?Java CEDD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

CEDD类属于net.semanticmetadata.lire.imageanalysis包,在下文中一共展示了CEDD类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: singleSearch

点赞 3

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public double singleSearch(int docNum) throws IOException, InstantiationException, IllegalAccessException {
        IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath)));

        // -----------

        String query = reader.document(docNum).getValues("hash")[0];
        CEDD ceddQuery = new CEDD();
        ceddQuery.setByteArrayRepresentation(reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().bytes, reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().offset, reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().length);

        // -----------

        HashSet<String> gold = new HashSet<String>(numImagesEval);
        ImageSearcher cis = ImageSearcherFactory.createCEDDImageSearcher(100);
        ImageSearchHits hits = cis.search(reader.document(docNum), reader);
        for (int i = 0; i < 10; i++) {
            gold.add(hits.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]);
        }

        // ------------

        IndexSearcher searcher = new IndexSearcher(reader);
        searcher.setSimilarity(new SimilarityBase() {
            @Override
            protected float score(BasicStats basicStats, float freq, float v2) {
                return 1;
            }

            @Override
            public String toString() {
                return null;
            }
        });
        TopDocs topDocs = searcher.search(createQuery(query), 500);
        topDocs = rerank(topDocs, ceddQuery, reader);
//        System.out.println("topDocs.scoreDocs.length = " + topDocs.scoreDocs.length);
        double numMatches = 0;
        for (int i = 0; i < topDocs.scoreDocs.length; i++) {
            ScoreDoc scoreDoc = topDocs.scoreDocs[i];
//            System.out.print(scoreDoc.score + ": ");
            String file = reader.document(scoreDoc.doc).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0];
//            System.out.println(file.substring(file.lastIndexOf('/') + 1) + (gold.contains(file)?" x":" o"));
            if (gold.contains(file)) numMatches++;
        }
        return numMatches;
    }
 

开发者ID:fish2000,
项目名称:lire,
代码行数:46,
代码来源:LocalitySensitiveHashingTest.java

示例2: rerank

点赞 3

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
private TopDocs rerank(TopDocs docs, LireFeature feature, IndexReader reader) throws IOException, IllegalAccessException, InstantiationException {
    LireFeature tmp = new CEDD();
    ArrayList<ScoreDoc> res = new ArrayList<ScoreDoc>(docs.scoreDocs.length);
    float maxScore = 0f;
    for (int i = 0; i < docs.scoreDocs.length; i++) {
        tmp.setByteArrayRepresentation(reader.document(docs.scoreDocs[i].doc).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().bytes,
                reader.document(docs.scoreDocs[i].doc).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().offset,
                reader.document(docs.scoreDocs[i].doc).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().length);
        maxScore = Math.max(1 / tmp.getDistance(feature), maxScore);
        res.add(new ScoreDoc(docs.scoreDocs[i].doc, 1 / tmp.getDistance(feature)));
    }
    // sorting res ...
    Collections.sort(res, new Comparator<ScoreDoc>() {
        @Override
        public int compare(ScoreDoc o1, ScoreDoc o2) {
            return (int) Math.signum(o2.score - o1.score);
        }
    });
    return new TopDocs(numImagesEval, (ScoreDoc[]) res.toArray(new ScoreDoc[res.size()]), maxScore);
}
 

开发者ID:fish2000,
项目名称:lire,
代码行数:21,
代码来源:LocalitySensitiveHashingTest.java

示例3: testLsaFilter

点赞 3

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public void testLsaFilter() throws IOException {
        // index images
//        indexFiles();
        // search
        System.out.println("---< searching >-------------------------");
        IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath)));
        Document document = reader.document(0);
        ImageSearcher searcher = ImageSearcherFactory.createCEDDImageSearcher(100);
        ImageSearchHits hits = searcher.search(document, reader);
        // rerank
        System.out.println("---< filtering >-------------------------");
        LsaFilter filter = new LsaFilter(CEDD.class, DocumentBuilder.FIELD_NAME_CEDD);
        hits = filter.filter(hits, document);

        // output
        FileUtils.saveImageResultsToHtml("filtertest", hits, document.getField(DocumentBuilder.FIELD_NAME_IDENTIFIER).stringValue());
    }
 

开发者ID:fish2000,
项目名称:lire,
代码行数:18,
代码来源:FilterTest.java

示例4: extract

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
@Override
public void extract(BufferedImage bimg) {
    // level 0:
    CEDD cedd = new CEDD();
    cedd.extract(bimg);
    System.arraycopy(cedd.getDoubleHistogram(), 0, histogram, 0, 144);
    // level 1:
    int w = bimg.getWidth() / 2;
    int h = bimg.getHeight() / 2;
    cedd.extract(bimg.getSubimage(0, 0, w, h));
    System.arraycopy(cedd.getDoubleHistogram(), 0, histogram, 144 * 1, 144);
    cedd.extract(bimg.getSubimage(w, 0, w, h));
    System.arraycopy(cedd.getDoubleHistogram(), 0, histogram, 144 * 2, 144);
    cedd.extract(bimg.getSubimage(0, h, w, h));
    System.arraycopy(cedd.getDoubleHistogram(), 0, histogram, 144 * 3, 144);
    cedd.extract(bimg.getSubimage(w, h, w, h));
    System.arraycopy(cedd.getDoubleHistogram(), 0, histogram, 144 * 4, 144);
    // level 2:
    int wstep = bimg.getWidth() / 4;
    int hstep = bimg.getHeight() / 4;
    int binPos = 5; // the next free section in the histogram
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            cedd.extract(bimg.getSubimage(i * wstep, j * hstep, wstep, hstep));
            System.arraycopy(cedd.getDoubleHistogram(), 0, histogram, 144 * binPos, 144);
            binPos++;
        }
    }

}
 

开发者ID:fish2000,
项目名称:lire,
代码行数:31,
代码来源:SPCEDD.java

示例5: testIndexing

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public double testIndexing() throws IOException, IllegalAccessException, InstantiationException {
        LocalitySensitiveHashing.generateHashFunctions();
        LocalitySensitiveHashing.readHashFunctions();
        DocumentBuilder builder = new ChainedDocumentBuilder();
        ((ChainedDocumentBuilder) builder).addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder());

//        System.out.println("-< Getting files to index >--------------");
        ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), true);
//        System.out.println("-< Indexing " + images.size() + " files >--------------");

        IndexWriter iw = LuceneUtils.createIndexWriter(indexPath, true, LuceneUtils.AnalyzerType.WhitespaceAnalyzer);
        int count = 0;
        long time = System.currentTimeMillis();
        for (String identifier : images) {
            CEDD cedd = new CEDD();
            cedd.extract(ImageIO.read(new FileInputStream(identifier)));
            Document doc = new Document();
            doc.add(new Field(DocumentBuilder.FIELD_NAME_CEDD, cedd.getByteArrayRepresentation()));
            doc.add(new Field(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier, Field.Store.YES, Field.Index.NOT_ANALYZED));
            int[] hashes = LocalitySensitiveHashing.generateHashes(cedd.getDoubleHistogram());
            StringBuilder hash = new StringBuilder(512);
            for (int i = 0; i < hashes.length; i++) {
                hash.append(hashes[i]);
                hash.append(' ');
            }
//            System.out.println("hash = " + hash);
            doc.add(new Field("hash", hash.toString(), Field.Store.YES, Field.Index.ANALYZED));
            iw.addDocument(doc);
            count++;
//            if (count % 100 == 0) System.out.println(count + " files indexed.");
        }
        long timeTaken = (System.currentTimeMillis() - time);
        float sec = ((float) timeTaken) / 1000f;

//        System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image.");
        iw.close();

        return testSearch();

    }
 

开发者ID:fish2000,
项目名称:lire,
代码行数:41,
代码来源:LocalitySensitiveHashingTest.java

示例6: testOutputSearchResults

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public void testOutputSearchResults() throws IOException, InstantiationException, IllegalAccessException {
    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath)));
    int docNum = 0; // doc to search for.
    // -----------

    String query = reader.document(docNum).getValues("hash")[0];
    CEDD ceddQuery = new CEDD();
    ceddQuery.setByteArrayRepresentation(reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().bytes, reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().offset, reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().length);

    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs topDocs = searcher.search(createQuery(query), numImagesEval);
    FileUtils.saveImageResultsToPng("result_lsh", topDocs, reader.document(docNum).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0], reader);
}
 

开发者ID:fish2000,
项目名称:lire,
代码行数:14,
代码来源:LocalitySensitiveHashingTest.java

示例7: generateImageHistogram

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
/**
 * Generate Image Histogram with help of 3rd party framwork LIRE
 */
private void generateImageHistogram(BufferedImage bufferedImage) {
	CEDD bimgCedd = new CEDD();
	bimgCedd.extract(bufferedImage);
	this.histogram = bimgCedd.getDoubleHistogram();
}
 

开发者ID:hiiamok,
项目名称:DISH,
代码行数:9,
代码来源:ImageFeatures.java

示例8: testGenFile

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public void testGenFile() throws IOException {
        ArrayList<File> images = FileUtils.getAllImageFiles(new File("W:\\Forschung\\Intention_Test_Data\\data\\images"), true);
        // print header
        System.out.println("% generated automatically by LIRe\n" +
                "@relation content_based_features\n" +
                "\n" +
                "@attribute image_filename String");
        System.out.println("@attribute faces numeric");
        System.out.println("@attribute cedd relational");
        for (int i = 0; i < 144; i++) {
            System.out.println("\[email protected] c" + i + " numeric");
        }
        System.out.println("@end cedd");
        System.out.println("@attribute rgb_hist relational");
        for (int i = 0; i < 64; i++) {
            System.out.println("\[email protected] rh" + i + " numeric");
        }
        System.out.println("@end rgb_hist");
        System.out.println("@data");
        // print data
        for (Iterator<File> iterator = images.iterator(); iterator.hasNext(); ) {
            File nextFile = iterator.next();
            try {
                BufferedImage img = ImageIO.read(nextFile);
                // filename
                System.out.print(nextFile.getName() + ",");
                // cedd
                CEDD cedd = new CEDD();
                cedd.extract(img);
                double[] histogram = cedd.getDoubleHistogram();
                for (int i = 0; i < histogram.length; i++) {
                    System.out.print((int) histogram[i]);
                    System.out.print(',');

                }
//                System.out.println();
                // rgb histogram
                SimpleColorHistogram.DEFAULT_NUMBER_OF_BINS = 64;
                SimpleColorHistogram rgb = new SimpleColorHistogram();
                rgb.extract(img);
                histogram = rgb.getDoubleHistogram();
                for (int i = 0; i < histogram.length; i++) {
                    System.out.print((int) histogram[i]);
                    System.out.print(',');
                }
                System.out.println();
            } catch (Exception e) {
                System.out.println("-- ERROR -- " + nextFile.getName() + ", " + e.getMessage());
            }
        }
    }
 

开发者ID:fish2000,
项目名称:lire,
代码行数:52,
代码来源:ArffGeneratorTest.java

示例9: tttestGetDistribution

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
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();
    }
 

开发者ID:fish2000,
项目名称:lire,
代码行数:50,
代码来源:TestWang.java

示例10: testExtraction

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public void testExtraction() {
    Extractor e = new Extractor();
    e.setFileList(new File("imageList.txt"));
    e.setOutFile(new File("out.data"));
    e.addFeature(new CEDD());
    e.run();

    // do it ...
    byte[] tempInt = new byte[4];
    int tmp, tmpFeature;
    byte[] temp = new byte[2064];
    File inputFile = new File("out.data");
    try {
        BufferedInputStream in = new BufferedInputStream(new GZIPInputStream(new FileInputStream("out.data")));
        // read file hashFunctionsFileName length:
        while (in.read(tempInt, 0, 4) > 0) {
            tmp = SerializationUtils.toInt(tempInt);
            // read file hashFunctionsFileName:
            in.read(temp, 0, tmp);
            String filename = new String(temp, 0, tmp);
            // normalize Filename to full path.
            filename = inputFile.getCanonicalPath().substring(0, inputFile.getCanonicalPath().lastIndexOf(inputFile.getName())) + filename;
            System.out.print(filename);
            while ((tmpFeature = in.read()) < 255) {
                System.out.print(", " + tmpFeature);
                LireFeature f = (LireFeature) Class.forName(Extractor.features[tmpFeature]).newInstance();
                // byte[] length ...
                in.read(tempInt, 0, 4);
                tmp = SerializationUtils.toInt(tempInt);
                // read feature byte[]
                in.read(temp, 0, tmp);
                f.setByteArrayRepresentation(temp, 0, tmp);
                // test f ...
                LireFeature f2 = (LireFeature) Class.forName(Extractor.features[tmpFeature]).newInstance();
                f2.extract(ImageIO.read(new File(filename)));
                System.out.println("f2.getDistance(f) = " + f2.getDistance(f));
            }
            System.out.println();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}
 

开发者ID:fish2000,
项目名称:lire,
代码行数:45,
代码来源:ExtractorTest.java

示例11: prepareFeaturesAndBuilders

点赞 2

import net.semanticmetadata.lire.imageanalysis.CEDD; //导入依赖的package包/类
public static void prepareFeaturesAndBuilders(Set<String> features, Map<String, DocumentBuilder> builders, Map<String, LireFeature> lireFeatures) {
	if (features.contains(ACC)) {
		builders.put(ACC, DocumentBuilderFactory.getAutoColorCorrelogramDocumentBuilder());
		lireFeatures.put(ACC, new AutoColorCorrelogram());
	}
	if (features.contains(CEDD)) {
		builders.put(CEDD, DocumentBuilderFactory.getCEDDDocumentBuilder());
		lireFeatures.put(CEDD, new CEDD());
	}
	if (features.contains(CH)) {
		builders.put(CH, DocumentBuilderFactory.getColorHistogramDocumentBuilder());
		lireFeatures.put(CH, new SimpleColorHistogram());
	}
	if (features.contains(CL)) {
		builders.put(CL, DocumentBuilderFactory.getColorLayoutBuilder());
		lireFeatures.put(CL, new ColorLayout());
	}
	if (features.contains(EH)) {
		builders.put(EH, DocumentBuilderFactory.getEdgeHistogramBuilder());
		lireFeatures.put(EH, new EdgeHistogram());
	}
	if (features.contains(FCTH)) {
		builders.put(FCTH, DocumentBuilderFactory.getFCTHDocumentBuilder());
		lireFeatures.put(FCTH, new FCTH());
	}
	if (features.contains(GABOR)) {
		builders.put(GABOR, DocumentBuilderFactory.getGaborDocumentBuilder());
		lireFeatures.put(GABOR, new Gabor());
	}
	if (features.contains(HCEDD)) {
		builders.put(HCEDD, DocumentBuilderFactory.getHashingCEDDDocumentBuilder());
		lireFeatures.put(HCEDD, new CEDD());
	}
	if (features.contains(JCD)) {
		builders.put(JCD, DocumentBuilderFactory.getJCDDocumentBuilder());
		lireFeatures.put(JCD, new JCD());
	}
	if (features.contains(JH)) {
		builders.put(JH,DocumentBuilderFactory.getJointHistogramDocumentBuilder());
		lireFeatures.put(JH, new JointHistogram());
	}
	if (features.contains(JCH)) {
		builders.put(JCH, DocumentBuilderFactory.getJpegCoefficientHistogramDocumentBuilder());
		lireFeatures.put(JCH, new JpegCoefficientHistogram());
	}
	if (features.contains(LL)) {
		builders.put(LL, DocumentBuilderFactory.getLuminanceLayoutDocumentBuilder());
		lireFeatures.put(LL, new LuminanceLayout());
	}
	if (features.contains(OH)) {
		builders.put(OH, DocumentBuilderFactory.getOpponentHistogramDocumentBuilder());
		lireFeatures.put(OH, new OpponentHistogram());
	}
	if (features.contains(PHOG)) {
		builders.put(PHOG, DocumentBuilderFactory.getPHOGDocumentBuilder());
		lireFeatures.put(PHOG, new PHOG());
	}
	if (features.contains(SC)) {
		builders.put(SC, DocumentBuilderFactory.getScalableColorBuilder());
		lireFeatures.put(SC, new ScalableColor());
	}
	if (features.contains(TAMURA)) {
		builders.put(TAMURA, DocumentBuilderFactory.getTamuraDocumentBuilder());
		lireFeatures.put(TAMURA, new Tamura());
	}
}
 

开发者ID:jinhuang,
项目名称:melody-join,
代码行数:67,
代码来源:GenerateUtil.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)