标记边界给定遮罩

标记边界给定遮罩

本文介绍了标记边界给定遮罩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆图像切片及其相应的蒙版.我一直在尝试使用 skimage.segmentation 库根据其切片的掩码在每个切片中标记该对象.

I have a volume of image slices and their according masks. I've been trying to use skimage.segmentation library to mark the object in mind for each slice according to its mask.

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()

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

Here's a sample image and mask slice:

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

However running the code results in given boundaries with black backgrounds.

我希望得到类似以下黄色boundAry的输出(忽略"CG"):

I am expecting an output like the following yellow boundAry (Ignore the 'CG'):

对于可能是什么问题的任何想法和建议,我们都会感激不尽.

Any thoughts and suggestions as to what might be the issue is appreciated.

推荐答案

尽管如此,我无法从您提供的数据中完全了解您正在尝试执行的操作,但是如果您只想在屏幕上显示遮罩,原始图片,这就是您可能想要做的:

Although, I couldn't understand fully from your provided data, that what you were trying to do, but if you just want the mask to be shown in the original image, this is what you may like to do:

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)

我希望这会有所帮助.

这篇关于标记边界给定遮罩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:50