How do I find the width of a curve at 1/e^2 but there are multiple points at this value
I am trying to find the width of a curve taken from the intensity vs x-index of an image (see below) at intensity = 1/e^2, essentially finding the beam diameter of a laser.
The resulting plot is:
The value of 1/e^2 is -3.55e4. Right now its calculating the width from the red points on the plot, but I’d like it to calculate the points from the green points. I’ve tried making it so it finds the points where the slope is negative, but that doesn’t seem to work. Even if you have an idea of how to do this that would be helpful, I can try to figure out the code from there. Still pretty new to matlab.
My code is:
clear
im=imread("D:THORS Imaging8.06.24Result of on_20000-off_20000.tif")
im=imrotate(im, -96,"bilinear")
im=imcrop(im, [200, 450, 700, 150]);
result=im
imshow(result)
%Sums pixel intensity in each verticle column
vertsum = sum(result, 1);
%Subtracts maximum intensity
vertsum =vertsum-max(vertsum);
%Sets threshold for baseline intensity
thresholdhigh = -100; %Threshold value chosen base on intensity of image
%Remove points above the threshold
vertsum = vertsum(vertsum <= thresholdhigh);
%Performs moving average on data
vertsum = movmean(vertsum,100);
%Sets data points fo create the Gaussian fit
[xData, yData] = prepareCurveData( [], vertsum );
%Sets conversion factor between pixels and cm
conversion = 3.5/1024;
%Convert pixels to cm
xcm = xData * conversion;
%Generates plot
plot(xcm, yData );
%% Find width of barrier
%Set the height of the fitted curve equal to the distance between 0 and the
%Height of intensity value
min = min(yData)
max=max(yData)
height=max-min
%Sets variable for 1/e^2, chosen due to gaussian shape of the beam
e = (1/((2.718281828459045)^2))
%Sets y-value on the curve at 1/e^2
pointY = max-(height * e)
%Finds nearest left side x-value on curve at 1/e^2
leftIndexWidth = find(yData <= pointY, 1, ‘first’)
%Finds nearest right side y-value on curve at 1/e^2
rightIndexWidth = find(yData <= pointY, 1, ‘last’)
%Converts pixel coordinate to cm
leftIndexWidth = leftIndexWidth * conversion
rightIndexWidth = rightIndexWidth * conversion
%Calculates width of curve at 1/e^2
widthpx = rightIndexWidth – leftIndexWidthI am trying to find the width of a curve taken from the intensity vs x-index of an image (see below) at intensity = 1/e^2, essentially finding the beam diameter of a laser.
The resulting plot is:
The value of 1/e^2 is -3.55e4. Right now its calculating the width from the red points on the plot, but I’d like it to calculate the points from the green points. I’ve tried making it so it finds the points where the slope is negative, but that doesn’t seem to work. Even if you have an idea of how to do this that would be helpful, I can try to figure out the code from there. Still pretty new to matlab.
My code is:
clear
im=imread("D:THORS Imaging8.06.24Result of on_20000-off_20000.tif")
im=imrotate(im, -96,"bilinear")
im=imcrop(im, [200, 450, 700, 150]);
result=im
imshow(result)
%Sums pixel intensity in each verticle column
vertsum = sum(result, 1);
%Subtracts maximum intensity
vertsum =vertsum-max(vertsum);
%Sets threshold for baseline intensity
thresholdhigh = -100; %Threshold value chosen base on intensity of image
%Remove points above the threshold
vertsum = vertsum(vertsum <= thresholdhigh);
%Performs moving average on data
vertsum = movmean(vertsum,100);
%Sets data points fo create the Gaussian fit
[xData, yData] = prepareCurveData( [], vertsum );
%Sets conversion factor between pixels and cm
conversion = 3.5/1024;
%Convert pixels to cm
xcm = xData * conversion;
%Generates plot
plot(xcm, yData );
%% Find width of barrier
%Set the height of the fitted curve equal to the distance between 0 and the
%Height of intensity value
min = min(yData)
max=max(yData)
height=max-min
%Sets variable for 1/e^2, chosen due to gaussian shape of the beam
e = (1/((2.718281828459045)^2))
%Sets y-value on the curve at 1/e^2
pointY = max-(height * e)
%Finds nearest left side x-value on curve at 1/e^2
leftIndexWidth = find(yData <= pointY, 1, ‘first’)
%Finds nearest right side y-value on curve at 1/e^2
rightIndexWidth = find(yData <= pointY, 1, ‘last’)
%Converts pixel coordinate to cm
leftIndexWidth = leftIndexWidth * conversion
rightIndexWidth = rightIndexWidth * conversion
%Calculates width of curve at 1/e^2
widthpx = rightIndexWidth – leftIndexWidth I am trying to find the width of a curve taken from the intensity vs x-index of an image (see below) at intensity = 1/e^2, essentially finding the beam diameter of a laser.
The resulting plot is:
The value of 1/e^2 is -3.55e4. Right now its calculating the width from the red points on the plot, but I’d like it to calculate the points from the green points. I’ve tried making it so it finds the points where the slope is negative, but that doesn’t seem to work. Even if you have an idea of how to do this that would be helpful, I can try to figure out the code from there. Still pretty new to matlab.
My code is:
clear
im=imread("D:THORS Imaging8.06.24Result of on_20000-off_20000.tif")
im=imrotate(im, -96,"bilinear")
im=imcrop(im, [200, 450, 700, 150]);
result=im
imshow(result)
%Sums pixel intensity in each verticle column
vertsum = sum(result, 1);
%Subtracts maximum intensity
vertsum =vertsum-max(vertsum);
%Sets threshold for baseline intensity
thresholdhigh = -100; %Threshold value chosen base on intensity of image
%Remove points above the threshold
vertsum = vertsum(vertsum <= thresholdhigh);
%Performs moving average on data
vertsum = movmean(vertsum,100);
%Sets data points fo create the Gaussian fit
[xData, yData] = prepareCurveData( [], vertsum );
%Sets conversion factor between pixels and cm
conversion = 3.5/1024;
%Convert pixels to cm
xcm = xData * conversion;
%Generates plot
plot(xcm, yData );
%% Find width of barrier
%Set the height of the fitted curve equal to the distance between 0 and the
%Height of intensity value
min = min(yData)
max=max(yData)
height=max-min
%Sets variable for 1/e^2, chosen due to gaussian shape of the beam
e = (1/((2.718281828459045)^2))
%Sets y-value on the curve at 1/e^2
pointY = max-(height * e)
%Finds nearest left side x-value on curve at 1/e^2
leftIndexWidth = find(yData <= pointY, 1, ‘first’)
%Finds nearest right side y-value on curve at 1/e^2
rightIndexWidth = find(yData <= pointY, 1, ‘last’)
%Converts pixel coordinate to cm
leftIndexWidth = leftIndexWidth * conversion
rightIndexWidth = rightIndexWidth * conversion
%Calculates width of curve at 1/e^2
widthpx = rightIndexWidth – leftIndexWidth fwhm, curve fitting MATLAB Answers — New Questions