Beispiel #1
0
        public void Index(DirectoryInfo folder)
        {
            var imagesOnDisk = FileHelper.GetImages(folder);

            _images.Clear();
            _imageGlobalColorDescriptors.Clear();
            _imageLocalDescriptors.Clear();

            foreach (var image in imagesOnDisk)
            {
                ColorHistogramPerRegionImageFeature colorFeature = new ColorHistogramPerRegionImageFeature();
                SurfImageFeatures features = new SurfImageFeatures();
                using (Image <Bgr, Byte> tempImage = new Image <Bgr, Byte>(image.FullName))
                {
                    using (Image <Gray, Byte> tempGrayImage = tempImage.Convert <Gray, byte>())
                    {
                        colorFeature.Compute(tempImage);
                        features.Compute(tempGrayImage);

                        var imageItem = new ImageItem(image.Name, image.FullName, features.Descriptors, colorFeature.Descriptors);

                        if ((colorFeature.Descriptors != null) && (features.Descriptors != null))
                        {
                            _images.Add(imageItem);
                            _imageGlobalColorDescriptors.Add(colorFeature.Descriptors);
                            _imageLocalDescriptors.Add(features.Descriptors);
                        }
                    }
                }
            }

            _localSimilarityEngine.Index(_imageLocalDescriptors);
            _globalSimilarityEngine.Index(_imageGlobalColorDescriptors);
        }
Beispiel #2
0
        private List <KeyValuePair <ImageItem, float> > QueryUsingPHistogram(Image <Bgr, Byte> queryImage)
        {
            List <KeyValuePair <ImageItem, float> > results      = new List <KeyValuePair <ImageItem, float> >();
            ColorHistogramPerRegionImageFeature     queryFeature = new ColorHistogramPerRegionImageFeature();

            queryFeature.Compute(queryImage);
            _globalSimilarityEngine.ComputeSimilarities(queryFeature.Descriptors);

            float[] distances = _globalSimilarityEngine.Distances;
            for (int index = 0; index < _imageGlobalColorDescriptors.Count; ++index)
            {
                if (distances[index] <= 10000.0f)
                {
                    results.Add(new KeyValuePair <ImageItem, float>(_images.ImageItems[index], distances[index]));
                }
            }

            results.Sort(delegate(KeyValuePair <ImageItem, float> first, KeyValuePair <ImageItem, float> second)
            {
                if (first.Value > second.Value)
                {
                    return(1);
                }
                if (first.Value < second.Value)
                {
                    return(-1);
                }

                return(0);
            });

            return(results);
        }