|
1 | | -# Copyright 2021-2025 MONAI Consortium |
| 1 | +# Copyright 2021-2026 MONAI Consortium |
2 | 2 | # Licensed under the Apache License, Version 2.0 (the "License"); |
3 | 3 | # you may not use this file except in compliance with the License. |
4 | 4 | # You may obtain a copy of the License at |
|
11 | 11 |
|
12 | 12 | import copy |
13 | 13 | import logging |
14 | | -import math |
15 | 14 | from typing import Dict, List, Union |
16 | 15 |
|
17 | 16 | import numpy as np |
@@ -324,15 +323,14 @@ def prepare_series(self, series): |
324 | 323 | series.depth_direction_cosine = copy.deepcopy(last_slice_normal) |
325 | 324 |
|
326 | 325 | 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 ") |
336 | 334 |
|
337 | 335 | s_1 = series._sop_instances[0] |
338 | 336 | s_n = series._sop_instances[-1] |
|
0 commit comments