Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5023720
Add import_optional_dependency util function
mccle Jan 8, 2026
c5f7398
Update optional import function.
mccle Jan 23, 2026
feef10b
Reformat code
mccle Jan 23, 2026
bc41ecf
Add module version compatibility check.
mccle Feb 5, 2026
ce4998a
Move version incompatibility error raise location and update error me…
mccle Feb 5, 2026
5c5e952
Update src/highdicom/utils.py
mccle Feb 19, 2026
1ce1bc7
Update src/highdicom/utils.py
mccle Feb 19, 2026
bdd3639
Update src/highdicom/utils.py
mccle Feb 19, 2026
b4cd240
Update src/highdicom/utils.py
mccle Feb 19, 2026
36a8fb5
Update src/highdicom/utils.py
mccle Feb 19, 2026
7ff4a13
Move to new utils file
mccle Feb 20, 2026
efb70aa
Add packaging to requirements
mccle Feb 20, 2026
1232204
add itk and sitk conversions
mccle Feb 20, 2026
9f9a7bb
Add frame_of_reference_uid and coordinate_system arguments; update do…
mccle Apr 17, 2026
ce79c6e
sync with v0.28.0dev
mccle Apr 17, 2026
b6b7d97
remove channel argument
mccle Apr 17, 2026
68d17d1
add noqa to work with flake8
mccle Apr 17, 2026
301c730
update type hints, minor tweaks to bool retyping
mccle Apr 27, 2026
edb9ac4
sync changes
mccle May 6, 2026
6094f87
flake8
mccle May 6, 2026
dfaba15
Add tests for sitk
mccle May 6, 2026
c616590
flake8
mccle May 6, 2026
ad3fbcd
skip sitk test on failed import
mccle May 6, 2026
60f2000
fix url syntax
mccle May 6, 2026
02b65fc
Fix itk conversion and add tests
mccle May 7, 2026
c3bfb69
Update .github/workflows/run_unit_tests.yml
mccle May 7, 2026
f72e251
Replace common url elements
mccle May 8, 2026
0bbbca7
Update docstrings and error messages
mccle May 15, 2026
8e8802f
Update volume docs file
mccle May 15, 2026
915f086
Update dtype tests with array equality and random values
mccle May 15, 2026
20c207e
Apply suggestion from @CPBridge
mccle May 15, 2026
d6a0d5f
Reorganize and update docs files
mccle May 15, 2026
d8acf67
Update docstrings
mccle May 15, 2026
fe87e09
Fix multichannel check and add tests
mccle May 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# and the likelihood of 3.12-specific bugs is considered low at this
# stage
python-version: ["3.10", "3.11", "3.13", "3.14"]
dependencies: [".", "'.[libjpeg]'"]
dependencies: [".", "'.[libjpeg,itk,sitk]'"]

env:
# Set this otherwise coverage on python 3.12 is absurdly slow
Expand Down
1 change: 1 addition & 0 deletions docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ parts of the library.
volume
coding
remote
other_libraries
49 changes: 49 additions & 0 deletions docs/itk_lib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. _itk_lib:

ITK
===

`ITK`_ is a widely-used library for volumetric image processing. In order to
use ITK with highdicom, the ``itk`` python package must be installed separately.
Version 5.4.0 or later is required.

.. _itk_vol:

Volume Conversions
------------------

Highdicom supports conversions with the ``itk.Image`` class through the
:meth:`highdicom.Volume.to_itk` and :meth:`highdicom.Volume.from_itk` methods.
Like highdicom, ITK uses the "LPS" convention. However, when converting to and
from NumPy arrays, ITK reverses the order of dimensions. This permutation is
handled automatically by highdicom and requires no intervention by the user.

Creating an ITK Image from a Volume:

.. code-block:: python

import highdicom as hd


vol = hd.Volume(...)

itk_im = vol.to_itk()

Creating a volume from an ITK Image:

.. code-block:: python

import itk
import highdicom as hd


itk_im = itk.image(...)

vol = hd.Volume.from_itk(
itk_im=itk_im,
coordinate_system='PATIENT',
frame_of_reference_uid=None
)


.. _`ITK`: https://itk.org/
24 changes: 24 additions & 0 deletions docs/other_libraries.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _other_libraries:

Interactions with Other Libraries
=================================

Highdicom is able to interact with other imaging and scientific python
libraries. These integrations are intended to provide streamlined access to
complementary functionality available in external ecosystems that would
otherwise require custom user code.

