find area for ROI

14 次查看(过去 30 天)
Max Bernstein
Max Bernstein 2011-10-20
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?

回答(2 个)

Walter Roberson
Walter Roberson 2011-10-20
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 2011-10-21
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 个评论
Image Analyst
Image Analyst 2011-10-21
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 2011-10-21
@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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by