Visualizing 3D label maps from medical image segmentation like itksnap #2434
-
Hi PyVista community 👋 What is the best way to visualize 3D label maps as are often used in medical imaging to represent segmentation output or ground-truth? The label map is a 3D volume where value of each voxel uniquely identifies the underlying structure of interest (e.g. in the example below, 1 is the left atrium, 2, 3, 4, 5 are pulmonary arteries). The values are categorical (ints) but not necessarily contiguous, the value of the background is often 0. This is a simple solution I have for now: import pyvista as pv
label = pv.read("example_label.mha")
num_classes = 5
pl = pv.Plotter()
pl.add_mesh(
label.contour(),
opacity=(num_classes + 1) * [1],
clim=[0, num_classes],
cmap=plt.cm.get_cmap("viridis", num_classes + 1)
)
pl.view_zy()
pl.show() Using it, I observe that there is a thin hull (or halo effect) around each label (I presume this is from marching cubes generating multiple contours whenever a transition from 0 occurs). Without setting the opacity the pulmonary all is hidden under one surface of the same color: Is there a way to remove the hull and make the segments fully opaque like in ITKSnap for example? What would be the best way to show only some labels and ignore the rest and not have any of those hulls? Thresholding the label map per individually per class might work but becomes fairly slow when the number of classes grows. example_label.zip adapted from the Medical decathlon (http://medicaldecathlon.com/) CC-SA |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Have you tried |
Beta Was this translation helpful? Give feedback.
Have you tried
image_threshold
or only triedthreshold
? I think the former should be a lot faster than the latter since it won't change the mesh topology and it will allow you to generate a binary image for each label that you can then visualize separately however you like.