Find yellow pixels in an image
7 views (last 30 days)
Show older comments
Yingxiu Guo
on 25 Jun 2019
Commented: Image Analyst
on 26 Jun 2019
So I have an image, jpg file, which means it is RGB?
I want to find out how many pixels are yellow, the following code is what I have now. Shouldn't be too hard except I don't know the syntax
img=imread('MyImage');
[a,b,c]=size(img);
count_y=0;
for i=1:a
for j=1:b
if img(a,b)==yellow %%% How do I write this line??
count_y=count_y+1;
end
end
end
Thanks folks!
2 Comments
Jan
on 25 Jun 2019
if img(a, b, :) == yellow
% ^
You have to consider the RGB values, therefore you need to extract the [1x3] RGB vector for each pixel.
How do you define "yellow" exactly? There are different RGB colors looking very yellowish, so "yellow" means a range of colors usually. Then the HSV color space is smarter. There are different methods to determine the distance between colors in the HSV space, but it is your turn to define, what "yellow" is for your needs.
Accepted Answer
Image Analyst
on 26 Jun 2019
Use the Color Thresholder on the Apps tab of the tool ribbon. Select HSV color space and load your image then select thresholds and then export the function.
2 Comments
More Answers (1)
KSSV
on 25 Jun 2019
Loop not required...refer this https://in.mathworks.com/matlabcentral/answers/4508-modify-this-code-to-detect-yellow-colour
2 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!