MATLAB: Circle centered on the object

contourImage Processing Toolboxpattern recognition

I have a reference image that contains 10 items. I have separate objects in small images (cut from the reference image). Code sequence must find an object that you selected (if the write code sequence "object 1" must make a circle around the "object 1" If it says "Objective 2" to make the circle around the "item 2" Can you help me please? reference image
Object
clear; clc;
I = imread('di-5Y01.jpg');
object = imread('di-FNMJ.jpg');
c = normxcorr2(object(:,:,1),I(:,:,1));
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = ind2sub(size(c),imax(1));
corr_offset = [(xpeak-size(object,2)) (ypeak-size(object,1))];
figure, imshow(I); hold on;
rectangle('position',[corr_offset(1) corr_offset(2) 30 60],...
'curvature',[1,1],'edgecolor','g','linewidth',2);
Code sequence works but not centered the circle on the object.

Best Answer

Hello, Why don't you use rectangle??
Why must circle??
I have my code detect the exact area if you consider to use rectangle??
Would you use rectangle? Then I'll give u the code
Here the results :
Object 1:
Object 2:
Object 3: