Write an image processing algorithm that measures the surface area of the green pills in pixels

1 view (last 30 days)
long le
long le on 27 Oct 2020
Answered: Mathieu NOE on 28 Oct 2020
Considering the image ‘pills2’, write an image processing algorithm that measures the surface area of the green pills in pixels. The pills pixels must be isolated as white pixels while the rest of the image must be colored in black.
I = imread('pills2.bmp');
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
hsv = rgb2hsv(I);
H = hsv(:,:,1);
figure,imshow(H), title('Hue');
How can I do next?

Answers (1)

Mathieu NOE
Mathieu NOE on 28 Oct 2020
hi
this is my 2 cents suggestion - but I am not truly an image processing expert
For what I know your "green" definition must be more precise, because it covers quite a large range of RGB triplets
see :
So you have to play with the individual R,G,B triplets or find a smarter way to compare with a RGB table that list allcombinations considered as green
I = imread('pills2.bmp');
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
thresholdValueR = 0.4*(max(max(R)));
thresholdValueG = 0.5*(max(max(G)));
thresholdValueB = 0.65*(max(max(B)));
binaryImage = R < thresholdValueR & G > thresholdValueG & B < thresholdValueB;
figure(2),
subplot(2,1,1),imshow(I), title('H');
subplot(2,1,2),imshow(binaryImage), title('Binary Image');
[a,b] = size(binaryImage == 1);
nb_of_G_pixels = a*b

Community Treasure Hunt

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

Start Hunting!