MATLAB: How to compute number of pixels in images

duplicate posthomeworkImage Processing Toolboxpixel count

Dear sir I have one ground truth image(image 1) and other segmented image(image 2). I want to compute the number of pixel for white area for image 1 and number of pixel for red area in image 2. and then want to compute the difference of pixels.

Best Answer

Because a different person asked this very same question with the very same image, and Walter answered it here I'm thinking it's homework. I've tagged it as such.