help with imfindcircles function
6 views (last 30 days)
Show older comments
mohamed samy
on 25 Aug 2014
Commented: mohamed samy
on 25 Aug 2014
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 Comments
Image Analyst
on 25 Aug 2014
Not necessarily. See my answer. It works perfectly with fractional locations.
Accepted Answer
Image Analyst
on 25 Aug 2014
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.
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!