给定掩码标记边界

Marking boundary given mask

我有大量图像切片及其对应的蒙版。我一直在尝试使用 skimage.segmentation 库根据其掩码为每个切片标记要记住的对象。

import numpy as np
from skimage.segmentation import mark_boundaries
import matplotlib.pyplot as plt
def plot_marked_volume(marked_image_volume, mask):
   for slice in range(len(marked_image_volume)):
       if np.count_nonzero(mask[slice,:,:]):
           plt.figure(figsize=(10,10))
           edges_pz = mark_boundaries(marked_image_volume[slice,:,:], mask[slice].astype(np.int),
                                                color=(1,0,0), mode='thin')
           plt.imshow(edges_pz)
           plt.title('slice ' + str(slice))
           plt.show()

这是示例图像和蒙版切片:

但是 运行 代码会生成带有黑色背景的给定边界。

我期待像下面黄色边界的输出(忽略 'CG'):

如有任何关于可能是什么问题的想法和建议,我们将不胜感激。

尽管我无法从您提供的数据中完全理解您想要做什么,但如果您只想在原始图像中显示蒙版,这就是您可能喜欢做的事情:

fig, axarr = plt.subplots(1, 3, figsize=(15, 40))
axarr[0].axis('off')
axarr[1].axis('off')
axarr[2].axis('off')
imgPath = "download.jpeg"

image = cv2.imread(imgPath)
#Show original image of same shape as of edges_pz or mask. Arguments should be image not its path.

axarr[0].imshow(image)
#Show the maks or edges_pz in your case
axarr[1].imshow(edges_pz)

#Show the image with combined mask and the original image, the shape of both image and mask should be same. 
axarr[2].imshow(image)
axarr[2].imshow(edges_pz, alpha=0.4)

希望对您有所帮助。