Skip to content

Conversation

@vvihorev
Copy link
Contributor

Copy of the original PR #1082 by @Jo-Byr, to run our CI

Problem

The current nifti exporter creates one nifti file per slot and label, it would be useful to generate one multi-label nifti per slot.

Solution

This solution merges all generated nifti file into one, while maintaining the previous ones, with the suffix "Segments".

Modified nifti exporter to do the above.
Added unit test comparing produced multi-label nifti's array to a manually generated nifti

Changelog

Add multi-segment nifti export support

Jo-Byr added 3 commits July 4, 2025 16:47
Modify nifti exporter to create an additional nifti file that contains
all segments of the annotated volume
Fix pixel offset in anisotropic test data
Add sagittal and axial test data
Add test ensuring correct import of multi-label nifti file, by asserting
no error is produced in the process, and that the number of unique
values in the produced array is coherent with the nifti file
Copilot AI review requested due to automatic review settings July 24, 2025 14:28
@linear
Copy link

linear bot commented Jul 24, 2025

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements multi-segment NIfTI export functionality, allowing the exporter to generate a single multi-label NIfTI file per slot containing all segments, in addition to the existing individual files per label.

  • Adds support for creating multi-segment NIfTI files with "_Segments" suffix
  • Implements test coverage for the new multi-segment export functionality
  • Includes test data with Darwin JSON annotations and ground truth NIfTI files

Reviewed Changes

Copilot reviewed 6 out of 9 changed files in this pull request and generated 3 comments.

File Description
tests/darwin/importer/formats/import_nifti_test.py Adds test to verify multi-label NIfTI import processing
tests/darwin/exporter/formats/export_darwin_test.py Adds comprehensive test for multi-segment NIfTI export with ground truth comparison
tests/darwin/data/nifti/multi_segment/*/darwin.json Test data files containing Darwin JSON annotations for different anatomical planes
darwin/exporter/formats/nifti.py Core implementation adding multi-segment export logic and constants
Comments suppressed due to low confidence (2)

darwin/exporter/formats/nifti.py:62

  • The variable name 'multi_segments_label' is misleading as it contains an ID value, not a label. Consider renaming to 'MULTI_SEGMENTS_ID' or 'ALL_SEGMENTS_ID' and make it a constant.
multi_segments_label = "0"

darwin/exporter/formats/nifti.py:63

  • Variable should follow constant naming convention. Rename to 'MULTI_SEGMENTS_NAME' to indicate it's a module-level constant.
multi_segments_name = "Segments"

@vvihorev vvihorev merged commit 8d91c1f into master Jul 24, 2025
32 checks passed
@vvihorev vvihorev deleted the nifti-multi-segment branch July 24, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants