How to count number of red, blue and green pixels in image.
13 views (last 30 days)
Show older comments
k khaja on 8 Oct 2022
Commented: Walter Roberson on 8 Oct 2022
I woud like to know, how can I count number of red, blue and green pixels in image.
Thanks in advance
Walter Roberson on 8 Oct 2022
If RGB components are integers 0 to 255, then is [1 0 0] red? That is, the smallest change towards red away from black: does that count as red, or does it count as black? It has red component but not green or blue... under some definitions that would have to count as red.
Z = zeros(48, 64, 3, 'uint8');
r = randi(size(Z,1),1,1);
c = randi(size(Z,2),1,1);
Z(r, c, 1) = 1;
title('which is the Red pixel?')
fprintf('Red pixel is at x = %d y = %d\n', c, r);
Personally I cannot detect the red pixel until you get up to around 40 instead of 1
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!