Release Notes

Brief release notes may be found on on Github. This page contains migration notes for major breaking changes to the library’s API.

Deprecation of add_segments method

Prior to highdicom 0.8.0, it was possible to add further segments to highdicom.seg.Segmentation image after its construction using the add_segments method. This was found to produce incorrect Dimension Index Values if the empty frames did not match within all segments added.

To create the Dimension Index Values correctly, the constructor needs access to all segments in the image when it is first created. Therefore, the add_segments method was removed in highdicom 0.8.0. Instead, in highdicom 0.8.0 and later, multiple segments can be passed to the constructor by stacking their arrays along the fourth dimension.

Given code that adds segments like this, in highdicom 0.7.0 and earlier:

import numpy as np
import highdicom as hd

# Create initial segment mask and description
mask_1 = np.array(
    # ...
)
description_1 = hd.seg.SegmentDescription(
    # ...
)
seg = hd.seg.Segmentation(
    # ...
    pixel_array=mask_1,
    segment_descriptions=[description_1],
    # ...
)

# Create a second segment and add to the existing segmentation
mask_2 = np.array(
    # ...
)
description_2 = hd.seg.SegmentDescription(
    # ...
)

seg.add_segments(
    # ...
    pixel_array=mask_2,
    segment_descriptions=[description_2],
    # ...
)

This can be migrated to highdicom 0.8.0 and later by concatenating the arrays along the fourth dimension and calling the constructor at the end.

import numpy as np
import highdicom as hd

# Create initial segment mask and description
mask_1 = np.array(
    # ...
)
description_1 = hd.seg.SegmentDescription(
    # ...
)

# Create a second segment and description
mask_2 = np.array(
    # ...
)
description_2 = hd.seg.SegmentDescription(
    # ...
)

combined_segments = np.concatenate([mask_1, mask_2], axis=-1)
combined_descriptions = [description_1, description_2]

seg = hd.seg.Segmentation(
    # ...
    pixel_array=combined_segments,
    segment_descriptions=combined_descriptions,
    # ...
)

Note that segments must always be stacked down the fourth dimension (with index 3) of the pixel_array. In order to create a segmentation with multiple segments for a single source frame, it is required to add a new dimension (with length 1) as the first dimension (index 0) of the array.

Correct coordinate mapping

Prior to highdicom 0.14.1, mappings between image coordinates and reference coordinates did not take into account that there are two image coordinate systems, which are shifted by 0.5 pixels.

  1. Pixel indices: (column, row) indices into the pixel matrix. The values are zero-based integers in the range [0, Columns - 1] and [0, Rows - 1]. Pixel indices are defined relative to the centers of pixels and the (0, 0) index is located at the center of the top left corner pixel of the total pixel matrix.

  2. Image coordinates: (column, row) coordinates in the pixel matrix at sub-pixel resolution. The values are floating-point numbers in the range [0, Columns] and [0, Rows]. Image coordinates are defined relative to the top left corner of the pixels and the (0.0, 0.0) point is located at the top left corner of the top left corner pixel of the total pixel matrix.

To account for these differences, introduced two additional transformer classes in highdicom 0.14.1. and made changes to the existing ones. The existing transformer class now map between image coordinates and reference coordinates (highdicom.spatial.ImageToReferenceTransformer and highdicom.spatial.ReferenceToImageTransformer). While the new transformer classes map between pixel indices and reference coordinates (highdicom.spatial.PixelToReferenceTransformer and highdicom.spatial.ReferenceToPixelTransformer). Note that you want to use the former classes for converting between spatial coordinates (SCOORD) (highdicom.sr.ScoordContentItem) and 3D spatial coordinates (SCOORD3D) (highdicom.sr.Scoord3DContentItem) and the latter for determining the position of a pixel in the frame of reference or for projecting a coordinate in the frame of reference onto the image plane.

To make the distinction between pixel indices and image coordinates as clear as possible, we renamed the parameter of the highdicom.spatial.map_pixel_into_coordinate_system() function from coordinate to index and enforce that the values that are provided via the argument are integers rather than floats. In addition, the return value of highdicom.spatial.map_coordinate_into_pixel_matrix() is now a tuple of integers.

Deprecation of processing_type parameter

In highdicom 0.15.0, the processing_type parameter was removed from the constructor of highdicom.content.SpecimenPreparationStep. The parameter turned out to be superfluous, because the argument could be derived from the type of the processing_procedure argument.

Refactoring of SpecimenPreparationStep class

In highdicom 0.16.0 and later versions, highdicom.content.SpecimenPreparationStep represents an item of the Specimen Preparation Sequence rather than the Specimen Preparation Step Content Item Sequence and the class is consequently derived from pydicom.dataset.Dataset instead of pydicom.sequence.Sequence. As a consequence, alternative construction of an instance of highdicom.content.SpecimenPreparationStep needs to be performed using the from_dataset() instead of the from_sequence() class method.

Deprecation of Big Endian Transfer Syntaxes

The use of “Big Endian” transfer syntaxes such as ExplicitVRBigEndian is disallowed from highdicom 0.18.0 onwards. The use of Big Endian transfer syntaxes has been retired in the standard for some time. To discourage the use of retired transfer syntaxes and to simplify the logic when encoding and decoding objects in which byte order is relevant, in version 0.17.0 and onwards passing a big endian transfer syntax to the constructor of highdicom.SOPClass or any of its subclasses will result in a value error.

Similarly, as of highdicom 0.18.0, it is no longer possible to pass datasets with a Big Endian transfer syntax to the from_dataset methods of any of the highdicom.SOPClass subclasses.

Change in MeasurementReport constructor for TID 1601 enhancement

A breaking change was made after highdicom 0.18.4 in the creation of Image Library TID 1601 objects. Previously the Image Library was constructed by explicitly passing a pydicom.sequence.Sequence of highdicom.sr.ImageLibraryEntryDescriptors objects to the highdicom.sr.MeasurementReport constructor in the image_library_groups argument. Now a pydicom.sequence.Sequence of pydicom.dataset.Dataset objects is passed in the referenced_images argument and the ImageLibrary components are created internally by highdicom. This standardizes the content of the Image Library subcomponents.

Deprecation of Window Center/Width Parameters in Parametric Map

In order to unify the API with other places in the library and give further flexibility, the window_center and windhow_width parameters of the highdicom.pm.ParametricMap class were deprecated in highdicom 0.28.0 in favor of the new voi_lut_transformations parameter and will be removed in a future release. To update existing code, create a simple VOI LUT transformation instead and pass to the voi_lut_transformations parameter. So this:

import highdicom as hd

pm = hd.pm.ParametricMap(
    ...,
    window_center=window_center,
    window_width=window_width,
    ...,
)

can be replaced with this to give the same output object:

import highdicom as hd

pm = hd.pm.ParametricMap(
    ...,
    voi_lut_transformations=[
        hd.VOILUTTransformation(
            window_center=window_center,
            window_width=window_width,
        )
    ],
    ...,
)

Deprecation of bits_allocated parameter in SCImage

Until highdicom 0.29.0, the constructor of highdicom.sc.SCImage (and its classmethod highdicom.sc.SCImage.from_ref_dataset()) had a required parameter named bits_allocated. However, there were several issues with this. Firstly, it would accept a value of 12, which is not valid for use with Bits Allocated. For other values, it had to match exactly the number of bits in the datatype of the pixel_array parameter, making it serve no useful purpose other than make the API more complex for users.

In version 0.29.0, the parameter was deprecated. The number of bits allocated is now inferred from the datatype of pixel_array. By default, the number of bits stored will match the number of bits allocated. A new keyword-only bits_stored parameter allows you to specify a number of bits stored that differs from the number of bits allocated. To minimize disruption for existing code, the constructor will continue to accept bits_allocated as a keyword parameter, and treat it as if the same value were passed to bits_stored, but issue a warning instructing the user to update the code.

