2 views (last 30 days)

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
on 28 Aug 2020

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

Jakob
on 28 Aug 2020

[a,b] = find((I(:,:,1) == 255 & I(:,:,2) == 255 & I(:,:,3) == 0));

gives you the exact postion of each yellow Pixel

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

Start Hunting!
## 0 Comments

Sign in to comment.