python 如何在只有边框的图像上显示对象的叠加层?

How to show the overlay of an object on an image with only borders in python?

我在一篇论文中看到了在图像上叠加结果的非常好的表示,并尝试对我的数据采用类似的方法。这里的ground truth是用红色边界线覆盖的对象,分割结果是绿色。

我有 3 张图像:MRI、地面实况 (gt) 和从算法 (res) 获得的结果。 python中这种类似表示的代码应该怎么写?或者,如果有任何免费代码可供使用,请在此处分享。 谢谢

如果 ground-truth 和 res 是二维蒙版,您可以从灰度图像创建 RGB 图像并更改 res 指示的像素颜色。下面是一个使用 Canny 边缘检测器在 sample 图像上突出显示边缘的示例:

import cv2
from matplotlib import pyplot as plt

img = cv2.imread('brain.png',0)
edges = cv2.Canny(img,50,200)   # canny edge detector

img = cv2.merge((img,img,img))  # creat RGB image from grayscale
img2 = img.copy()
img2[edges == 255] = [255, 0, 0]  # turn edges to red

plt.subplot(121),plt.imshow(img)
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(img2)
plt.title('Edge Highlighted'), plt.xticks([]), plt.yticks([])

plt.show()

假设ground truth是一个二进制分割掩码, 这个 skimage find contour 应该可以。可能会找到多个等高线,您可以选择只绘制其中一个。为参数 'level' 设置不同的值以从多类分割蒙版中提取轮廓。