count how many pixel has value 255 in an image

The image cameraman, how can we find how many pixel has value of 255? Please help me

 Accepted Answer

data=GrayImage==255;
total_pix=sum(data(:))

4 Comments

So, we change the image to gray and apply that function. Is it correct?
Tu, cameraman is already gray. I will write here another way to write it.
GrayImage = imread('cameraman.tif');
count = sum(GrayImage==255,'all');
% yet another way
% count = nnz(GraImage==255);
btw you will see the maximum value of cameraman is only 253 so the count is 0.
you can also peep counts from a histogram
histogram(GrayImage)
Thank you, I just use the cameraman as an example. Thank a lot

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 16 Feb 2022

Edited:

on 16 Feb 2022

Community Treasure Hunt

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

Start Hunting!