pyvista.examples.downloads.download_whole_body_ct_female

pyvista.examples.downloads.download_whole_body_ct_female#

download_whole_body_ct_female(load=True, *, high_resolution=False)[source]#

Download a CT image of a female subject with 117 segmented anatomic structures.

This dataset is subject 's1380' from the TotalSegmentator dataset, version 2.0.1, available from zenodo. See the original paper for details:

Jakob Wasserthal et al., “TotalSegmentator: Robust Segmentation of 104 Anatomic Structures in CT Images,” Radiology, Jul. 2023, doi: https://doi.org/10.1148/ryai.230024.

The dataset is loaded as a MultiBlock with three blocks:

  • 'ct': ImageData with CT data.

  • 'segmentations': MultiBlock with 117 ImageData blocks, each containing a binary segmentation label. The blocks are named by their anatomic structure (e.g. 'heart') and are sorted alphabetically. See the examples below for a complete list label names.

  • 'label_map': ImageData with a label map array. The label map is an alternative representation of the segmentation where the masks are combined into a single scalar array.

    Note

    The label map is not part of the original data source.

Licensed under Creative Commons Attribution 4.0 International.

Added in version 0.45: Three dictionaries are now included with the dataset’s user_dict to map label names to ids and colors:

  • 'names_to_colors' : maps segment names to 8-bit RGB colors.

  • 'names_to_ids' : maps segment names to integer ids used by the label map.

  • 'ids_to_colors' : maps label ids to colors.

The label ids are the ids used by the included label map.

Changed in version 0.45: A downsampled version of this dataset with dimensions (160, 160, 273) is now returned. Previously, a high-resolution version with dimensions (320, 320, 547) was returned. Use high_resolution=True for the high-resolution version.

Parameters:
loadbool, default: True

Load the dataset after downloading it when True. Set this to False and only the filename will be returned.

high_resolutionbool, default: False

Set this to True to return a high-resolution version of this dataset. By default, a resampled version with a 0.5 sampling rate is returned.

Added in version 0.45.

Returns:
pyvista.MultiBlock or str

DataSet or filename depending on load.

Examples

Load the dataset.

>>> from pyvista import examples
>>> import pyvista as pv
>>> dataset = examples.download_whole_body_ct_female()

Get the names of the dataset’s blocks.

>>> dataset.keys()
['ct', 'segmentations', 'label_map']

Get the CT image.

>>> ct_image = dataset['ct']
>>> ct_image
ImageData (...)
  N Cells:      6825870
  N Points:     6937600
  X Bounds:     7.500e-01, 4.778e+02
  Y Bounds:     7.500e-01, 4.778e+02
  Z Bounds:     7.528e-01, 8.122e+02
  Dimensions:   160, 160, 271
  Spacing:      3.000e+00, 3.000e+00, 3.006e+00
  N Arrays:     1

Get the segmentation label names and show the first three.

>>> segmentations = dataset['segmentations']
>>> label_names = segmentations.keys()
>>> label_names[:3]
['adrenal_gland_left', 'adrenal_gland_right', 'aorta']

Get the label map and show its data range.

>>> label_map = dataset['label_map']
>>> label_map.get_data_range()
(np.uint8(0), np.uint8(117))

Show the 'names_to_colors' dictionary with RGB colors for each segment.

>>> dataset.user_dict['names_to_colors']  

Show the 'names_to_ids' dictionary with a mapping from segment names to segment ids.

>>> dataset.user_dict['names_to_ids']  

Create a surface mesh of the segmentation labels.

>>> labels_mesh = label_map.contour_labels()

Color the surface using color_labels(). Use the 'ids_to_colors' dictionary included with the dataset to map the colors.

>>> colored_mesh = labels_mesh.color_labels(
...     colors=dataset.user_dict['ids_to_colors']
... )

Plot the CT image and segmentation labels together.

>>> pl = pv.Plotter()
>>> _ = pl.add_volume(
...     ct_image,
...     cmap='bone',
...     opacity='sigmoid_7',
...     show_scalar_bar=False,
... )
>>> _ = pl.add_mesh(colored_mesh)
>>> pl.view_zx()
>>> pl.camera.up = (0, 0, 1)
>>> pl.camera.zoom(1.3)
>>> pl.show()
../../../_images/pyvista-examples-downloads-download_whole_body_ct_female-1_00_00.png

See also

Visualize Anatomical Groups

Additional examples using this dataset.

Whole Body Ct Female Dataset

See this dataset in the Dataset Gallery for more info.

Whole Body Ct Male Dataset

Similar dataset of a male subject.

Medical Datasets

Browse other medical datasets.

Volume With Segmentation Mask

See additional examples using this dataset.