How can I calculate surface area of black vs red balls in this image ?

1 view (last 30 days)
I am a matlab noob and need some help. I have an image where ideally I would like to count the number of red and black balls. At the minimum though I would like to calculate the fraction of red vs black. Thanks for your help in advance. Currently I have masked the image to only look at the circular area and have tried thresholding in grey scale but don't seem to be getting anywhere. Thanks for your help in advance.
close all; clear all; % Read Image rgb = imread('DSC_0377.jpg');
t = 0:pi/20:2*pi;
xc=1740; % point around which I want to extract/crop image
yc=1625;
r=920; %Radium of circular region of interest
xcc = r*cos(t)+xc;
ycc = r*sin(t)+yc;
roimaskcc = poly2mask(double(xcc),double(ycc), size(rgb,1),size(rgb,2));
% NaN everything outside the mask (in R, G and B layers) rgb1(repmat(~roimaskcc,[1,1,3])) = NaN; figure,imshow(rgb1) BW1 = im2bw(rgb1,0.7);
figure,imshow(rgb1)
figure,imshow(BW1)

Answers (1)

Image Analyst
Image Analyst on 15 Nov 2014
Edited: Image Analyst on 15 Nov 2014
You can probably get fairly accurate simply doing color segmentation in RGB space. See my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 Extract into R, G, and B and then look for red as having a high red signal and low green and blue signals. You may need to do some special things to get rid of the specular reflections. Why not use crossed polarizers? That's the usual method.

Community Treasure Hunt

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

Start Hunting!