0

我创建了一个具有随机像素组的图像:

img=ones(100,100)
numRandom = 505;
linearIndices = ceil(numel(img) * rand(1, numRandom));
img(linearIndices) = 0;
imshow(img)`

然后我将此图像转换为二进制并找到每组像素的面积:

regionprops(L, 'Area');

我还需要每组的周长。不幸的是,regionprops没有给我正确的结果(例如,如果有一个像素,则函数返回 0 而不是 4),所以我认为最好找到每组的相邻像素数(这样对于只有一个像素,答案将是 4)。如果该组位于图像的边界上,则也应将其考虑在内。

任何人都可以给我一个关于如何做到这一点的提示吗?

4

1 回答 1

1

Perimeter and regionprops is not what you need then, or find all these single pixels using regionprops(L, 'Area')==1 and set their perimeter to 4....

From Matlab documentation:

Perimeter — is the distance around the boundary of the region. regionprops computes the perimeter by calculating the distance between each adjoining pair of pixels around the border of the region. If the image contains discontiguous regions, regionprops returns unexpected results. The following figure shows the pixels included in the perimeter calculation for this object.

enter image description here

From this image you can see that the edge pixels are counted only once, not twice.

于 2013-07-23T16:59:57.570 回答