Skip to content

Feature/itk volume conversions#394

Draft
mccle wants to merge 26 commits into
v0.28.0devfrom
feature/itk_volume_conversions
Draft

Feature/itk volume conversions#394
mccle wants to merge 26 commits into
v0.28.0devfrom
feature/itk_volume_conversions

Conversation

@mccle
Copy link
Copy Markdown
Collaborator

@mccle mccle commented Feb 20, 2026

Depends on #387 for optional dependency importing.

Introduces 'to' and 'from' methods for the itk and SimpleITK libraries on the highdicom.Volume class.

Comment thread src/highdicom/volume.py Outdated
Comment thread src/highdicom/volume.py Outdated
Comment thread src/highdicom/volume.py
SimpleITK.Image:
Image constructed from the Volume.

"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be nice to add some more information to the docstring to help users:

  • SITK (itk) uses the same LPS convention as highdicom
  • The returned volume is transposed to hide the difference in row major / column major orderings between the two formats transparent from the user

Comment thread src/highdicom/volume.py
if array.min() >= f64.min and array.max() <= f64.max:
warnings.warn(
'SimpleITK does not support float128 data.'
' Safely recasting to float64.'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not really safe as it still involves a loss of precision (I think...)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also I think "casting" would be preferred to "recasting"

Comment thread .github/workflows/run_unit_tests.yml Outdated
Comment thread tests/test_sitk.py

else:
sitk_roundtrip = Volume.from_sitk(volume.to_sitk())
assert sitk_roundtrip.dtype == volume.dtype
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it be a good idea to test for equality of the arrays here? (except in cases where casting may lead to small differences)

Comment thread tests/test_sitk.py
'zip_url,nifti_url',
[
(
'https://github.com/neurolabusc/dcm_qa_mprage/raw/refs/heads/main/In/2_t1_mp2rage_sag_p3_32.zip', # noqa: E501
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suggest that is might be neater to factor out "https://github.com/neurolabusc/dcm_qa_mprage/raw/refs/heads/main"

Co-authored-by: Chris Bridge <chrisbridge44@googlemail.com>
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.

2 participants