MATLAB: Hello everyone, how do i count the white pixels of a image after setting the threshold

pizels

% Extract the channel green.
img = imread('DSC_0315.JPG');
green = img;
subplot(2,2,1);imshow(img);
green(:,:,1:2:3)=0;
subplot(2,2,2);imshow(green);
title ('Green channel');
%%convert to greyscale
imgray1 = rgb2gray(green);
subplot(2,2,3);imshow(imgray1);
title ('Grayscale');
%%Thresholding
imA =imgray1>66;
figure;
imshow(imA);

Best Answer

I'd use the nnz (number of non-zeros) function:
imA =imgray1>66;
numPixels = nnz(imA);
- Sebastian