help with imfindcircles function

i used imfindcircles to detect circles in image and it works good then i tried to get the color of the circles that the function detected but i can't cause the centers that it returned wasn't in pixels !!

3 Commenti

can you give more details?
what does it returns if not pixels?
notice that the function return values are:
[centers, r_estimated, metric] = imfindcircles(varargin)
and that "A can be a grayscale, RGB or binary image".
centers are value of numbers like "3.255309863557299e+02" pixels must be without fractions so !!
Not necessarily. See my answer. It works perfectly with fractional locations.

Accedi per commentare.

 Risposta accettata

See the FAQ to Create a circle mask: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F. Then extract each color channel from the RGB image. Use the mask to extract the color channel pixels inside the mask. Then get their mean or whatever you want to do with them.
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels);
colormap([0 0 0; 1 1 1]);
title('Binary image of a circle');
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get pixels inside mask for each color channel
redPixels = redChannel(circlePixels);
greenPixels = greenChannel(circlePixels);
bluePixels = blueChannel(circlePixels);
% Get means
redMean = mean(redPixels);
greenMean = mean(greenPixels);
blueMean = mean(bluePixels);
Repeat for each circle that you have.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by