How do I count the number of all color pixels of different shades in the image attached?

조회 수: 9 (최근 30일)
The picture attached is 256x256 represents the regions of different colors. When I use the color pixel count using the following code that doesn't give the correct counts of each pixel color when I sum up the whole counts it ends up 50333 but I think it should be 65536. Kindly help to correct the code as I think where there are region boundaries the color intensities are changing thats why the counts are not correct and if its so then how can I manage?
clc;
clear;
close all;
I = imread('B001.png');
YellowPixelsI = I(:,:,1) == 255 & I(:,:,2) == 255 & I(:,:,3) == 0;
numYellowPixelsI = sum(YellowPixelsI(:));
LimePixelsI = I(:,:,1) == 0 & I(:,:,2) == 127 & I(:,:,3) == 0;
numLimePixelsI = sum(LimePixelsI(:));
GreenPixelsI = I(:,:,1) == 0 & I(:,:,2) == 255 & I(:,:,3) == 0;
numGreenPixelsI = sum(GreenPixelsI(:));
IndigoPixelsI = I(:,:,1) == 74 & I(:,:,2) == 0 & I(:,:,3) == 129;
numIndigoPixelsI = sum(IndigoPixelsI(:));
TealPixelsI = I(:,:,1) == 0 & I(:,:,2) == 127 & I(:,:,3) == 127;
numTealPixelsII = sum(TealPixelsI(:));
RedPixelsI = I(:,:,1) == 255 & I(:,:,2) == 0 & I(:,:,3) == 0;
numRedPixelsI = sum(RedPixelsI(:));
BrownPixelsI = I(:,:,1) == 164 & I(:,:,2) == 41 & I(:,:,3) == 41;
numBrownPixelsI = sum(BrownPixelsI(:));
BluePixelsI = I(:,:,1) == 0 & I(:,:,2) == 0 & I(:,:,3) == 255;
numBluePixelsI = sum(BluePixelsI(:));
CyanPixelsI = I(:,:,1) == 0 & I(:,:,2) == 255 & I(:,:,3) == 255;
numCyanPixelsI = sum(CyanPixelsI(:));
MagentaPixelsI = I(:,:,1) == 255 & I(:,:,2) == 0 & I(:,:,3) == 255;
numMagentaPixelsI = sum(MagentaPixelsI(:));
WhitePixelsI = I(:,:,1) == 255 & I(:,:,2) == 255 & I(:,:,3) == 255;
numWhitePixelsI = sum(WhitePixelsI(:));

채택된 답변

Jakob
Jakob 2020년 8월 28일
numYellowPixelsI= size(find((I(:,:,1) == 255 & I(:,:,2) == 255 & I(:,:,3) == 0)),1);
In this case there would be 7025 yellow Pixel. Hope this helps
  댓글 수: 1
Jakob
Jakob 2020년 8월 28일
[a,b] = find((I(:,:,1) == 255 & I(:,:,2) == 255 & I(:,:,3) == 0));
gives you the exact postion of each yellow Pixel

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by