How do I count the number of all color pixels of different shades in the image attached?
5 次查看(过去 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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/352790/image.png)
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(:));
0 个评论
采纳的回答
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
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 Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!