I would reccomend using the Color Thresholder App which is part of the Image Processing Toolbox. You can load in an image either from a GUI or from your workspace (use imread). Use HSV color space and adjust your V value as you want the darker region.
Your MATLAB script would look something like this:
I = imread('image1.jpg');
[BW,maskedRGBImage] = createMask(I);
imshow(BW)
Where the createMask function is autogenerated from the app:
function [BW,maskedRGBImage] = createMask(RGB)
I = rgb2hsv(RGB);
channel1Min = 0.000;
channel1Max = 1.000;
channel2Min = 0.000;
channel2Max = 1.000;
channel3Min = 0.000;
channel3Max = 0.236;
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
maskedRGBImage = RGB;
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
The result is (in black and white):
From there you can use regionprops to get all the information you need.
Best Answer