How can I count pixel of particular color in image?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
GeonWoo Jeon
le 31 Oct 2017
Commenté : Image Analyst
le 10 Juin 2021
I want to count the number of pixels with particular color in the image below. What function can I use to count pixels?
The size of this image is 672*708*3.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168997/image.png)
0 commentaires
Réponse acceptée
Image Analyst
le 31 Oct 2017
For example, to get the number of yellow pixels:
yellowPixels = rgbImage(:,:,1) == 255 & rgbImage(:,:,2) == 255 & rgbImage(:,:,3) == 0;
numYellowPixels = sum(yellowPixels(:));
To get the number of blue pixels:
bluePixels = rgbImage(:,:,1) == 0 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 255;
numBluePixels = sum(bluePixels(:));
9 commentaires
Iszuzuldin amirull bin mohd janudin
le 9 Juin 2021
mask= g_channel > 100, b_channel > 800, r_channel < 800, b_channel < 0, r_channel < 0;
numBlackPixels = sum(~mask(:))
how can i change to yellow mask ?
Image Analyst
le 10 Juin 2021
@Iszuzuldin amirull bin mohd janudin, try using the Color Thresholder app on the Apps tab of the tool ribbon. Segment your image, probably using the HSV color space would be good. then tell it to export the code as a function that you can then call from your program.
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!