Unfortunately, code that passes bits_allocated as a positional argument will break with this change. In this case, users should either remove this argument entirely to have bits allocated and bits stored inferred from the pixel array, or specify bits_stored instead.

CIELab Conversions Now Use The D50 White Point

DICOM encodes CIELab values (such as Recommended Display CIELab Value) in the same way as the ICC Profile Connection Space (see PS3.3 C.10.7.1.1), i.e. relative to the D50 illuminant, whereas the native white point of sRGB is D65.

Prior to highdicom 0.29.0, the conversions implemented by highdicom.color.CIELabColor (from_rgb, from_string and to_rgb) omitted the chromatic adaptation between the two white points and therefore produced CIELab values relative to D65. From highdicom 0.29.0, sRGB values are linearized, converted to CIE XYZ (D65), chromatically adapted to D50 using the linear Bradford transform, and only then converted to CIELab (and vice versa). The matrices and constants used are those of the CSS Color Module Level 4 sample code, matching the behavior of DCMTK (changed after version 3.7.0) and PixelMed.

No code changes are required, but note that the CIELab values stored in files created with highdicom 0.29.0 and later differ slightly from those created with earlier versions for the same RGB input. Neutral (gray) colors are unaffected; for chromatic colors the a* and b* components change. For example, pure red (255, 0, 0) was previously encoded as L*a*b* (53.23, 80.11, 67.22) and is now encoded as (54.29, 80.81, 69.89).

Codes With Modifiers in Segmentation and Annotation Objects

In highdicom 0.29.0, the segmented property type of a segment (in highdicom.seg.SegmentDescription), the annotated property type of an annotation group (in highdicom.ann.AnnotationGroup), and the anatomic regions and primary anatomic structures of both, may include modifier codes (for example to specify laterality) via the new classes highdicom.seg.SegmentedPropertyType, highdicom.ann.AnnotatedPropertyType, highdicom.AnatomicRegion and highdicom.PrimaryAnatomicStructure. See Codes With Modifiers, Segment Descriptions With Modifiers and Annotation Groups With Modifiers for details.

Existing code continues to work without modification, but some behavior has changed:

To compare only root codes in existing code, either use highdicom.sr.codes_equal() with ignore_modifiers=True or compare the unmodified property:

import highdicom as hd
from pydicom.sr.codedict import codes

seg = hd.seg.segread('path/to/seg.dcm')
desc = seg.get_segment_description(1)

# Compares the root code only, whether or not the segment has modifiers
assert hd.sr.codes_equal(
    desc.segmented_property_type,
    codes.SCT.Kidney,
    ignore_modifiers=True,
)
assert desc.segmented_property_type.unmodified == codes.SCT.Kidney

Tolerances in match_geometry

In highdicom 0.29.0, the tol parameter of highdicom.Volume.match_geometry() and highdicom.VolumeGeometry.match_geometry() is deprecated. It previously governed both the voxel spacing and the position comparisons using a very tight default of 1e-5 that often caused spurious failures with real DICOM data. It is replaced by three more specific parameters:

  • spacing_tol (default 1e-3): the ratio of the two volumes’ voxel spacings must be within spacing_tol * n of the nearest integer n, so the tolerance is relative to the step size.

  • position_tol (default 1e-2): the translation between the volumes must be within this fraction of a voxel of a whole number of voxels. This is also applied to the misalignment at the far end of the grid, so that small spacing differences that accumulate across a volume are detected.

  • parallel_tol: the tolerance used when deciding whether direction vectors are parallel.

Passing tol still works but emits a DeprecationWarning and sets both spacing_tol and position_tol to the given value. To update your code, replace tol with the new parameters:

# Before
matched = volume.match_geometry(other, tol=1e-4)

# After
matched = volume.match_geometry(
    other,
    spacing_tol=1e-4,
    position_tol=1e-4,
)

Note that the new defaults are more permissive for rounding error in individual positions and spacings, but the far-end alignment check may reject large volumes with slightly inexact spacings that were previously accepted. If this occurs, increase position_tol.