【问题标题】:Marking boundary given mask标记边界给定掩码
【发布时间】:2019-01-20 07:25:28
【问题描述】:

我有大量图像切片及其相应的蒙版。我一直在尝试使用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()

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

但是,运行代码会导致给定的边界带有黑色背景。

我期待如下黄色 boundAry 的输出(忽略“CG”):

感谢您对可能出现的问题提出任何想法和建议。

【问题讨论】:

  • 您的预期结果是什么?
  • @user2906838 添加在帖子末尾:)
  • 能否请您分享您的输入数据以调用该方法,以便我可以重现它,您只需替换原始绘制maks的像素值。
  • @user2906838 请在此处找到卷:transfernow.net/4195b0b9cw4n

标签: python numpy image-segmentation scikit-image


【解决方案1】:

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

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)

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 2019-12-27
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 2020-03-12
    相关资源
    最近更新 更多