我有一堆图像切片及其相应的蒙版。我一直在尝试使用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”):
对于可能是什么问题的任何想法和建议,我们都会感激不尽。
答案 0 :(得分: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)
我希望这会有所帮助。