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

7 ビュー (過去 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 Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by