如何检查两个图像中标记的区域是否相同?

How to check if the labelled regions are the same in two images?

所以我的想法是为分割任务写一个准确率和召回率指标。分割任务的常用指标通过按像素比较地面实况和预测掩码来计算此指标。我想计算的方式是,即使预测了ground truth中物体的某些部分,那么整个物体os就认为是真实的positive。

我目前处理问题的方式是计算逻辑和基本事实以及预测的掩码。然后使用 skimage.measure.label 为每个 blob 分配一个唯一的 id。然后我通过使用

and_mask = np.logical_and(gt, pred)
labels1 = measure.label(gt, neighbors=8, background=0)
labels2 = measure.label(and_mask, neighbors=8, background=0)

这适用于 most 种情况,但如果我预测的 blob 掩码分为两部分预测,那么对其执行 logical_and 会得到一个额外的对象。这搞砸了我的指标计算。

有没有办法避免这种情况,还有更简单的方法吗?

细分评估是一个活跃的研究领域,但一些指标已经存在。我最喜欢的是信息的变化。一个关键特征是它不依赖于每个图像中的标签数量或图像之间的标签分配。这还没有在 scikit-image 中,但我们有一个拉取请求打开以包含它:

https://github.com/scikit-image/scikit-image/pull/3354

您可以查看该分支或从那里复制实现,或者稍等一下,希望它会出现在下一个版本中!

我设法解决了。我使用 measure.label 来获取各个掩码,然后使用 gt 掩码计算 iou。这就是我想要的

    labels1 = measure.label(gt, neighbors=8, background=0)
        # loop over the unique components
        for label in np.unique(labels1):
            # if this is the background label, ignore it
            if label == 0:
                continue
            # otherwise, construct the label mask 
            labelMask1 = np.zeros(pred.shape, dtype="uint8")
            labelMask1[labels1 == label] = 255
            c, counts1 = np.unique(np.logical_and(labelMask1, pred, 
             where=255), return_counts=True)
            inter = np.sum(np.logical_and(labelMask1, pred, where=255)) / 
            np.sum(np.logical_or(labelMask1, pred, where=255))

如果有人感兴趣,这里是粗略的算法。