Skip to content

Commit e7420e0

Browse files
authored
slice removal fix (#527)
Signed-off-by: bluna301 <luna.bryanr@gmail.com>
1 parent c12a1a9 commit e7420e0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

monai/deploy/operators/dicom_series_to_volume_operator.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2023 MONAI Consortium
1+
# Copyright 2021-2025 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
@@ -234,11 +234,17 @@ def prepare_series(self, series):
234234
series._sop_instances[slice_index].distance = distance
235235
series._sop_instances[slice_index].first_pixel_on_slice_normal = point
236236
else:
237-
print("going to removing slice ", slice_index)
237+
logging.debug(f"Slice index to remove: {slice_index}")
238238
slice_indices_to_be_removed.append(slice_index)
239239

240-
for sl_index, _ in enumerate(slice_indices_to_be_removed):
240+
logging.debug(f"Total slices before removal (if applicable): {len(series._sop_instances)}")
241+
242+
# iterate in reverse order to avoid affecting subsequent indices after a deletion
243+
for sl_index in sorted(slice_indices_to_be_removed, reverse=True):
241244
del series._sop_instances[sl_index]
245+
logging.info(f"Removed slice index: {sl_index}")
246+
247+
logging.debug(f"Total slices after removal (if applicable): {len(series._sop_instances)}")
242248

243249
series._sop_instances = sorted(series._sop_instances, key=lambda s: s.distance)
244250
series.depth_direction_cosine = copy.deepcopy(last_slice_normal)

0 commit comments

Comments
 (0)