How to use 'corr' function

20 visualizzazioni (ultimi 30 giorni)
Ali Bunny
Ali Bunny il 15 Gen 2021
Risposto: Anudeep Kumar il 24 Giu 2025
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.

Risposte (1)

Anudeep Kumar
Anudeep Kumar il 24 Giu 2025
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:

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by