MATLAB: With the grayscale image 150*100 how should I find out the number of text pixels(black) and background pixel (white)count I have used histogram but I can’t accurately predict the pixel count

pixel count

I have converted that gray block into binary and I have found out the pixel count.is there is any other method

Best Answer

Convert image into binary (suppose bw_image);
white_pixels_count=sum(bw_image(:));
black_pixel_count=(num_of_rows*num_of_col-white_pixels_count);
Another way-
num_pixels=numel(bw_image);
white_pixels_count=sum(bw_image(:));
black_pixel_count=(num_pixels-white_pixels_count);