githubEdit

Volumes (DICOM)

Introduction

In this tutorial we will focus on working with volumes using Supervisely SDK.

You will learn how to:

πŸ“— Everything you need to reproduce this tutorial is on GitHubarrow-up-right: source code and demo data.

How to debug this tutorial

Step 1. Prepare ~/supervisely.env file with credentials. Learn more here.

Step 2. Clone repositoryarrow-up-right with source code and demo data and create Virtual Environmentarrow-up-right.

Step 3. Open repository directory in Visual Studio Code.

Step 4. Change workspace ID in local.env file by copying the ID from the context menu of the workspace.

Step 5. Download sample volumesarrow-up-right

Step 6. Place downloaded files in the project structure as shown below:

Step 7. Start debugging src/main.py.

Import libraries

Init API client

First, we load environment variables with credentials and init API for communicating with Supervisely Instance.

Get variables from environment

In this tutorial, you will need an workspace ID that you can get from environment variables. Learn more here

Create new project and dataset

Create new project with ProjectType.VOLUMES type.

Source code:

Output:

Create new dataset.

Source code:

Output:

Upload volumes from local directory to Supervisely

Upload NRRD format volume

Source code:

Output:

Upload volume as NumPy array

Source code:

Output:

Upload DICOM series from local directory

Inspect you local directory and collect all dicom series.

Source code:

Upload DICOM series from local directory to Supervisely platform.

Source code:

Set anonymize=True if you want to anonymize DICOM series and hide PatientID and PatientName fields.

Output:

Upload list of volumes from local directory

Source code:

Output:

Now you can explore and label it in Supervisely labeling toolarrow-up-right:

Get volume info from Supervisely

Get list of volumes infos from current dataset

Source code:

Output:

Get single volume info by id

Source code:

Output:

Get single volume info by name

Source code:

Output:

Download volume from Supervisely to local directory

Source code:

Output:

Get volume slices from local directory

Read NRRD file from local directory

Read NRRD file from local directory and get meta and volume (as NumPy array).

Source code:

Output:

Get slices from volume

Get slices from current volume. In this example we will get sagittal slices.

Source code:

Output:

Download slice from Supervisely

Download slice as NumPy from Supervisely by ID

Source code:

Output:

Save slice to local directory

βœ… There is a built-in function supervisely.image.write which reads file extension from path and saves image (slice) with the desired format in local directory.

Example:

Save slice as NRRD

Recommended way to save slice as NRRD file to preserve image quality (pixel depth)

Source code:

Save slice as JPG

Source code:

Note:

In case you save slice using nrrd library, it is recommendedarrow-up-right to use C-order indexing.

Last updated

Was this helpful?