Skip to content
Snippets Groups Projects
Unverified Commit a1199a39 authored by HanBrady's avatar HanBrady Committed by GitHub
Browse files

Merge pull request #17 from HanBrady/beam_widths

Manual beam width measurement
parents cb483066 8d9a080e
Branches main
No related tags found
No related merge requests found
...@@ -9,10 +9,6 @@ import imageio.v3 as iio ...@@ -9,10 +9,6 @@ import imageio.v3 as iio
import laserbeamsize as lbs import laserbeamsize as lbs
from PIL import Image from PIL import Image
## Read in image as numpy array
#im_in = Image.open('laser_sim.png') # read in laser data
#im = np.asarray(im_in) # Could do this in one line with cv2?
## Locate peak x and y ## Locate peak x and y
def beam_width_manual(image, axis_in): def beam_width_manual(image, axis_in):
...@@ -27,19 +23,35 @@ def beam_width_manual(image, axis_in): ...@@ -27,19 +23,35 @@ def beam_width_manual(image, axis_in):
""" """
im_in = Image.open(image) # read in laser data im_in = Image.open(image) # read in laser data
im = np.asarray(im_in) im = np.asarray(im_in)
print(im)
if axis_in == 'x': if axis_in == 'x':
axis = 0 axis = 0
max_point = np.argmax(im, axis) # find coord at peak
peak = np.max(max_point)
print('peak:', peak)
plot = im[peak, :, 0]
#Plot line of pixels with max
plt.plot(plot)
#determine fwhm
max_val = plot[peak]
hm = int(max_val/2)
hmx = plt.axhline(hm, color = 'black')
plt.show()
index1 = np.where(plot >= hm)
index = index1[0]
width = index[-1] - index[0]
print(f'Beam width (manual) is {width} pixels')
elif axis_in == 'y': elif axis_in == 'y':
axis = 1 axis = 1
else:
raise ValueError('Please input either x or y for axis_in')
max_point = np.argmax(im, axis) # find coord at peak max_point = np.argmax(im, axis) # find coord at peak
peak = np.max(max_point) peak = np.max(max_point)
print('peak:', peak)
plot = im[:, peak, 0]
#Plot line of pixels with max #Plot line of pixels with max
plot = im[peak, :, 0]
plt.plot(plot) plt.plot(plot)
#determine fwhm #determine fwhm
...@@ -47,10 +59,13 @@ def beam_width_manual(image, axis_in): ...@@ -47,10 +59,13 @@ def beam_width_manual(image, axis_in):
hm = int(max_val/2) hm = int(max_val/2)
hmx = plt.axhline(hm, color = 'black') hmx = plt.axhline(hm, color = 'black')
plt.show() plt.show()
index1 = np.where(plot >= hm) index1 = np.where(plot >= hm)
index = index1[0] index = index1[0]
width = index[-1] - index[0] width = index[-1] - index[0]
print(width) print(f'Beam width (manual) is {width} pixels')
else:
raise ValueError('Please input either x or y for axis_in')
return width return width
...@@ -81,10 +96,10 @@ def beam_width(image): ...@@ -81,10 +96,10 @@ def beam_width(image):
print("The ellipse diameter (closest to vertical) is %.0f pixels" % dy) print("The ellipse diameter (closest to vertical) is %.0f pixels" % dy)
print("The ellipse is rotated %.0f degrees ccw from the horizontal" % (phi * 180/3.1416)) print("The ellipse is rotated %.0f degrees ccw from the horizontal" % (phi * 180/3.1416))
beam_width_manual('laser_beam.jpg', 'x') beam_width_manual('laser_sim.png', 'x')
#beam_width_manual('22.07_laserpic3.png', 'y') beam_width_manual('laser_sim.png', 'y')
## Compare with lbs ## Compare with lbs
image = dithered('laser_beam.jpg') image = dithered('laser_sim.png')
beam_width(image) beam_width(image)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment