| 1 |
:octicon:`book;1em;sd-text-info` Measuring Laser Beam Size |
| 2 |
========================================================== |
| 3 |
|
| 4 |
.. meta:: |
| 5 |
:description: Tutorial on how to measure the size of a laser beam using DataLab, the open-source scientific analysis and visualization platform |
| 6 |
:keywords: DataLab, tutorial, laser beam, size, FWHM, Gaussian fit, radial profile, line profile, thresholding, centroid, image statistics, linear calibration, HDF5, workspace |
| 7 |
|
| 8 |
This example shows how to measure the size of a laser beam along the propagation |
| 9 |
axis using DataLab: |
| 10 |
|
| 11 |
- Load all the images in a folder |
| 12 |
- Apply a threshold to the images |
| 13 |
- Extract the intensity profile along an horizontal line |
| 14 |
- Fit the intensity profile to a Gaussian function |
| 15 |
- Compute the full width at half maximum (FWHM) of intensity profile |
| 16 |
- Try another method: extract the radial intensity profile |
| 17 |
- Compute the FWHM of the radial intensity profile |
| 18 |
- Perform the same analysis on a stack of images and on the resulting profiles |
| 19 |
- Plot the beam size as a function of the position along the propagation axis |
| 20 |
|
| 21 |
Load the images |
| 22 |
--------------- |
| 23 |
|
| 24 |
.. note:: |
| 25 |
|
| 26 |
The images used in this tutorial "TEM00_z_*.jpg" are available in the tutorial data |
| 27 |
folder of DataLab's installation directory |
| 28 |
(``<DataLab installation directory>/data/tutorials/``). |
| 29 |
|
| 30 |
.. only:: html |
| 31 |
|
| 32 |
Alternatively, you can download them from :download:`here </_download/laser_beam.zip>` |
| 33 |
and extract to the folder of your choice. |
| 34 |
|
| 35 |
.. only:: latex |
| 36 |
|
| 37 |
Alternatively, they can be downloaded from the online documentation at |
| 38 |
https://datalab-platform.com. |
| 39 |
|
| 40 |
|
| 41 |
First, we open DataLab and load the images. When working with multiple images, the most |
| 42 |
efficient approach is to use the "Open from directory..." option |
| 43 |
from the "File" menu (or click the |fileopen_dir| button in the toolbar). This feature |
| 44 |
loads all images from a selected directory at once. |
| 45 |
|
| 46 |
.. figure:: ../../images/tutorials/laser_beam/00.png |
| 47 |
|
| 48 |
The "File > Open Image..." menu |
| 49 |
|
| 50 |
.. |fileopen_dir| image:: ../../../datalab/data/icons/io/fileopen_directory.svg |
| 51 |
:width: 24px |
| 52 |
:height: 24px |
| 53 |
:class: dark-light no-scaled-link |
| 54 |
|
| 55 |
.. figure:: ../../images/tutorials/laser_beam/01.png |
| 56 |
|
| 57 |
Select the folder containing the images and click "Choose". |
| 58 |
|
| 59 |
The images are now loaded in the "Image panel". You can zoom in and out by |
| 60 |
right-clicking and dragging the mouse vertically. |
| 61 |
To pan the image, use the middle mouse button while dragging. |
| 62 |
|
| 63 |
.. figure:: ../../images/tutorials/laser_beam/02.png |
| 64 |
|
| 65 |
Zoom in and out with the right mouse button. Pan the image with the middle mouse |
| 66 |
button. |
| 67 |
|
| 68 |
.. note:: |
| 69 |
|
| 70 |
To view multiple images simultaneously, select the image group and choose |
| 71 |
"View images side-by-side" from the "View" menu. |
| 72 |
|
| 73 |
.. figure:: ../../images/tutorials/laser_beam/03b.png |
| 74 |
|
| 75 |
Viewing images side by side. |
| 76 |
|
| 77 |
.. warning:: |
| 78 |
|
| 79 |
The "Processing > Geometry" menu includes a "Distribute on a grid" option |
| 80 |
|distribute_on_grid|. This feature repositions the images by applying |
| 81 |
offsets to their X and Y coordinates, arranging them in a grid layout |
| 82 |
for side-by-side viewing. Note that this operation modifies the image |
| 83 |
coordinates. |
| 84 |
|
| 85 |
.. figure:: ../../images/tutorials/laser_beam/03.png |
| 86 |
|
| 87 |
Images distributed on 4 columns grid. |
| 88 |
|
| 89 |
To restore the original image positions, use the "Reset image positions" |
| 90 |
option |reset_positions| from the "Processing > Geometry" menu. Note that this |
| 91 |
operation sets all image origins to match the first image's origin, |
| 92 |
which means any initial differences in image origins will be lost. |
| 93 |
|
| 94 |
.. |distribute_on_grid| image:: ../../../datalab/data/icons/processing/distribute_on_grid.svg |
| 95 |
:width: 24px |
| 96 |
:height: 24px |
| 97 |
:class: dark-light no-scaled-link |
| 98 |
|
| 99 |
.. |reset_positions| image:: ../../../datalab/data/icons/processing/reset_positions.svg |
| 100 |
:width: 24px |
| 101 |
:height: 24px |
| 102 |
:class: dark-light no-scaled-link |
| 103 |
|
| 104 |
Remove background noise |
| 105 |
----------------------- |
| 106 |
|
| 107 |
When we select one of the images, we notice the presence of background noise, making |
| 108 |
it beneficial to apply a threshold to the images. |
| 109 |
Several methods are available to estimate the background noise level. |
| 110 |
|
| 111 |
One approach utilizes the "Cross section" tool, which is provided by the |
| 112 |
`PlotPy <https://github.com/PlotPyStack/plotpy>` library that DataLab uses for signal and image visualization. |
| 113 |
Select an image from the "Image panel", choose the corresponding image |
| 114 |
in the visualization panel, and activate the "Cross section" tool |cross_section| from |
| 115 |
the vertical toolbar on the left side of the visualization panel. This |
| 116 |
reveals that the background noise level is approximately 30 lsb. |
| 117 |
|
| 118 |
.. |cross_section| image:: ../../images/tutorials/csection.png |
| 119 |
|
| 120 |
.. figure:: ../../images/tutorials/laser_beam/04.png |
| 121 |
|
| 122 |
An image from the "Image panel". To display the curve marker, |
| 123 |
select the profile curve and right-click to open the context |
| 124 |
menu, then choose "Markers > Bound to active item". |
| 125 |
|
| 126 |
Another method for measuring background noise, also provided by `PlotPy <https://github.com/PlotPyStack/plotpy>`, involves using the "Image statistics" tool |
| 127 |
|imagestats| from the vertical toolbar on the left side of the visualization panel. |
| 128 |
This tool displays statistical information for a rectangular region that you define by dragging the mouse |
| 129 |
across the image. This analysis confirms that the background noise level is approximately 30 lsb. |
| 130 |
|
| 131 |
.. figure:: ../../images/tutorials/laser_beam/05.png |
| 132 |
|
| 133 |
The "Image statistics" tool |
| 134 |
|imagestats| in the vertical toolbar. |
| 135 |
|
| 136 |
.. |imagestats| image:: ../../images/tutorials/imagestats.png |
| 137 |
|
| 138 |
Note that these tools are not persistent: the analysis results disappear when you select |
| 139 |
another image, they are intended to provide a fast insight on the image data. |
| 140 |
|
| 141 |
Now we can clip the image at 35 lsb to remove the background noise |
| 142 |
using the "Processing > Level Adjustment > Clipping..." menu. |
| 143 |
|
| 144 |
.. figure:: ../../images/tutorials/laser_beam/05b.png |
| 145 |
|
| 146 |
The two original and the clipped images are displayed side by side in the |
| 147 |
"Image view" (using the "Distribute on a grid" feature seen previously). |
| 148 |
|
| 149 |
Beam size measurement |
| 150 |
--------------------- |
| 151 |
|
| 152 |
We can now compute the centroid of the beam—that is, the position of its center of mass. |
| 153 |
To do this, select "Analysis > Centroid" from the menu. |
| 154 |
|
| 155 |
.. figure:: ../../images/tutorials/laser_beam/06.png |
| 156 |
|
| 157 |
The centroid position is displayed on the image. |
| 158 |
|
| 159 |
Next, we can extract a line profile along the horizontal axis using |
| 160 |
"Analysis > Intensity profiles > Line profile". Set the row position to the |
| 161 |
previously computed centroid position (i.e., 668) using the "Set Parameters" button. |
| 162 |
See :ref:`tutorial_fabry_perot` for more details on intensity profile extraction. |
| 163 |
|
| 164 |
The intensity profile will be displayed in the "Signal panel". We can then fit the profile |
| 165 |
to a Gaussian function using "Processing > Fitting > Gaussian fit". Here we have |
| 166 |
selected both signals for comparison. |
| 167 |
|
| 168 |
.. figure:: ../../images/tutorials/laser_beam/08.png |
| 169 |
|
| 170 |
The intensity profile fitted to a Gaussian function. Here both signals are |
| 171 |
selected. |
| 172 |
|
| 173 |
Now let's explore another method to compute the FWHM. Returning to the intensity profile signal, |
| 174 |
we can directly compute the FWHM using "Analysis > Full width at half maximum". |
| 175 |
You can choose the estimation method based on your curve characteristics |
| 176 |
and optionally specify the interval to consider for this computation. Once complete, |
| 177 |
the results window will display the FWHM value, which is stored in the metadata and |
| 178 |
shown on the curve. |
| 179 |
|
| 180 |
.. figure:: ../../images/tutorials/laser_beam/09.png |
| 181 |
|
| 182 |
The popup that allows to choose the method to estimate the FWHM. |
| 183 |
|
| 184 |
.. figure:: ../../images/tutorials/laser_beam/10.png |
| 185 |
|
| 186 |
The FWHM result shown in the popup and over the curve. |
| 187 |
|
| 188 |
.. |show_titles| image:: ../../../datalab/data/icons/view/show_titles.svg |
| 189 |
:width: 24px |
| 190 |
:height: 24px |
| 191 |
:class: dark-light no-scaled-link |
| 192 |
|
| 193 |
Let's also try another method to measure the beam size by returning to the image. |
| 194 |
|
| 195 |
From the "Image panel", we can extract the radial intensity profile using |
| 196 |
"Analysis > Intensity profiles > Radial profile". The radial intensity profile |
| 197 |
can be computed around the centroid position, the center of the image, |
| 198 |
or a user-defined position, depending on your data. |
| 199 |
For our data, which appears to have radial symmetry with a center not necessarily |
| 200 |
identical to the image center, the best option is the centroid position. |
| 201 |
|
| 202 |
.. figure:: ../../images/tutorials/laser_beam/11.png |
| 203 |
|
| 204 |
The options available for the Radial Profile computation. |
| 205 |
|
| 206 |
.. figure:: ../../images/tutorials/laser_beam/12.png |
| 207 |
|
| 208 |
The radial intensity profile displayed in the "Signal panel". It is smoother |
| 209 |
than the line profile, because it is computed from a larger number of pixels, |
| 210 |
thus averaging the noise. |
| 211 |
|
| 212 |
Apply these operations to all the images |
| 213 |
---------------------------------------- |
| 214 |
|
| 215 |
All the operations and computations performed on a single image can |
| 216 |
be applied to all images in the "Image panel". |
| 217 |
|
| 218 |
To begin, clean the "Signal panel" using "Edit > Delete all" or |
| 219 |
the |delete_all| button in the toolbar. Also remove intermediate results |
| 220 |
from the "Image panel" by selecting the images created during prototyping |
| 221 |
and deleting them individually using "Edit > Remove" or the |delete| button. |
| 222 |
|
| 223 |
.. |delete_all| image:: ../../../datalab/data/icons/edit/delete_all.svg |
| 224 |
:width: 24px |
| 225 |
:height: 24px |
| 226 |
:class: dark-light no-scaled-link |
| 227 |
|
| 228 |
.. |delete| image:: ../../../datalab/data/icons/edit/delete.svg |
| 229 |
:width: 24px |
| 230 |
:height: 24px |
| 231 |
:class: dark-light no-scaled-link |
| 232 |
|
| 233 |
Next, select all images in the "Image panel" (individually or by selecting |
| 234 |
the entire group "g001"). |
| 235 |
|
| 236 |
Apply the clipping operation to all images, then extract the radial intensity |
| 237 |
profiles for all images (after selecting the entire group "g002"—it should be |
| 238 |
automatically selected if you had "g001" selected before applying the threshold). |
| 239 |
|
| 240 |
.. figure:: ../../images/tutorials/laser_beam/13.png |
| 241 |
|
| 242 |
The clipping applies to all images of the group. |
| 243 |
|
| 244 |
.. figure:: ../../images/tutorials/laser_beam/14.png |
| 245 |
|
| 246 |
The "Signal panel" now contains all the radial intensity profiles. |
| 247 |
|
| 248 |
We can now compute the FWHM for all radial intensity profiles. The "Results" dialog |
| 249 |
will display the FWHM values for all profiles. |
| 250 |
|
| 251 |
.. figure:: ../../images/tutorials/laser_beam/15.png |
| 252 |
|
| 253 |
The "Results" dialog displays the FWHM values for all the profiles. |
| 254 |
|
| 255 |
.. note:: |
| 256 |
|
| 257 |
To display the analysis results again, select "Show results" |
| 258 |
|show_results| from the "Analysis" menu, or click the "Show results" |show_results| |
| 259 |
button below the image list: |
| 260 |
|
| 261 |
.. image:: ../../images/tutorials/fabry_perot/12.png |
| 262 |
|
| 263 |
.. |show_results| image:: ../../../datalab/data/icons/analysis/show_results.svg |
| 264 |
:width: 24px |
| 265 |
:height: 24px |
| 266 |
:class: dark-light no-scaled-link |
| 267 |
|
| 268 |
Finally, we can plot the beam size as a function of position along the |
| 269 |
propagation axis using the "Plot results" feature |plot_results| |
| 270 |
from the "Analysis" menu. This feature allows you to plot result datasets by |
| 271 |
selecting the x and y axes from the available result columns. Here, we will |
| 272 |
plot the FWHM values (`L`) as a function of the image index (`Indices`). |
| 273 |
|
| 274 |
.. figure:: ../../images/tutorials/laser_beam/16.png |
| 275 |
|
| 276 |
The "Plot results" feature |plot_results| |
| 277 |
in the "Analysis" menu. |
| 278 |
|
| 279 |
.. |plot_results| image:: ../../../datalab/data/icons/analysis/plot_results.svg |
| 280 |
:width: 24px |
| 281 |
:height: 24px |
| 282 |
:class: dark-light no-scaled-link |
| 283 |
|
| 284 |
.. figure:: ../../images/tutorials/laser_beam/17.png |
| 285 |
|
| 286 |
The beam size as a function of position along the |
| 287 |
propagation axis (the position is in arbitrary units—the image index). |
| 288 |
|
| 289 |
We can also calibrate the X and Y axes using "Processing > Linear calibration". |
| 290 |
Here we set the X axis to the position in mm (entering the title and |
| 291 |
unit in the "Properties" group box) using the formula: |
| 292 |
:math:`X[\textrm{mm}] = 0.5 \cdot i + 10` where :math:`i` is the image index. |
| 293 |
|
| 294 |
.. figure:: ../../images/tutorials/laser_beam/18.png |
| 295 |
|
| 296 |
The calibrated beam size as a function of the position along the |
| 297 |
propagation axis (the position is now in mm). |
| 298 |
|
| 299 |
Finally, we can save the workspace to a file |filesave_h5|. The workspace contains |
| 300 |
all the images and signals that were loaded or processed in DataLab. It also contains |
| 301 |
the analysis results, the visualization settings (colormaps, contrast, etc.), the |
| 302 |
metadata, and the annotations. |
| 303 |
|
| 304 |
.. |filesave_h5| image:: ../../../datalab/data/icons/io/filesave_h5.svg |
| 305 |
:width: 24px |
| 306 |
:height: 24px |
| 307 |
:class: dark-light no-scaled-link |
| 308 |
|
| 309 |
If you want to load the workspace again, you can use the "File > Open HDF5 file..." |
| 310 |
(or the |fileopen_h5| button in the toolbar) to load the whole workspace, or the |
| 311 |
"File > Browse HDF5 file..." (or the |h5browser| button in the toolbar) to load |
| 312 |
only a selection of data sets from the workspace. |
| 313 |
|
| 314 |
.. |fileopen_h5| image:: ../../../datalab/data/icons/io/fileopen_h5.svg |
| 315 |
:width: 24px |
| 316 |
:height: 24px |
| 317 |
:class: dark-light no-scaled-link |
| 318 |
|
| 319 |
.. |h5browser| image:: ../../../datalab/data/icons/h5/h5browser.svg |
| 320 |
:width: 24px |
| 321 |
:height: 24px |
| 322 |
:class: dark-light no-scaled-link |