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.
댓글 수: 0
채택된 답변
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!