Find yellow pixels in an image
37 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Yingxiu Guo
il 25 Giu 2019
Commentato: Image Analyst
il 26 Giu 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 Commenti
Jan
il 25 Giu 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.
Risposta accettata
Image Analyst
il 26 Giu 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 Commenti
Più risposte (1)
KSSV
il 25 Giu 2019
Loop not required...refer this https://in.mathworks.com/matlabcentral/answers/4508-modify-this-code-to-detect-yellow-colour
2 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!