How can i count the number of pixels for a specific color using the L*A*B?

조회 수: 2 (최근 30일)
I want to write a code that will count the number of pixels for all the tints of a specific color in an image.

채택된 답변

Image Analyst
Image Analyst 2020년 6월 26일
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
Stephani Kanga
Stephani Kanga 2020년 6월 28일
Yes for example i have this image and i want to calculate the % of the pixels that have dark purple-black color.
Image Analyst
Image Analyst 2020년 6월 28일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by