Compare images and find the most similar

16 views (last 30 days)
Hello, I am new in this web site, but I am finding a good support and help by the community, so firstly, I want to say thank you in advance for your time and support.
My problem is that I want to compare one image with several models with differences each one, with the intention to clasify this image, for example the following music notes would be our data base:
and the image to clasify would be the following:
Then I am trying to compare my image with all the previous masks one by one, and find the most similar to my main image. I tried with the detectSURFFeatures, but the image doesn´t have sufficient details to this technique... so I am looking for other idea to do this.
Maybe comparing the Histograms between every image and finding the most similar? Please if someone have another idea, he/she is welcome. Thank you very much.

Accepted Answer

Alex Taylor
Alex Taylor on 14 Jan 2014
Edited: Alex Taylor on 14 Jan 2014
Image Analyst's answer is extremely computationally efficient and a good solution to the problem. If it happened that you had additional notes in your database with similar numbers black pixels, another approach that you could use that would take into account the actual geometric similarity between the notes would be normalized cross correlation.
For example:
noteOfInterest = imread('');
noteOfInterest = rgb2gray(noteOfInterest);
C1 = normxcorr2(noteOfInterest,noteOfInterest);
Now compare this peak normalized correlation to a note from the database which is dissimilar:
aDifferentNoteFromLibrary = imread('');
aDifferentNoteFromLibrary = rgb2gray(aDifferentNoteFromLibrary);
C2 = normxcorr2(noteOfInterest,aDifferentNoteFromLibrary);
We see that C1 has a peak normalized cross correlation of 1.0 when the same image is correlated with itself, and a lower peak normalized cross correlation when two dissimilar images are correlated in C2.
In this approach, you would have to correlate the note being classified with each note in the database, then choose the one with the largest peak normalized cross correlation. This will certainly be slower than Image Analyst's approach, so I'd use the proposed lookup table approach if that provides an accurate classification.
Alberto on 15 Jan 2014
Thank you very much for your time and support. Your solution has helped me a lot. I think that by this way I can continue with my project. One more time thank you for your support.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Jan 2014
The simplest way is to count the number of black pixels. That's assuming all your notes are perfect ones like this. As they get more corrupted and noisy, this method deteriorates. The number of black pixels for each note is unique so you can just use a lookup table to find out which note it is. For example
lookupTable = [1000, 850, 1100, 1200];
Then let's say your 'test" note has 870 black pixels, then just
blackInMyNote = 870;
[~, noteNumber] = min(abs(blackInMyNote - lookupTable))
noteNumber is your answer.
Image Analyst
Image Analyst on 15 Jan 2014
Rotation with my method with high quality notes should be fine - it will still find the proper note and will work. With scaling, it won't, and you'll have to look into more sophisticated pattern recognition methods, or else try to scale the test image to be the proper size. Of course if you have a lot of clutter/garbage/noise then it gets more and more difficult to identify the proper note.

Sign in to comment.


Find more on Rubik's Cube in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by