I'm trying to crop a circle from an image using imfindcircle... but It deosn't work. what is the issue ?

5 Ansichten (letzte 30 Tage)
Here is my code
imfindcircle can find the circle(traffic sign) but the mask to crop it , is not functioning
clc;
close all;
image = imread('111.jpg');
hsv = rgb2hsv(image);
h= hsv(:,:,1);
s= hsv(:,:,2);
maskh = (h <= 0.09) | (h >= 0.9);
masks = s >= 0.2 ;
redmask = uint8(maskh & masks) ;
redmasko = bwareaopen(redmask,50);
[centers,radii,metric] = imfindcircles(redmasko,[20 50]);
h = viscircles(centers,radii);
imagesize= size(image);
[xx,yy] = ndgrid((1:imagesize(1))-centers(1),(1:imagesize(2))-centers(2));
mask = uint8((xx.^2 + yy.^2)<(radii^2));
croppedImage = uint8(zeros(size(image)));
croppedImage(:,:,1) = image(:,:,1).*mask;
croppedImage(:,:,2) = image(:,:,2).*mask;
croppedImage(:,:,3) = image(:,:,3).*mask;
figure ; imshow(croppedImage);

Akzeptierte Antwort

Matt J
Matt J am 5 Sep. 2019
Bearbeitet: Matt J am 5 Sep. 2019
Swap the coordinates in the output of imfindcircles.
[xx,yy] = ndgrid((1:imagesize(1))-centers(2),(1:imagesize(2))-centers(1));

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by