Last active
April 10, 2023 18:07
-
-
Save jrkerns/244dc2ec073cb98dd2564e638dfbe16f to your computer and use it in GitHub Desktop.
PF picket distances by leaf pair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pylinac | |
from pylinac.core.profile import MultiProfile | |
pf = pylinac.PicketFence.from_demo_image() | |
pf.analyze() | |
# the secret sauce. This gives the y-value for each leaf kiss. | |
# We convert to a set because we have N kisses for each pair where N is the # of pickets. | |
y_values = list(set([meas.leaf_center_px for meas in pf.mlc_meas])) | |
# sample the image and take a profile; note this is only for up/down pickets. need to invert for left/right pickets. | |
line = pf.image[int(round(y_values[0])), :] # grab the first leaf pair. Wrap this in a for loop or similar to iterate over all y_values. | |
profile = MultiProfile(line) | |
peak_idxs, _ = profile.find_peaks(min_distance=0.01, threshold=0.6) # might need to tweak these parameters for your image(s) | |
profile.plot() # optional, plot to verify peaks were correctly found | |
plt.show() | |
dists = np.diff(peak_idxs) / pf.image.dpmm # get distances and convert to mm | |
print(f"Distances between pickets in mm: {dists}") | |
# with the demo image I get: | |
# Distances between pickets in mm: [14.78342839 15.45540241 14.78342839 15.1194154 15.1194154 14.78342839 | |
# 15.1194154 15.1194154 14.78342839] | |
# note this isn't subpixel! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment