Reputation: 1142
I have detected a circle as shown below:
As later I want to detect what speed limit is in the detected sign, how do I crop it out so that I am left with an image like below?
When program finishes it, it shows me where the center is and the radii in terminal.
centers =
248.4873 170.4811
radii =
24.5024
I know how to use imcrop
but how do I use the values that are returned instead of writing in them myself, as there might be more than 1 circle detected?
Code:
I = imread('p1.tif');
subplot(3,3,1); imshow(I); title('Original Image');
%sharpen edges
B = imsharpen(I);
subplot(3,3,2); imshow(B); title('sharpened edges');
%find circles
Img = im2bw(B(:,:,3));
minRad = 20;
maxRad = 90;
[centers, radii] = imfindcircles(Img, [minRad maxRad], ...
'ObjectPolarity','bright','sensitivity',0.87)
imagesc(Img);
viscircles(centers, radii,'Color','green');
Upvotes: 1
Views: 303
Reputation: 469
Assuming you have one centre and one radius. This should do it
rect = [centers(1)-radii,centers(2)-radii,2*radii,2*radii]
I2 = imcrop(I,rect)
For multiple circles you can do this process for each of the circle returned in a loop.
Upvotes: 2