
package pl.gda.biomed.jwr.color;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author jwr
 */
public class SearchImages {

    /**
     * @param args the command line arguments
     */
    
    public int [] getDominantColor(File f) throws IOException{
        int []rgb=new int[3];
        BufferedImage bi=ImageIO.read(f);
        AverageColor ac=new AverageColor();
        rgb=ac.getHistDominantColor(bi);
        return rgb;
    }
    
    public static void main(String[] args) {
        TreeSet<ImageMetaData> coll=new TreeSet<ImageMetaData>();
        
        SearchImages si=new SearchImages();
        int [] rgbR=new int[3];
        
        int [] rgbDB=new int[3];
        try {
            rgbR = si.getDominantColor(new File("/Users/jwr/Desktop/test2.png"));
            
            File fDB=new File("/Users/jwr/Desktop/test9.png");
            ImageMetaData imd=new ImageMetaData();
            rgbDB = si.getDominantColor(fDB);
            imd.dominantColor=rgbDB;
            imd.fileLocation=fDB;
            imd.similarity=ColorSimilarityMeasure.getEuclSimilarity(rgbR, rgbDB);
            
            coll.add(imd);
            
            fDB=new File("/Users/jwr/Desktop/test4.png");
            imd=new ImageMetaData();
            rgbDB = si.getDominantColor(fDB);
            imd.dominantColor=rgbDB;
            imd.fileLocation=fDB;
            imd.similarity=ColorSimilarityMeasure.getEuclSimilarity(rgbR, rgbDB);
            
            coll.add(imd);
            
            fDB=new File("/Users/jwr/Desktop/test8.png");
            imd=new ImageMetaData();
            rgbDB = si.getDominantColor(fDB);
            imd.dominantColor=rgbDB;
            imd.fileLocation=fDB;
            imd.similarity=ColorSimilarityMeasure.getEuclSimilarity(rgbR, rgbDB);
            
            coll.add(imd);
            
            for(ImageMetaData imdO:coll){
                System.out.println("Image: "+imdO.fileLocation+", Similarity= "+imdO.similarity);
            }
            
        } catch (IOException ex) {
            Logger.getLogger(SearchImages.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Kolor dominujący to: "+Arrays.toString(rgbR));
        
    }

}
