图像分割:如何表示检测区域的“分散”?

问题描述 投票:0回答:1

我正在使用 python 3.9 执行图像分割(图像 => 灰度图像 => 手动灰度阈值 => 从 [0-255] 到 [0-1] 图像的转换)。在分割结束时,我获得了一个二值图像,白色蒙版包含我想用值“1”突出显示的区域(图像的其余部分为“0”):

Image 1 - areas dispersed

现在我可以使用“CV2”从此掩码中提取一些属性,例如检测区域的面积:

cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)

areas=[]
aspectRatios=[]
for (i, c) in enumerate(cnts):
    # compute the area of the contour along with the bounding box
    # to compute the aspect ratio
    area = cv2.contourArea(c)
    (x, y, w, h) = cv2.boundingRect(c)

    # compute the aspect ratio of the contour, which is simply the width
    # divided by the height of the bounding box
    aspectRatio = w / float(h)

        
    areas=np.append(areas,area)
    aspectRatios=np.append(aspectRatios,aspectRatio)

我有不同种类的图像,正如您所见,有时检测到的区域非常“本地化”:

Image 2 - areas more localized

我希望能够表示图像上检测到的区域的“分散”(不确定该术语)。我有多个图像,我想要一个值来表示它们是在一个地方更本地化还是分散在各处。我没有找到任何价值代表,但我认为这可能是可行的?

python-3.x opencv image-processing image-segmentation
1个回答
0
投票

您可以计算一个圆与所有其他圆之间的平均距离。如果你对所有圆圈都这样做,并计算这些平均值的平均值,它应该给你一个更小的值,圆圈越密集。但这只是一个建议,不确定它是否有效。

© www.soinside.com 2019 - 2024. All rights reserved.