These functions, along with the optical propagation functions ahead, were inspired by the descriptions in the book: Numerical Simulation of Optical Wave Propagation with Examples in MATLAB Author(s): Jason D. Schmidt https://spie.org/Publications/Book/866274?SSO=1 He made a wonderful work explaining the ideas, so I recommend going there for a detailed explanation behind them. In any case, all of them share some fundamentals. You need to input the number of pixels of your image, the position of the source (x,y), and the pixel size (the physical size of the mesh grid you want to simulate)
Generates a field with a quadratic profile for both amplitud and phase.
Generates a field with a Gaussian profile for both amplitud and phase.
Generates a field with a sinc profile for both amplitud and phase.
Generates a field were the amplitude is just a circular (small) pupil and no phase (constant phase).
Generates a field were the amplitude is just a single pixel (like a delta).
Discretized version of the Fourier Transform by using DFT
Discretized version of the Inverse Fourier Transform by using DFT
Evaluates the Fraunhoffer diffraction integral between two planes. Returns both the field and the mesh (grid spacing) at the output plane.
Evaluates the Fresnel diffraction integral between two planes. Propagation is done in a single step, which does not allow to choose the grid spacing at the output plane.
Evaluates the Fresnel diffraction integral between two planes. Propagation is done in a two steps, which allows to choose the grid spacing at the output plane.
Evaluates the Fresnel diffraction integral between two planes using the angular spectrum method. As it solves Fresnel, this is assuming paraxial approximation.
Evaluates the Rayleigh-Sommerfeld diffraction integral for the propagation of a field between two planes. No paraxial approximation. Does not take into account evanescent waves, so this method is nice if you want to propagate back and forth between two planes (you should get the exact same field when backgpropagating to the original plane).
Evaluates the Rayleigh-Sommerfeld diffraction integral for the propagation of a field between two planes. No paraxial approximation. Takes into account evanescent waves.
Evaluates the Rayleigh-Sommerfeld diffraction integral for the propagation of a field between two planes. No paraxial approximation. This method was inspired by [fresbek_two_steps] and tries to tackle two main problems. First, when trying to propagate optical fields in microscopy simulations, you usually work with small fields of view (tens or hundreds of microns, typically). But, given that you work with wavelengths in the order of 400-800 nm (in the VIS), your mesh needs to be fine enough to sample these features. This entails that, for example, if you want to sample a 100 microns aperture, with pixel sizes in the order of 200 nm, you would need to use at least 500 pixels for representing your field. This is fine (computers are powerful nowadays), BUT if you want to propagate for long distances (lets say some milimiters or even a few centimeters), Fourier Transform propagation methods start introducing aliasing and the result looks terrible. The conventional solution to this is to do zero-padding, but for long distances the pad sizes become so big that even nowadays computers have memory troubles (you cannot propagate easily images with sizes on the order of tens of megapixels). This method tackles this by breaking the full propagation into several short distance propagations. After each propagation, the mesh can be recalculated (pixels become larger in physical size) and an absorbing window is applied in the borders of the field of view (so you do not need to do a huge zero-padding). The final result is quite good in the center of the field of view, but the border regions become a bit distorted (due to the absorbing window removing energy from the field after each propagation).
Propagates a field from a plane in front of a lens, to the focal plane after the lens (so basically does a Fourier Transform with some scaling).
Plots a single input image (numpy 2D array)
Plots two images (numpy 2D array) side by side
Plots N images (numpy 2D array) in the same window
Shows an animation. Input should be a 3D numpy array, where the third axis corresponds to the frames (individual images)
Plots a 2D scatter plot. Input is a 2D numpy array, where each column corresponds to the X and Y coordinates of a single data point.
Converts complex numbers to RGB color space, where the Saturation value corresponds to the intensity and the Hue and Value encode the phase. This is useful for repsenting intensity + phase distributions into a single image (instead of plotting amplitude and phase individually)
Plots a complex field in a single image (using [z2rgb])
Converts a 2D numpy array into a grayscale Image (PIL library) object, which can be easily exported (as a .png for example)
Stores all the images from a 3D array into individual .png files. Useful for exporting batches of images.
Crops a Region of Interest, centered at the central part of an image.
Crops a Region of Interest, at any given position of an image.
Crops a Region of Interest, with an arbitrary size and at any position of the image. Selection of the ROI is done by using OpenCV, by showing the image on screen and selecting the ROI with the mouse.
Removes a Region of Interest from an image, with an arbitrary size and at any position of the image. Selection of the ROI is done by using OpenCV, by showing the image on screen and selecting the ROI with the mouse. After selecting the first ROI, the function asks if you want to remove additional ROIs.
Builds a circular aperture
Builds a 2D Gaussian profile
Builds a 2D superGaussian profile
Filters an input image in the fourier domain with a given filter
Generates a quadratic phase profile (useful for simulating thin lenses in the paraxial approximation)
Generates a quadratic phase profile
Introduces noise into a signal, with a desired SNR
Correlation coefficient between two images
Cross-correlation between two images
Calculates the SNR of an image
Crops an input image into N subimages. Useful for breaking an image taken after a microlens array into individual subimages from each lenslet.
Merges N subimages into an image
From a raw image taken through a microlens array, calculates the position of the centroid of each microimage.
Estudies correlations between microimages. From an input image, crops into subimages and correlates an individual image with all the others. Then returns the position of the correlation peaks.
Generates a low resolution image from a subaperture image.
Checks if a number is even
Checks if a number is odd
Decomposes an input wavefront into the basis of zernike polynomials
Calculates the [n,m] index from the Noll index [j]
Calculates the Zernike radial function of order [n,m]
Calculates the Zernike polynomial with radial index [n] and azimuthal index [m]
Generates teh zernike polynomial with Noll index [j]
Generates an array of Zernike polynomials (using a list of Noll indexes)
From the partial X,Y derivatives of a wavefront, calculate the zernike decomposition of the original wavefront.
Calculate the phase profile of a wavefront from its zernike decomposition coefficients.
Calculate the 2D gradient of an image
Generates an activation pulse for a neuron. Linear ramp for the rise and an exponential fall. You can tune the ratio between rise/fall, and the exponential decay rate.
Generate a temporal activity trace with many activation pulses.
Crops the central region of a speckle pattern
Removes black borders on the sides of an image
Normalizes the entries of a matrix. Can be used to normalize individual rows/columns independently