How to counts matched object from main image with the template sub-Image

3 次查看(过去 30 天)
I have a task where I should count numbers of suits(diamonds, clubs, ...) in a set of playing cards image. I have created a template sub-image for diamond from my original image for example, using imcrop in Matlab. I have also converted both Original or target Image in grayscale. I'm trying to find the match of the sub-image in the target image and counts the corresponding diamonds in the target image.
Does anyone have a suggestion?
I try to use normxcorr2 I got a plot where I can see the area with highest peak, but I don't have any ideas how to compute this.
Any suggestions of algorithms.
Thank you.

回答(1 个)

Jakob
Jakob 2017-8-3
编辑:Jakob 2017-8-3
Using normxcorr2 will give you the point of highest correlation between image and template.
% Perform registration
reg = normxcorr2(t,sI);
% find peaks and location and offset
[dy,dx] = find(reg== max(reg(:)));
Where t is the template and sI is the search image. You can then find the offset with:
yoffSet = dy-size(t,1);
xoffSet = dx-size(t,2);
P(yoffSet+1,yoffSet+1) is the point in the sI where the template starts.

Community Treasure Hunt

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

Start Hunting!

Translated by