MATLAB: How to calculate the total white dots/ white region in this image

image processingImage Processing ToolboxMATLAB

hi, i'm beginner of matlab. Please show me the ways to calculate the total white pixel/regions that appear on this image..thanks http://imageshack.us/photo/my-images/841/result2cars.jpg/ http://img841.imageshack.us/img841/810/result2cars.jpg

Best Answer

To read in the image, use
M = imread('result2cars.jpg');
Because your image is a grayscale image, M is just a matrix. Each entry corresponds to one pixel. The entries are integers from 0 (black) to 255 (white). To calculate the number of completely white pixels, use
sum(M(:) == 255)
If you accept very light gray as white as well, use
sum(M(:) > t)
where t sets the white tolerance. For example, using t = 128 would count all pixels who is brighter than 50% gray as being white.
Related Question