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

1 visualización (últimos 30 días)
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);

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Assembly en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by