Find yellow pixels in an image
Show older comments
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.
Yingxiu Guo
on 26 Jun 2019
Accepted Answer
More Answers (1)
KSSV
on 25 Jun 2019
0 votes
Loop not required...refer this https://in.mathworks.com/matlabcentral/answers/4508-modify-this-code-to-detect-yellow-colour
2 Comments
Yingxiu Guo
on 25 Jun 2019
Image Analyst
on 26 Jun 2019
How could we know? -- you forgot to attach your image.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!