How can i count the number of pixels for a specific color using the L*A*B?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Stephani Kanga
le 26 Juin 2020
Commenté : Image Analyst
le 28 Juin 2020
I want to write a code that will count the number of pixels for all the tints of a specific color in an image.
0 commentaires
Réponse acceptée
Image Analyst
le 26 Juin 2020
Just make a mask and use nnz():
lMask = lImage > Lmin & lImage <= Lmax;
aMask = aImage > Amin & aImage <= Amax;
bMask = bImage > Bmin & bImage <= Bmax;
overallMask = lMask & aMask & bMask;
numberOfPixels = nnz(overallMask)
Of you can make a 3-D histogram.
Look at colorcloud().
4 commentaires
Image Analyst
le 28 Juin 2020
OK. So did you do it? The demo gives you the class for each pixel so just sum them up and divide by the number of pixels and multiply by 100 to get percent area for each class.
classCounts = histcounts(pixel_labels)
percentAreas = 100 * classCounts / numel(pixel_labels)
The tricky part is you have to know which class is dark purple but you can look at the cluster centers to get the color of each class and then you can figure out what class number dark purple is. That class number could possibly vary each time you run the program because kmeans uses random numbers.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
