Write an image processing algorithm that measures the surface area of the green pills in pixels
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/393853/image.bmp)
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?
댓글 수: 0
답변 (1개)
Mathieu NOE
2020년 10월 28일
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!