How to use 'corr' function

16 次查看(过去 30 天)
Ali Bunny
Ali Bunny 2021-1-15
I encountered such an assignment:
For each ith coin centroid found in step 1, compute jth (j = 1, 2, and 3 should correspond to the dime, nickel and quarter filters, respectively) matching filter result by computing the correlation between the matching filter and the local region of image pixels that fall within filtsizeh (half the matching filter width) rows and columns to the centroid. Store the result in D(i,j)
I found all matching filters (dime nickel and quarter). Their sizes are 85x85 matrix.
for i = 1:size(centroid,1)
D(i,1) = corr(dimefilter,....)
D(i,2) = corr(nickelfilter,....)
D(i,3) = corr(quarterfilter,....)
end
I create such a for function and I believe it will create 14*3 maxtrix which is required. My problem is I don't know how to work with 'corr' function. I don't know what variables I should put inside of 'corr' function. Finally, I need some tiny hint to get understand the purpose of this exercise. Can anybody help me to figure out with this.

回答(1 个)

Anudeep Kumar
Anudeep Kumar 2025-6-24
From your description I believe the goal is to measure how well each coin region looks like a dime, nickel or quarter.
We can use 'corr' function to tell the statistical similarity between the filter and the image pixel or patch of the image.
We are storing it in a matrix D(i,j) where 'j' is filter index and 'i' is coin index.
MATLAB's 'corr' returns a matrix of the pairwise correlation coefficient between each pair of columns in the input matrices X and Y. Higher the correlation, better is the match.
To use 'corr' you should
  • Flatten both the image patch and the filter into vectors using '(:)'
  • Make sure patches are same size of filter, i.e, 85x85
Assuming filter size 85, the below code should help you come close to what you want to achieve:
filtsizeh = floor(85 / 2); % Half filter size
for i = 1:size(centroid, 1)
cx = round(centroid(i,2)); % y-coordinate (row)
cy = round(centroid(i,1)); % x-coordinate (column)
% Extract local patch around centroid
patch = image(cx-filtsizeh:cx+filtsizeh, cy-filtsizeh:cy+filtsizeh);
% Flatten and correlate
D(i,1) = corr(patch(:), dimefilter(:));
D(i,2) = corr(patch(:), nickelfilter(:));
D(i,3) = corr(patch(:), quarterfilter(:));
end
Here is the documentation of 'corr' for your reference:

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by