The picture attached is 256×256 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(:));
Best Answer