Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACR Object orientation - bugfix #416

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ uploads
report*
# TODO: Remove the following if no longer needed
hazenlib/data
dump/
tests/data

# docs
docs/_build
Expand Down
5 changes: 4 additions & 1 deletion hazenlib/ACRObject.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import cv2
import scipy
import skimage
Expand Down Expand Up @@ -39,7 +40,9 @@ def sort_dcms(self, dcm_list):
"""
orientation, positions = determine_orientation(dcm_list)
if orientation == "unexpected":
pass
# TODO: error out for now,
# in future allow manual override based on optional CLI args
sys.exit()

logger.info("image orientation is %s", orientation)
dcm_stack = [dcm_list[i] for i in np.argsort(positions)]
Expand Down
1 change: 0 additions & 1 deletion hazenlib/tasks/uniformity.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def get_fractional_uniformity(self, dcm):
tuple: values of horizontal and vertical fractional uniformity
"""
arr = dcm.pixel_array
print(type(dcm))
x, y = self.get_object_centre(dcm)

central_roi = arr[(y - 5) : (y + 5), (x - 5) : (x + 5)].flatten()
Expand Down
26 changes: 19 additions & 7 deletions hazenlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ def determine_orientation(dcm_list):
# assuming each have a unique position in one of the 3 directions
expected = len(dcm_list)
iop = dcm_list[0].ImageOrientationPatient
x = np.array([dcm.ImagePositionPatient[0] for dcm in dcm_list])
y = np.array([dcm.ImagePositionPatient[1] for dcm in dcm_list])
z = np.array([dcm.ImagePositionPatient[2] for dcm in dcm_list])
x = np.array([round(dcm.ImagePositionPatient[0]) for dcm in dcm_list])
y = np.array([round(dcm.ImagePositionPatient[1]) for dcm in dcm_list])
z = np.array([round(dcm.ImagePositionPatient[2]) for dcm in dcm_list])

# Determine phantom orientation based on DICOM header metadata
# Assume phantom orientation based on ImageOrientationPatient
Expand All @@ -382,12 +382,24 @@ def determine_orientation(dcm_list):
return "axial", z
else:
logger.debug("Checking phantom orientation based on ImagePositionPatient")
# Assume phantom orientation based on ImagePositionPatient
if len(set(x)) == expected and len(set(y)) == 1 and len(set(z)) == 1:
# Assume phantom orientation based on the changing value in ImagePositionPatient
if (
len(set(x)) == expected
and len(set(y)) < expected
and len(set(z)) < expected
):
return "sagittal", x
elif len(set(x)) == 1 and len(set(y)) == expected and len(set(z)) == 1:
elif (
len(set(x)) < expected
and len(set(y)) == expected
and len(set(z)) < expected
):
return "coronal", y
elif len(set(x)) == 1 and len(set(y)) == 1 and len(set(z)) == expected:
elif (
len(set(x)) < expected
and len(set(y)) < expected
and len(set(z)) == expected
):
return "axial", z
else:
logger.warning("Unable to determine orientation based on DICOM metadata")
Expand Down
Loading