Because these libraries are not required for all workflows, they are
treated as optional dependencies and are not installed as part of the
default ``highdicom`` installation. Functionality requiring an external
library becomes available when an appropriate version of the corresponding
package is installed alongside ``highdicom``. The following sections describe
which libraries are currently supported and the additional features each
library enables.

.. toctree::
:maxdepth: 3
:caption: Contents:

itk_lib
sitk_lib
51 changes: 51 additions & 0 deletions docs/sitk_lib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. _sitk_lib:

SimpleITK
=========

`SimpleITK`_ provides a simplified interface for the algorithms and data structures
of `ITK`_. In order to use ITK with highdicom, the ``SimpleITK`` python package must
be installed separately. Version 2.2.1 or later is required.

.. _sitk_vol:

Volume Conversions
------------------

Highdicom supports conversions with the ``SimpleITK.Image`` class through the
:meth:`highdicom.Volume.to_sitk` and :meth:`highdicom.Volume.from_sitk` methods.
Like highdicom, SimpleITK uses the "LPS" convention. However, when converting to
and from NumPy arrays, SimpleITK reverses the order of dimensions. This permutation
is handled automatically by highdicom and requires no intervention by the user.


Creating a SimpleITK Image from a Volume:

.. code-block:: python

import highdicom as hd


vol = hd.Volume(...)

sitk_im = vol.to_sitk()

Creating a volume from a SimpleITK Image:

.. code-block:: python

import SimpleITK as sitk
import highdicom as hd


sitk_im = sitk.image(...)

vol = hd.Volume.from_sitk(
sitk_im=sitk_im,
coordinate_system='PATIENT',
frame_of_reference_uid=None
)


.. _`ITK`: https://itk.org/
.. _`SimpleITK`: https://simpleitk.org/
60 changes: 10 additions & 50 deletions docs/volume.rst
Original file line number Diff line number Diff line change
Expand Up @@ -731,60 +731,20 @@ Writing a volume to a NIfTI file:
nifti_path = '/path/to/nifti.nii' # or .nii.gz
nib.save(nifti, nifti_path)

Volumes To/From ITK Images
--------------------------

`ITK`_ is a widely-used library for volumetric image processing. Its ``Image``
class shares many similarities with our :class:`highdicom.Volume` class. Like
highdicom, ITK uses the "LPS" convention. However, when converting to and from
NumPy arrays, ITK reverses the order of dimensions. It is important to account
for this when performing conversions.
Volumes To/From Other Libraries
-------------------------------

We plan to add tools to handle this conversion in the near future, but for now
these snippets should correctly handle simple situations converting to and from
ITK Images.

Creating a volume from an ITK Image:

.. code-block:: python

import itk
import numpy as np
import highdicom as hd


im = itk.image(...)

# Reverse array dimension order
array = itk.array_from_image(im).transpose([2, 1, 0])

vol2 = hd.Volume.from_components(
array=array,
direction=np.asarray(im.GetDirection()),
spacing=np.asarray(im.GetSpacing()),
position=np.asarray(im.GetOrigin()),
coordinate_system="PATIENT"
)

Creating an ITK Image from a Volume:

.. code-block:: python

import itk
import highdicom as hd


vol = hd.Volume(...)

# Reverse array dimension order
array = vol.array.transpose([2, 1, 0])
Many other libraries have classes that share similarities with our
:class:`highdicom.Volume` class and allow for simple conversions between
formats. For commonly used libraries, highdicom Volumes provide
``to_<library>()`` and ``from_<library>()`` methods to simplify moving to and
from other libraries as much as possible. For more information about each library,
visit the following:

im = itk.image_from_array(array)
im.SetOrigin(vol.position)
im.SetDirection(vol.direction)
im.SetSpacing(vol.spacing)
- :ref:`ITK <itk_vol>`
- :ref:`SimpleITK <sitk_vol>`


.. _`NIfTI`: https://nifti.nimh.nih.gov/
.. _`ITK`: https://itk.org/
.. _`nibabel`: https://nipy.org/nibabel/
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ libjpeg = [
"pylibjpeg-openjpeg>=2.0.0",
"pylibjpeg>=2.0",
]
itk = ["itk>=5.4.0"]
sitk = ["SimpleITK>=2.2.1"]

[dependency-groups]
test = [
Expand Down
Loading
Loading