Skip to content

Volume.copy() drops channels, so match_geometry() fails on multichannel volumes with equal geometry #462

Description

@fedorov

Issue identified and summarized by Claude while working on ImagingDataCommons/idc-index-data#170


Volume.copy() does not pass channels to the constructor, so it fails for any volume with channel dimensions. match_geometry() calls copy() when the geometries already match, so a SEG volume that is already on its source image's grid cannot be matched to it.

import numpy as np
import highdicom as hd

vol = hd.Volume(
    array=np.zeros((2, 3, 3, 2), dtype=np.uint8),
    affine=np.eye(4),
    coordinate_system="PATIENT",
    channels={"SegmentNumber": [1, 2]},
)
vol.copy()
ValueError: Number of items in the 'channels' parameter (0) does not match the number of channel dimensions in the array (1).

highdicom 0.28.1. Workaround: skip match_geometry() when geometry_equal() is true.

Activity

  1. fedorov commented on Sep 25, 2026

    @fedorov
    MemberAuthor

    Real-data case from IDC (QIN-Breast PET and its BAMF SEG), public, no credentials needed:

    from pathlib import Path
    
    import highdicom as hd
    import pydicom
    from idc_index import IDCClient
    
    seg_uid = "1.2.276.0.7230010.3.1.3.17436516.294850.1696966650.448304"
    pt_uid = "1.3.6.1.4.1.14519.5.2.1.8162.7003.717106612860546095602089628380"
    IDCClient().download_from_selection(
        seriesInstanceUID=[seg_uid, pt_uid], downloadDir="data", dirTemplate="%SeriesInstanceUID"
    )
    
    pt = hd.get_volume_from_series(
        [pydicom.dcmread(f) for f in Path("data", pt_uid).glob("*.dcm")]
    )
    seg = hd.seg.segread(next(Path("data", seg_uid).glob("*.dcm"))).get_volume()
    print(seg.geometry_equal(pt, tol=1e-3))  # True
    seg.match_geometry(pt, tol=1e-3)  # ValueError
  2. self-assigned this
    on Sep 25, 2026
  3. CPBridge commented on Oct 6, 2026

    @CPBridge
    Collaborator

    Closed by #468

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions