find area for ROI

16 views (last 30 days)
Max Bernstein
Max Bernstein on 20 Oct 2011
Hello,
I dont have the image processing toolbox and I'm trying to find an area of an image. I have been able to reduced it to bw double array but I'm having trouble trying to calculate the area. Should I calculate the area for 1 pixel and multiply it by the number of black pixels?

Answers (2)

Walter Roberson
Walter Roberson on 20 Oct 2011
ROI usually use white (1) for a selected pixel, and black (0) for one that is not selected.
ROIarea = sum(sum(YouImage.*ROI))
Or simply regionprops(ROI) and look at the 'Area' field.
Yes you would want to multiply by area of a pixel. But unless you have some kind of absolute measurement, or you know your pixels are non-square, a pixel would normally be assumed to have an area of 1.

Image Analyst
Image Analyst on 21 Oct 2011
Hmm... Usually BW in the MATLAB examples is a logical image (true or false), not a double. Anyway I'd do it like Walter said because I prefer pixel-based measurements. However just to let you know there is an alternate definition of area that bwarea uses. Run this code to see:
m = [0 1; 1 1]
numberOfPixels = sum(m(:))
bwAreaMeasurement = bwarea(m)
x = [2 2 1];
y = [1 2 2];
poly_area = polyarea(x, y)
m =
0 1
1 1
numberOfPixels =
3
bwAreaMeasurement =
3.1250
poly_area =
0.5000
Tell me, what do you think the area is? is it 3 pixels? Or is it 0.5, which it is if you go from center of pixel to center of pixel and along the diagonal? Or is it 3.1250? Is there a right answer, or is there no right answer, or multiple answers?
regionprops() returns the number of pixels, 3 in this example.
  4 Comments
Image Analyst
Image Analyst on 21 Oct 2011
By the way, by your definition this array
0 0 0 0 0
0 1 1 1 0
0 0 0 0 0
would give the object an area of zero.
Walter Roberson
Walter Roberson on 21 Oct 2011
@IA:
I think you missed the "and connect to the corner for ending pixels". It sounds like Max would want it to be measured as if
|>----<|
where the > and > should have 45 degree angles and each "-" is a half-width. That would, I figure, give a total area of sqrt(2)
"Connect to the corners" is, though, ambiguous since it doesn't really say which point to start the connection from.
@Max:
Your algorithm confuses distance with area. For example it leaves confused a case such as looking near the diagonal on
0 1
1 ?
as it does not take in to account whether the ? is occupied or not in determining an area contribution.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!