MATLAB Answers


how to find the area

Asked by andhavarapu lokesh on 30 Dec 2016
Latest activity Commented on by Star Strider
on 30 Dec 2016
iam trying to find the area of circular ring which is short axis image of myocardial spect image where i want to find the volume of the white area can any one tell how to find the area what happens if we use bwarea command in matlab


Sign in to comment.

3 Answers

Image Analyst
Image Analyst 님의 답변 30 Dec 2016

bwarea() does NOT give the same area as a simple count of pixels, like sum() and regionprops() give you. It weights the edge pixels according to their neighbors, so like an edge slanted at 45 degrees might give half a pixel instead of a full pixel. There are different weights for different edge orientations. The bwarea documentation explains it all.
bwarea estimates the area of all of the on pixels in an image by summing the areas of each pixel in the image. The area of an individual pixel is determined by looking at its 2-by-2 neighborhood. There are six different patterns, each representing a different area:
  • Patterns with zero on pixels (area = 0)
  • Patterns with one on pixel (area = 1/4)
  • Patterns with two adjacent on pixels (area = 1/2)
  • Patterns with two diagonal on pixels (area = 3/4)
  • Patterns with three on pixels (area = 7/8)
  • Patterns with all four on pixels (area = 1)
Keep in mind that each pixel is part of four different 2-by-2 neighborhoods. This means, for example, that a single on pixel surrounded by off pixels has a total area of 1.
You have to decide if you want that or if you want a simple count of pixels.

  1 Comment

i want to find the volume for that i need area means what should i use please tell iam not familiar

Sign in to comment.

John D'Errico
John D'Errico 님의 답변 30 Dec 2016
John D'Errico 님이 편집함. 30 Dec 2016

Why not apply common sense? Count the number of white pixels. If you have some tiny amount of white pixels that are not connected to the main region of interest, then remove them first.
Since this is a black and white image, then 1 is white, 0 is black.
Since each pixel has an "area" of 1, then the sum is just the area you want.

  1 Comment

sir bwarea means sum of counts both are same or not

Sign in to comment.

Star Strider
Star Strider 님의 답변 30 Dec 2016

Your ‘.png’ image may be ‘binarised’, but it contains 3 channels. Choose one of them to use with bwarea:
[Img,Map] = imread('andhavarapu lokesh Capture9.png');
MyocardArea = bwarea(Img(:,:,1));
for k1 = 1:3
MyocardArea =


will the bwarea give the area of white pixels or total are including black pixels also
The bwarea function calculates the area of each pixel in a 2-by-2 neighborhood, according to the documentation.
If you just want the numbers of white and black pixels with a threshold of 1 for your image, see if this does what you want:
Imgv = reshape(Img(:,:,1), [], 1);
Black_pxl = sum(Imgv == 0)
White_pxl = numel(Imgv)-Black_pxl
MyocardArea = bwarea(Img(:,:,1))
Black_pxl =
White_pxl =
MyocardArea =
This is a rather simple way of calculating it, but may give you what you want.

Sign in to comment.