用Matlab计算一幅二值图像中目标的面积(也就是像素数表示),如何计算?

图像是c
我用的是bwarea(c)函数,计算出的像素数是1760个
但是用 >>[l,num]=bwlabel(c);
>>stats=regionprops(l,'Area'); >> A=stats.Area;
计算出的是1710个,我想知道为什么两个计算结果不一样呢,差了50个像素呢,谢谢大家了?

第1个回答  2013-06-07
sum(c(:))试一下。我猜结果应该是1710.

你doc bwarea看一下,有下面这些话
total = bwarea(BW)

Description
total = bwarea(BW) estimates
the area of the objects in binary image BW. total is
a scalar whose value corresponds roughly to the total number of on pixels
in the image, ****but might not be exactly the same because different
patterns of pixels are weighted differently****.本回答被提问者和网友采纳