diff --git a/Scripts/manual_comp.py b/Scripts/manual_comp.py index ee94fdc96cf81e1f5a20380b697d741fb11d9927..7993083a9a1922417859061681afc6bd92133581 100644 --- a/Scripts/manual_comp.py +++ b/Scripts/manual_comp.py @@ -9,10 +9,6 @@ import imageio.v3 as iio import laserbeamsize as lbs 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 def beam_width_manual(image, axis_in): @@ -27,31 +23,50 @@ def beam_width_manual(image, axis_in): """ im_in = Image.open(image) # read in laser data im = np.asarray(im_in) - print(im) if axis_in == 'x': 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': axis = 1 + 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') else: raise ValueError('Please input either x or y for axis_in') - max_point = np.argmax(im, axis) # find coord at peak - peak = np.max(max_point) - - #Plot line of pixels with max - plot = im[peak, :, 0] - 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(width) - return width def dithered(image_in): @@ -81,10 +96,10 @@ def beam_width(image): 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)) -beam_width_manual('laser_beam.jpg', 'x') -#beam_width_manual('22.07_laserpic3.png', 'y') +beam_width_manual('laser_sim.png', 'x') +beam_width_manual('laser_sim.png', 'y') ## Compare with lbs -image = dithered('laser_beam.jpg') +image = dithered('laser_sim.png') beam_width(image) \ No newline at end of file