Skip to content

Commit

Permalink
Add info on segmentation file formats
Browse files Browse the repository at this point in the history
  • Loading branch information
lassoan committed Sep 6, 2024
1 parent 30da197 commit 3049f12
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ print("First segment info:\n" + json.dumps(segment0, sort_keys=False, indent=4))

#### Extract segments by terminology

Example for getting a 3D NRRD file that has label values assigned based on [standard terminology codes](UsingStandardTerminology.md).
Example for getting a 3D [NRRD](SegmentationFileFormat.md) file that has label values assigned based on [standard terminology codes](UsingStandardTerminology.md).
Terminology is a `dict` that must specify `category` and `type` codes and may optionally also specify `typeModifier`, `anatomicRegion`, and `anatomicRegionModifier`. Each code is specifed by a triplet of "coding scheme designator", "code value", "code meaning" in a list.

Coding scheme designator is typically `SCT` (SNOMED-CT) for clinical images. You can find codes in the [SNOMED-CT browser](https://browser.ihtsdotools.org/). When code exists for "entire X" and "structure of X" then always use the "structure" code ("entire" code has a very strict meaning that is rarely applicable in practice).
Expand Down
51 changes: 51 additions & 0 deletions SegmentationFileFormat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# File formats for image segmentations

## Commonly used file formats

### DICOM

DICOM allows saving image segmentations along with rich, structured metadata in a standard, very well documented way in [DICOM Segmentation](https://dicom.nema.org/dicom/2013/output/chtml/part03/sect_A.51.html).

Pro:
- Compatibility with clinical software: DICOM is universally supported by all clinical imaging softare, DICOM Segmentation is not very widely supported but its adoption is increasing.
- Long-term stability: DICOM format is changed very slowly and carefully
- Rich, structured metadata storage, all defined carefully in the DICOM standard

Con:
- Standard is very large, complex
- Low performance: size of segmentation metadata may be huge (magnitudes larger than the segmentation data itself), encoding and decoding can be magnitudes slower compared to simple 3D image formats

### NRRD

Very simple and efficient file format for storing multi-dimensional images. 3D Slicer and related software established convention for [storing segmentation metadata](https://slicer.readthedocs.io/en/latest/developer_guide/modules/segmentations.html#segmentation-labelmap-file-format-seg-nrrd) (commonly referred to as `.seg.nrrd` files).

Pro:
- Very simple
- Compatibility with research software and toolkits: most libraries and research application support this file format
- Common convention exists for storing essential metadata
- File header is human-readable: easily readable, modifiable with any text editor

Con:
- Not compatible with clinical software
- Common conventions for metadata storage only include essential metadata (not as rich or structured as DICOM)

### NIFTI

Very limited, yet complex and ambiguous file format. Unfortunately, for historical reasons, it is commonly used in medical image computing.

Pro:
- Compatibility with research software and toolkits: most libraries and research application support this file format
- Somewhat simple: simpler than DICOM, but much more complex than NRRD
- It can store some neuroimaging-specific metadata in a standard way: this makes the file format beneficial for neuroimaging

Con:
- Orientation definition in NIFTI files can be ambiguous: there are multiple ways to define orientation, they can be both present, and contain contradicting information. Various softare will interpret these ambiguous files differently. See for example these discussions: [1](https://www.openfmri.org/dataset-orientation-issues/), [2](https://discourse.slicer.org/t/orientation-origin/23365), [3](https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/3283)
- Not compatible with clinical software
- Common convention for storing essential metadata does not exist
- File header is not human-readable: you cannot use a text editor/viewer to see the actual file header but you always have to rely on a parser to give you an interpretation of the file header

## Recommended file formats

- DICOM format is recommended for long-term archival due to compatibility and stability of the file format and the ability to encode rich, structured metadata in a well-defined manner.
- NRRD file format is recommended for local storage and data exchange, due to its simplicity, efficiency, and non-ambiguity.
- NIFTI format usage may be justified for neuroimaging, as many neuroimaging pipelines only support this format.

0 comments on commit 3049f12

Please sign in to comment.