MATLAB: Help with imfindcircles function

color measurementImage Processing Toolboximfindcircles color pixels

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 !!

Best Answer

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.