1

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:

image mask

However running the code results in given boundaries with black backgrounds. enter image description here

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

enter image description here

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

SamAtWork
  • 455
  • 5
  • 17

1 Answers1

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.

SamAtWork
  • 455
  • 5
  • 17
user2906838
  • 1,178
  • 9
  • 20