# segmentation labels are siplayed incorrectly in python

**URL:** <https://discourse.slicer.org/t/segmentation-labels-are-siplayed-incorrectly-in-python/31369>\
**Category:** Support\
**Tags:** segmentation, python\
**Created:** [August 26, 2023, 2:13am UTC](https://discourse.slicer.org/t/segmentation-labels-are-siplayed-incorrectly-in-python/31369 "2023-08-26T02:13:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sepehr](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@sepehr](https://discourse.slicer.org/u/sepehr)\
**Post date:** [August 26, 2023, 2:13am UTC](https://discourse.slicer.org/t/segmentation-labels-are-siplayed-incorrectly-in-python/31369/1 "2023-08-26T02:13:52Z")

</div>

hello, I am trying to segment the lung (label 1,purple) and lung opacities (label 2,yellow) from ct scan images. after I finish segmenting in the slicer I save the labels as a nifti file. when I try to visualize the segmented areas in jupyter notebook label 1 and label 2 segments are mixed up. I mean that for some of the slices label 1 is displayed as purple and for others label 2 is displayed as purple. I run the following code in jupyter:

> Blockquote  
> data = nib.load(sample\_path)  
> label = nib.load(sample\_path\_label)

ct = data.get\_fdata()  
mask = label.get\_fdata().astype(int)

fig = plt.figure()  
camera = Camera(fig) # Create the camera object from celluloid

for i in range(ct.shape[2]): # Axial view  
plt.imshow(ct[:,:,i], cmap=“bone”)  
mask\_ = np.ma.masked\_where(mask[:,:,i]==0, mask[:,:,i])  
plt.imshow(mask\_, alpha=0.5)  
# plt.axis(“off”)  
camera.snap() # Store the current slice  
plt.tight\_layout()  
animation = camera.animate() # Create the animation

> Blockquote
