Skip to content

ENH: Support genuine 4D (x,y,z,time) MINC images#6586

Open
gdevenyi wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
gdevenyi:enh-minc-4d-time
Open

ENH: Support genuine 4D (x,y,z,time) MINC images#6586
gdevenyi wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
gdevenyi:enh-minc-4d-time

Conversation

@gdevenyi

Copy link
Copy Markdown
Contributor

MINC volumes with a time dimension now map to a genuine itk::Image<T,4> instead of folding time into components; vector_dimension still maps to components. Fixes the time↔vector round-trip flip and the 3D-only write limit.

Design rationale

Mapping is now by MINC dimension class rather than component count:

  • MItime / MItfrequency (MI_DIMCLASS_TIME) → a 4th ITK dimension; tstepspacing[3], tstartorigin[3], orthogonal direction.
  • MIvector_dimension (MI_DIMCLASS_RECORD) → ITK components (deformation grids, DTI, RGB, tensors — unchanged).
  • MIxspace/MIyspace/MIzspace → spatial dims.

Apparent dimension order is [time, z, y, x, vector] (slowest→fastest), matching the Read()/Write() hyperslab arrays. SupportsDimension now allows dim < 5.

Behavior change: a MINC file with a time dimension previously read as VectorImage<T,3> (time as N components) and now reads as Image<T,4>. vector_dimension files are unchanged. itkMINCImageIOTest_4D was migrated from VectorImage<float,3> to Image<float,4>; the fixture dti_sample.mnc is a 32-frame time series.

Test results
  • ctest -R MINCImageIOTest — 119/119 pass (incl. migrated 4D test, multi-component vector round-trips).
  • ITKIOTransformMINC functional tests (itkIOTransformMINCTest, itkMINCTransformAdapterTest) — pass; deformation-grid path (Image<Vector<double,3>,3>vector_dimension) unaffected.
  • Added synthetic Image<float,4> round-trip asserting spacing[3]/origin[3] map to tstep/tstart.
AI assistance
  • Tool: Claude Code (Opus 4.8)
  • Role: root-cause analysis and implementation
  • Contribution: identified the component-count heuristic as the cause of the time↔vector flip; implemented the dimension-class mapping
  • All code reviewed and tested locally before committing

@gdevenyi

Copy link
Copy Markdown
Contributor Author

@vfonov could you review? This changes MINC time-dimension handling (now genuine 4D itk::Image<T,4>); vector_dimension mapping is unchanged.

@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:IO Issues affecting the IO module labels Jul 10, 2026
@gdevenyi gdevenyi force-pushed the enh-minc-4d-time branch 2 times, most recently from e8ba066 to e3e48cb Compare July 10, 2026 21:07
The MINC time dimension now maps to a 4th ITK dimension; the
vector_dimension maps to components. Component count no longer selects
the written dimension kind, so time and vector survive a round-trip.

Change-Id: I155561693ee98c5677b2dfa125fc9990e7721bb2
@gdevenyi gdevenyi marked this pull request as ready for review July 11, 2026 03:06
Copilot AI review requested due to automatic review settings July 11, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown

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 updates itk::MINCImageIO to treat MINC files with a true time dimension as genuine 4D ITK images (itk::Image<T,4>) instead of folding time into the component count, while keeping MINC vector_dimension mapped to ITK components. This resolves the time↔vector “flip” on round-trips and lifts the previous 3D-only write limitation to allow 4D (3 spatial + time) volumes.

Changes:

  • Read path: map MINC time (MI_DIMCLASS_TIME) to an additional ITK dimension (highest), and keep MINC vector_dimension mapped to ITK components.
  • Write path: always write ITK components as MINC vector_dimension, and write the 4th ITK dimension as MINC time (reject >4D).
  • Tests: migrate the existing “4D” MINC test to itk::Image<float,4> and add a synthetic 4D round-trip that asserts time origin/spacing preservation; add cleanup for the synthetic output.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Modules/IO/MINC/src/itkMINCImageIO.cxx Implements the dimension-class-based mapping for read/write, enabling genuine 4D time series and fixing time/vector ambiguity.
Modules/IO/MINC/include/itkMINCImageIO.h Updates SupportsDimension to allow up to 4D images (plus degenerate 0 case).
Modules/IO/MINC/test/itkMINCImageIOTest2.cxx Expands the dimension-support expectation to include 4D.
Modules/IO/MINC/test/itkMINCImageIOTest_4D.cxx Converts the test to scalar 4D images and adds a synthetic 4D time-geometry/value round-trip check.
Modules/IO/MINC/test/CMakeLists.txt Ensures the new synthetic MINC output is removed as a temporary test file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes MINC time handling to use a real ITK image dimension. The main changes are:

  • Allows MINC IO to report support for 4D images.
  • Maps MINC time/frequency dimensions to ITK dimension 3.
  • Keeps MINC vector_dimension mapped to image components.
  • Updates write-side dimension creation and ordering for 4D data.
  • Migrates the 4D test to itk::Image<float, 4> with a synthetic round-trip.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues were found in the changed code. The read and write dimension ordering is consistent for scalar, vector, and 4D time layouts, and the updated test includes the headers it uses and cleans up its synthetic output.

No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • The explicit high-value test plan for the MINC image IO suite executed and completed successfully with all targeted tests passing; no fallback or unrelated tests were run.
  • The run log shows that itkMINCImageIOTest_4D and itkMINCImageIOTest2 started and passed.
  • The final test summary reported 100% tests passed out of 119.
  • The test log was saved for review and verification.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Modules/IO/MINC/include/itkMINCImageIO.h Updates MINC dimension support from 3D to 4D.
Modules/IO/MINC/src/itkMINCImageIO.cxx Maps time to an ITK dimension and keeps vector data as components.
Modules/IO/MINC/test/CMakeLists.txt Adds cleanup for the synthetic 4D test output.
Modules/IO/MINC/test/itkMINCImageIOTest2.cxx Updates the supported-dimension expectation.
Modules/IO/MINC/test/itkMINCImageIOTest_4D.cxx Migrates the 4D test to itk::Image<float, 4> and adds time geometry checks.

Reviews (1): Last reviewed commit: "ENH: Support genuine 4D (x,y,z,time) MIN..." | Re-trigger Greptile

@vfonov

vfonov commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

It was done this way to handle DWI acquisitions. And something else, that i don't remember now.
What is the reason for this change?

@gdevenyi

Copy link
Copy Markdown
Contributor Author

It was done this way to handle DWI acquisitions. And something else, that i don't remember now. What is the reason for this change?

I was updating https://github.com/gdevenyi/minc-diff-labels to use SimpleITK so I can be agnostic to the filetypes and it fell over on the MINC file saving, so I went to investigate.

If you expand the design "Design rationale" section in the PR top you'll find this maintains the existing implementation for the example DWI tests included in the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:IO Issues affecting the IO module type:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants