示例#1
0
        public List <String> perceptualSim(String imgPath)
        {
            Console.WriteLine("doing perceptual..");

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            double threshold = 1.5;
            Dictionary <String, double> tempResults = new Dictionary <string, double>();
            PerceptualSimilarity        ps          = new PerceptualSimilarity();

            Bitmap                       img            = new Bitmap(imgPath);
            ComputeHistogram             ch             = new ComputeHistogram();
            Dictionary <LUVClass, float> luv            = ch.convertToLuv(ch.getRGBValues(img));
            Dictionary <int, float>      queryHistogram = ch.quantizeColors(luv, 0);

            foreach (String path in fileEntries)
            {
                Bitmap dImg = new Bitmap(path);
                Dictionary <LUVClass, float> luv2       = ch.convertToLuv(ch.getRGBValues(dImg));
                Dictionary <int, float>      dHistogram = ch.quantizeColors(luv2, 0);

                Dictionary <int, float> qHist = new Dictionary <int, float>();
                Dictionary <int, float> dHist = new Dictionary <int, float>();

                //normalize
                foreach (KeyValuePair <int, float> k in queryHistogram)
                {
                    qHist[k.Key] = queryHistogram[k.Key] / (img.Width * img.Height);
                }

                foreach (KeyValuePair <int, float> k in dHistogram)
                {
                    dHist[k.Key] = dHistogram[k.Key] / (dImg.Width * dImg.Height);
                }

                double similarity = ps.getSimilarity(qHist, dHist);
                if (similarity > threshold)
                {
                    tempResults[path] = similarity;
                }
            }

            stopwatch.Stop();
            Console.WriteLine("Done! Time: " + stopwatch.ElapsedMilliseconds);
            //printDictionary(tempResults);
            return(reversedOrderList(tempResults));
        }