73 views (last 30 days)

Show older comments

Star Strider
on 14 Aug 2017

Edited: Star Strider
on 14 Aug 2017

It is equivalent to prod(size(BI)), where ‘BI’ is your binary image.

Image Analyst
on 14 Aug 2017

If you want the number of rows and columns of the binary image, you can do this:

[rows, columns] = size(binaryImage);

If you want the number of pixels (sum total, no matter whether black or white), you can do this:

numPixels = row * columns;

or you can use numel():

numPixels = numel(binaryImage);

If you want the area of just the white/1/true pixels, then you can do

foregroundArea = sum(binaryImage(:)); % Result is in pixels.

backgroundArea = numel(binaryImage) - foregroundArea;

Hopefully one of those examples will give you what you want, because we're not 100% sure what you want.

Image Analyst
on 15 Aug 2019

No, you can find the area directly. See my attached spatial calibration demo.

Jan
on 14 Aug 2017

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

Start Hunting!