Marking boundary given mask

别来无恙 提交于 2021-02-08 09:32:28

问题


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.

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.


回答1:


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)

I hope this helps.



来源:https://stackoverflow.com/questions/51824455/marking-boundary-given-mask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!