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: