Skip to content

Commit 187bf52

Browse files
committed
depth pixel spacing fix for oblique cases
Signed-off-by: bluna301 <luna.bryanr@gmail.com>
1 parent 4f777ee commit 187bf52

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

monai/deploy/operators/dicom_series_to_volume_operator.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2025 MONAI Consortium
1+
# Copyright 2021-2026 MONAI Consortium
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -11,7 +11,6 @@
1111

1212
import copy
1313
import logging
14-
import math
1514
from typing import Dict, List, Union
1615

1716
import numpy as np
@@ -324,15 +323,14 @@ def prepare_series(self, series):
324323
series.depth_direction_cosine = copy.deepcopy(last_slice_normal)
325324

326325
if len(series._sop_instances) > 1:
327-
p1 = series._sop_instances[0].first_pixel_on_slice_normal
328-
p2 = series._sop_instances[1].first_pixel_on_slice_normal
329-
depth_pixel_spacing = (
330-
(p1[0] - p2[0]) * (p1[0] - p2[0])
331-
+ (p1[1] - p2[1]) * (p1[1] - p2[1])
332-
+ (p1[2] - p2[2]) * (p1[2] - p2[2])
333-
)
334-
depth_pixel_spacing = math.sqrt(depth_pixel_spacing)
335-
series.depth_pixel_spacing = depth_pixel_spacing
326+
# Depth spacing is the difference of the two slice origins' scalar projections
327+
# onto the unit slice normal, dot(n, p) — already computed into .distance above
328+
d1 = series._sop_instances[0].distance
329+
d2 = series._sop_instances[1].distance
330+
series.depth_pixel_spacing = abs(d2 - d1)
331+
332+
logging.debug(f"Slice normal projections, first two instances: {d1} & {d2}")
333+
logging.debug(f"Depth pixel spacing: {series.depth_pixel_spacing:.6f} mm ")
336334

337335
s_1 = series._sop_instances[0]
338336
s_n = series._sop_instances[-1]

0 commit comments

Comments
 (0)