hello everyone,
I am running this code and getting warning that text is too long for a messagebox. I set breakpoints and at message it is giving different values and showing messagebox without text. What am I doing wrong here?
code is given below;
close all
clc
workspace;
im = imread('lena.bmp')
Image1= im;
im2 = imread('lena2.bmp')
Image2= im2;
NCC = normxcorr2(Image1,Image2);
message = sprintf('The normalized cross correlation is %.2f.', NCC);
msgbox(message);

 Réponse acceptée

Peter O
Peter O le 24 Sep 2020

0 votes

The NCC return value you're getting back is a matrix of correlation values (for Lena, it's 512x512). The string you're passing to messagebox will print that text 262,144 times (one for each value in the matrix), so yes, it gets pretty big!
Are you looking for the max correlation? If so, just wrap:
maxcorr = max(NCC(:)); % Single max across all
message = sprintf('The max normalized cross correlation is %.2f.', maxcorr);
msgbox(message);
If you're interested in a pattern or more than a single quantity, it might be easier to view it as a 3D surface plot. See the worked example here: https://www.mathworks.com/help/images/ref/normxcorr2.html

5 commentaires

marie lasz
marie lasz le 24 Sep 2020
thank you for your response. The image size are 32x32. And I am trying to find the normalized correlation between two image to see their similarity.
marie lasz
marie lasz le 24 Sep 2020
Modifié(e) : marie lasz le 24 Sep 2020
And tbh I don't know about max correlation . Is that the same to NC?
Peter O
Peter O le 24 Sep 2020
In suggesting max correlation, I was just suggesting something that might print in a message box more easily. It is just going to find the most similar point in the normalized correlation matrix -- the value closest or equal to 1. This point's index can be used for alignment of signals or images.
You're looking at a spatial quantity, so you're going to get a matrix of values back when you look at a correlation (equivalently, for 1-D signals, you get an array).
marie lasz
marie lasz le 24 Sep 2020
If I am not wrong you meant that max() function selects the one closest value/average value from the set of array or matrix. It will print on message box otherwise these values are too big that it cannot be shown.
Peter O
Peter O le 25 Sep 2020
That's correct, it's the one max value which is friendlier to the message box. You could also use mean(NCC(:)) if you wanted the average of the entire matrix.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 25 Sep 2020

0 votes

Get rid of the message and use imshow():
imshow(NCC, []);

Community Treasure Hunt

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

Start Hunting!

Translated by