Exporting Annotations

You can make use of RedBrick AI's Python SDK to export your annotations using a Python script.

Within the Python SDK, annotations are exported in two ways:

  1. The export_tasks function returns a Python object containing meta-data information and any vector annotations (measurements, landmarks, etc.). Please see the format of the object here.

  2. By default, segmentation data is written to your disk in NIfTI format. Segmentation data can also be exported in PNG or RT Struct by manipulating the parameters of the export_tasks function. Please view the detailed export_tasks reference here.

If you're attempting a one-time export or don't have intensive requirements for your export, the CLI also provides a simple and optimized workflow for exporting a Project's annotations.

Export Folder Structure

RedBrick AI exports annotations in a JSON structure, accompanied by NIfTI-1 masks for segmentations. All data will be exported within a folder named after your project_id, with the following structure:

project_id/
├── segmentations
│   ├── study01
│   │   └── series1.nii
│   └── study02
│       ├── series1.nii
│       └── series2.nii
└── tasks.json

The above structure is for a standard export (i.e. not semantic, not binary mask, etc.) and assumes no overlapping segmentations.

Segmentations Subdirectory

The segmentation directory will contain a single sub-directory for each task in your export. The sub-directories will be named after the task name. A single task (depending on whether it was single series or multi-series) can have one or more segmentations.

The individual segmentation files will be in NIfTI-1 format and be named after the user-defined series name. If no series name is provided on upload, RedBrick will assign a unique name. Corresponding meta-data ex. category names will be provided in tasks.json.


Code Examples

As always, you should first perform the standard RedBrick AI SDK setup to create a Project object.

project = redbrick.get_project(org_id, project_id, api_key)

With a new Project object created, you can export your Project's Tasks in various ways. Please see some common examples below.

Export All Tasks

The export_tasks() function exports segmentation files for all Ground Truth Tasks by default. To export All Tasks, set the only_ground_truth parameter to False.

annotations = project.export.export_tasks(only_ground_truth=False)

Export Only Ground Truth

You can export only the Tasks in Ground Truth, i.e., Tasks that have successfully made it through all Label and Review Stages.

gt_annotations = project.export.export_tasks(only_ground_truth=True)

Export Specific Tasks

Export selected Tasks by specifying Task IDs.

specific_annotations = project.export.export_tasks(task_id="...")

Generate an Audit Trail

An audit trail can be useful for regulators interested in your quality control processes, as well as for managing your internal QA processes.

Please see a detailed reference forget_task_events here.

First, perform the standard RedBrick AI SDK setup to create a Project object.

Audit Trail - All Tasks

If you'd like to generate an audit trail for all Tasks (not only those in the Ground Truth Stage), be sure to include the only_ground_truth=False parameter.

# Return an audit trail for all Tasks in all Stages
audit_trail = project.export.get_task_events(only_ground_truth=False)

Audit Trail - Ground Truth Tasks Only

Retrieve an audit trail for all Ground Truth Tasks. Please note that by default, get_task_events only returns audit information for Tasks in the Ground Truth Stage.

project = redbrick.get_project(org_id, project_id, api_key)

# Return an audit trail for all Tasks currently in the Ground Truth Stage
audit_trail = project.export.get_task_events()

The returned object will contain data similar to the code snippet below, where each entry will represent a single Task (uniquely identified by taskId). The events array contains all key events/actions performed on the Task, with events[0] being the first event.

[
  {
    "taskId": "...",
    "currentStageName": "Label",
    "events": [
      {
        "eventType": "TASK_CREATED",
        "createdAt": "...",
        "isGroundTruth": false,
        "createdBy": "..."
      },
      {
        "eventType": "TASK_ASSIGNED",
        "createdAt": "...",
        "assignee": "...",
        "stage": "Label"
      }
    ]
  }
]

Additional Capabilities

The following is a non-exhaustive list of other available functionalities when using the Export class. A full list of the capabilities of our Export class can be found here.

Last updated