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

Update ACRObject.py with phantom rotation detection function. #453

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions hazenlib/ACRObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ def order_phantom_slices(self, dcm_list):
# else:
# print("LR orientation swap not required.")

def calculate_rotation(img):
img = (np.maximum(img,0) / img.max()) * 255
img = np.uint8(img)

imgBlur = cv.GaussianBlur(img, (13,13), 0)
canny_edge = cv.Canny(imgBlur, 5, 40)

test_angles = np.linspace(-pi/2, pi/2, 1801, endpoint = False)
hough_space, theta, rho = hough_line(canny_edge, test_angles)
_ , bestTheta, _ = hough_line_peaks(hough_space, theta, rho, min_angle = 10)
rotation = np.mean(bestTheta[:2]) * 180/pi

# Transform to be angle wrt positive x axis.
rotation = 90 - (rotation + 180)

# Select positive angle that is less than 360 deg.
while rotation < 0:
rotation += 180

if rotation > 360:
rotation -= 360

# Angle in degrees from positive x-axis.
return rotation

@staticmethod
def determine_rotation(img):
"""Determine the rotation angle of the phantom using edge detection and the Hough transform.
Expand Down