Ask Your Question
1

Measure similarity between two images with the same size

asked 2019-06-18 11:41:09 -0600

JimZhou001 gravatar image

updated 2019-06-22 02:03:26 -0600

Hello, I meet a problem how to measure the similarity between two image.

Though there are some solutions in the following link, they can't solve my problem.

https://answers.opencv.org/question/5...

It seems that (normalized) cross correlation is to find the best match of a small image from a big one. What's worse, it can get a maximal score in any case, even when there is no similar region in the big image.

Histogram comparison is too simple to distinguish different regions. In my case, all results are 0.99 … Maybe it's because the differences between them are really small. But at least we humans can see whether they are similar or not easily. So I'm looking up for better methods.

As for feature point matching, the result are really poor when there are ambiguities.

So, how can we measure similarity between two images with the same size?

Thank you very much!

Here I find an useful tool.

https://deepai.org/machine-learning-m...

But I want to search for some source code. It's very nice if the code is based on opencv (images with Mat format).

Acturally my images are like the following ones.

image description Image 1

image description Image 2

image description Image 3

I need to compare image 1 with image 2 and image 3, and find that image 2 (instead of image 3) is more similar to image 1.

edit retag flag offensive close merge delete

Comments

sturkmen gravatar imagesturkmen ( 2019-06-22 01:31:19 -0600 )edit

Thank you! @sturkmen

I tried them before. But the results are not so good.

JimZhou001 gravatar imageJimZhou001 ( 2019-06-22 01:49:21 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2019-06-22 08:51:13 -0600

When I use template matching with TM_CCOEFF_NORMED, I get

0.83 score for Image1 & Image2 and

0.37 score for Image1 & Image3

    Mat image1Img = imread("image1.png", IMREAD_COLOR);
Mat image2Img = imread("image2.png", IMREAD_COLOR);
Mat image3Img = imread("image3.png", IMREAD_COLOR);

Mat scoreImg;
double maxScore;

matchTemplate(image1Img, image2Img, scoreImg, TM_CCOEFF_NORMED);
minMaxLoc(scoreImg, 0, &maxScore);
wxLogMessage(wxString::Format("score <%.2f>", maxScore));

matchTemplate(image1Img, image3Img, scoreImg, TM_CCOEFF_NORMED);
minMaxLoc(scoreImg, 0, &maxScore);
wxLogMessage(wxString::Format("score <%.2f>", maxScore));
edit flag offensive delete link more

Comments

Wow, thank you.

But I have some doubts.

When we use different template, dose matchTemplate return comparable values? And you use matchTemplate in whole images. When image1Img doesn't contain image2Img, can we also use this function?

And I have said my images are actually with the same size. The images I gave are just to illustrate. So in real case, each scoreImg has just one element which can't be used in minMaxLoc correctly.

Finally, my images are rectified, so there will be some black regions.

JimZhou001 gravatar imageJimZhou001 ( 2019-06-22 10:38:56 -0600 )edit

Or if we can find a shared and unique region in both images, we can use matchTemplate. But how can we find this kind of region. (All windows are considered the same)

JimZhou001 gravatar imageJimZhou001 ( 2019-06-22 10:48:19 -0600 )edit

If you give matchTemplate two images that are the same size, it will return a single value or score. This score will be a measure of similarity. If the two images are very different, you should get a low score. I did use minMaxLoc on the score image but I guess that wasn't necessary since the scoreImg should only have one value.

I'm not sure what you mean by rectified. Can you share some "real" images?

Chris gravatar imageChris ( 2019-06-23 08:42:29 -0600 )edit

Hi, you got resolve its problem? I have equal problem, i need identify regions equals in two images

txavier gravatar imagetxavier ( 2020-09-06 19:08:42 -0600 )edit

@txavier asking a new question will be more helpful to you.

sturkmen gravatar imagesturkmen ( 2020-09-06 23:52:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-06-18 11:41:09 -0600

Seen: 9,798 times

Last updated: Jun 22 '19