From 05aa9f26e0dfd4f4f7eef780945e315797e9f0e4 Mon Sep 17 00:00:00 2001 From: rtmalikian Date: Thu, 18 Jun 2026 15:51:38 -0700 Subject: [PATCH 1/2] fix: warn when PydicomReader cannot determine affine from DICOM metadata When ImageOrientationPatient (00200037) or ImagePositionPatient (00200032) are missing from DICOM metadata, PydicomReader silently returns an identity affine matrix. This commonly occurs with multiframe DICOM files (e.g., Enhanced CT) where spatial metadata is stored in per-frame functional groups. This change adds a warning to inform users that the affine matrix may be incorrect and suggests using ITKReader as an alternative. Fixes #8468 Signed-off-by: Raphael Malikian --- monai/data/image_reader.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/monai/data/image_reader.py b/monai/data/image_reader.py index a85eb95c20..689ef76940 100644 --- a/monai/data/image_reader.py +++ b/monai/data/image_reader.py @@ -738,6 +738,14 @@ def _get_affine(self, metadata: dict, lps_to_ras: bool = True): """ affine: np.ndarray = np.eye(4) if not ("00200037" in metadata and "00200032" in metadata): + warnings.warn( + "PydicomReader: ImageOrientationPatient (00200037) or " + "ImagePositionPatient (00200032) not found in DICOM metadata. " + "The affine matrix will be set to identity, which may be incorrect. " + "This commonly occurs with multiframe DICOM files (e.g., Enhanced CT). " + "Consider using ITKReader for accurate spatial metadata.", + stacklevel=2, + ) return affine # "00200037" is the tag of `ImageOrientationPatient` rx, ry, rz, cx, cy, cz = metadata["00200037"]["Value"] From 78ac03b6e988c5f0da978b90fdc8f180ffdf9f8f Mon Sep 17 00:00:00 2001 From: rtmalikian Date: Thu, 18 Jun 2026 16:02:29 -0700 Subject: [PATCH 2/2] docs: add Warns section to _get_affine docstring documenting the missing-tag warning Signed-off-by: Raphael Malikian --- monai/data/image_reader.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/monai/data/image_reader.py b/monai/data/image_reader.py index 689ef76940..653078c5a4 100644 --- a/monai/data/image_reader.py +++ b/monai/data/image_reader.py @@ -735,6 +735,11 @@ def _get_affine(self, metadata: dict, lps_to_ras: bool = True): metadata: metadata with dict type. lps_to_ras: whether to convert the affine matrix from "LPS" to "RAS". Defaults to True. + Warns: + UserWarning: when ImageOrientationPatient (00200037) or ImagePositionPatient + (00200032) is missing from metadata. The affine matrix is set to identity, + which may be incorrect. Common with multiframe DICOM files. + """ affine: np.ndarray = np.eye(4) if not ("00200037" in metadata and "00200032" in metadata):