/// <summary> /// Set search options from the UI (method, filter and similarity cutoff) /// </summary> private void ReadSearchOptions() { // method switch (this.CBMethod.SelectedIndex) { case 0: option_image_hash = Images.ImageHashAlgorithm.Average; break; case 1: option_image_hash = Images.ImageHashAlgorithm.AverageHistogram; break; case 2: option_image_hash = Images.ImageHashAlgorithm.AverageColor; break; case 3: option_image_hash = Images.ImageHashAlgorithm.Block; break; case 4: option_image_hash = Images.ImageHashAlgorithm.BlockHistogram; break; case 5: option_image_hash = Images.ImageHashAlgorithm.BlockColor; break; case 6: option_image_hash = Images.ImageHashAlgorithm.Color; break; case 7: option_image_hash = Images.ImageHashAlgorithm.Difference; break; case 8: option_image_hash = Images.ImageHashAlgorithm.DifferenceHistogram; break; case 9: option_image_hash = Images.ImageHashAlgorithm.DifferenceColor; break; case 10: option_image_hash = Images.ImageHashAlgorithm.Histogram; break; case 11: option_image_hash = Images.ImageHashAlgorithm.Perceptive; break; case 12: option_image_hash = Images.ImageHashAlgorithm.PerceptiveHistogram; break; case 13: option_image_hash = Images.ImageHashAlgorithm.PerceptiveColor; break; default: option_image_hash = Images.ImageHashAlgorithm.PerceptiveHistogram; break; } // filter switch (this.CBFilter.SelectedIndex) { case 0: option_filter_colors = Images.ComparisonMethod.None; break; case 1: option_filter_colors = Images.ComparisonMethod.MainColor; break; case 2: option_filter_colors = Images.ComparisonMethod.TopColors; break; case 3: option_filter_colors = Images.ComparisonMethod.PixelsDifference; break; case 4: option_filter_colors = Images.ComparisonMethod.PixelsDifferenceSorted; break; case 5: option_filter_colors = Images.ComparisonMethod.PixelsDistance; break; case 6: option_filter_colors = Images.ComparisonMethod.PixelsDistanceSorted; break; default: option_filter_colors = Images.ComparisonMethod.TopColors; break; } // similarity switch (this.CBSimilarity.SelectedIndex) { case 0: option_similarity_cutoff = 65; break; case 1: option_similarity_cutoff = 70; break; case 2: option_similarity_cutoff = 75; break; case 3: option_similarity_cutoff = 80; break; case 4: option_similarity_cutoff = 85; break; case 5: option_similarity_cutoff = 90; break; case 6: option_similarity_cutoff = 95; break; case 7: option_similarity_cutoff = 100; break; default: option_similarity_cutoff = 90; break; } }
/// <summary> /// Search similar images /// </summary> /// <param name="image"> path of image of interest </param> /// <param name="imagehash"> Image hash algorithm </param> /// <param name="filter_method"> Color filtering method </param> /// <param name="similarity_cutoff"> min. similarity % </param> /// <returns></returns> public Dictionary <string, int> SearchSimilarImages(string image, Images.ImageHashAlgorithm imagehash, Images.ComparisonMethod filter_method, int similarity_cutoff) { var matches = new Dictionary <string, int>(); similar_images_found = new Dictionary <string, int> [number_of_index]; Parallel.For(0, number_of_index, i => { var found = new Dictionary <string, int>(); found.Add(image, 100); if (index_list[i].Count > 0) { found = index_list[i].SearchSimilarImages(image, imagehash, filter_method, similarity_cutoff); } similar_images_found[i] = found; }); if (similar_images_found == null) { return(matches); } if (similar_images_found.Length == 0) { return(matches); } foreach (var images_found in similar_images_found) { matches = matches.Union(images_found).ToDictionary(k => k.Key, v => v.Value); } return(matches); }