Finding correlation between two images

5 ビュー (過去 30 日間)
Mohammad Saquib Khan
Mohammad Saquib Khan 2021 年 9 月 24 日
コメント済み: Image Analyst 2021 年 9 月 25 日
Suppose I want to perform correlation between two images. I know there is a function normxcorr2 which can be used to find the correlation between two images (img1, img2) like this
When I run the imfilter command and use the imshow() command to output the resulting image, I can see that it is different from what I get when I output the resulting image using normxcorr2 command.The image generated through normxcorr2 looks more like what i would expect from the correlation of the two images. What's the difference between these two methods?
C = normxcorr2(img1, img2)
But can I find the correlation using imfilter? Does this command perform correlation?
corr = imfilter(img1, img2, 'corr','replicate');
When I run the imfilter command and use the imshow() command to output the resulting image, I can see that it is different from what I get when I output the resulting image using normxcorr2 command.
imshow(C);
figure
imshow(corr);
The image generated through normxcorr2 looks more like what i would expect from the correlation of the two images. What's the difference between these two methods? Is using imfilter even logical?
  2 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 9 月 24 日
Have you looked in the documentation how normxcorr2 normalizes the x-correlation values for the different shifts, it seems a "natural" guess that it properly scales with the number of samples, while imfilter might "not bother with that" since its purpose is mainly to filter images.
Mohammad Saquib Khan
Mohammad Saquib Khan 2021 年 9 月 24 日
I haven't yet looked into the documentation but I will surely do that now. What if after computing my variable corr, I normalise it? Will then the the two resulting images be same?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2021 年 9 月 24 日
normxcorr2() scans the image with a window and does a normalization at each location. imfilter() does not. It simply moves the window, multiplies the pixels together, and sums -- no normalization. You cannot normalize a xcorr2() or imfilter() output image to make it look like what it would look like if it had normalized the subimages at each location.
  4 件のコメント
Mohammad Saquib Khan
Mohammad Saquib Khan 2021 年 9 月 24 日
If I use xcorr2, I just get a simple white image. But when I used normxcorr2, I get an image where I can see a pattern. So I guess normxcorr2 is the right way. Thank you so much for your help!
Image Analyst
Image Analyst 2021 年 9 月 25 日
If your output is a floating point image you're going to have to make sure it's in the range 0-1 or else any values more than 1 will show up as white. Try casting to uint8 before display. If it's a gray scale floating point image, try
imshow(yourImage, []);

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by