Function Reference
Classes
Provides object-oriented access to core functionality of PyHoloscope. See Holo class for details.
Stores a propagator used for numerical refocusing. See Propagator class for details.
Stores a refocus stack, allowing convenient access to each image and ability to write stack to a file. See FocusStack class for details.
Stores a propagator look up table for faster refocusing across multiple depths. See PropLUT class for details.
Region of interest, a rectangle with top left coordinates (x, y) with width width and height height. crop method is used to extract the ROI
from an image and constrain method is used to limit coordinates to adjust the ROI to fit within an image. See Roi class for details.
General Functions
- pyholoscope.fourier_plane_display(img)
Returns a real, log-scale Fourier plane for display purposes.
- Arguments:
- imgnumpy.ndarray
2D numpy array, real or complex.
- Returns:
numpy.ndarray : 2D real array, log scale of the Fourier plane.
- pyholoscope.pre_process(img, background=None, normalise=None, window=None, downsample=1.0, numba=False, precision='single')
Carries out steps required prior to refocusing. This includes background correction, normalisation and windowing and downsampling. It also coverts image to either type depending in specified precision (default is single precision).
- Parameters:
- imgnumpy.ndarray
raw hologram, 2D array, real or complex
- Keyword Arguments:
- backgroundnumpy.ndaarray
backround hologram to be subtracted 2D real array (default = None)
- normalisenumpy.ndarray
background hologram to be divided 2D real array (default = None)
- windownumpy.ndarray
window to smooth edges. 2D real array. Will be resized to match size of img if necessary. (default = None)
- downsamplefloat
factor to downsample image by (default = 1)
- numbabool
flag to use numba for speed up (default = False)
- precisionstr
‘single’ or ‘double’ (default = ‘single’)
- Returns:
numpy.ndarray : pre-processed hologram, 2D array, real or complex
Off-axis Holography
- pyholoscope.off_axis_demod(hologram, crop_centre, crop_radius, real_fft=False, return_full=False, return_fft=False, mask=None, cuda=False)
Removes spatial modulation from off-axis hologram to obtain complex field.
By default, returns the complex field as a 2D numpy array of size 2 * crop_radius. If return_full is True, the returned array will instead by the same size as the input hologram. If return_fft is True, function returns a tuple (field, FFT) where FFT is a log scaled image of the FFT of the hologram (2D numpy array, real).
- Arguments:
- hologramnumpy.ndarray
2D numpy array, real, raw hologram
- crop_centretuple of (int, int).
pixel location in FFT of modulation frequency (y, x)
- crop_radiusint or (int, int)
semi-diameter of sqaure or rectangle to extract around modulation frequency. Provide a single int for a sqaure area or a tuple of (h,w) for a rectangle.
- Keyword Arguments:
- real_fftboolean
if True, the real FFT will be used for speed up (default is False). This only works if the reference is tilted so that the modulation is at an angle of approximately 45 degrees to the x and y axes, so that the shifted (modulated) signal is in one quadrant of the FFT.
- return_fullboolean
if True, the returned reconstruction will be the same size as the input hologram, otherwise it will be 2 * crop_radius. (Default is False)
- return_fftboolean
if True will return a tuple of (demod image, log scaled FFT) for display purposes (Default is False)
- maskndarray
2D complex array. Custom mask to use around demodulation frequency. Must match size of (crop_radius_x, crop_radius_y)
- cudaboolean
if True GPU will be used if available.
- Returns:
- numpy. ndarrayreconstructed field as complex numpy array or
tuple of (ndarray, ndarray) if return_fft is True
- pyholoscope.off_axis_find_mod(hologram, mask_fraction=0.1, real_fft=False)
Finds the location of the off-axis holography modulation peak in the FFT.
- Arguments:
- hologramndarray
2D numpy array, real, raw hologram
- Keyword Arguments:
- mask_fractionfloat
between 0 and 1, fraction of image around d.c. to mask to avoid the d.c. peak being detected (default = 0.1).
- real_fftbool
if True, then the real FFT will be used (default is False). This only works if the reference is tilted so that the modulation is at an angle of appoximately 45 degrees to the x and y axes, so that the shifted (modulated) signal is in one quadrant of the FFT.
- Returns:
tuple of (int, int), modulation location in FFT (x location, y location)
- pyholoscope.off_axis_find_crop_radius(hologram, mask_fraction=0.1, real_fft=False)
Estimates the off-axis crop radius based on modulation peak position. If the hologram is square, this is the radius of a circle, otherwise if it is rectangular than the crop radius is a tuple of (y radius, x radius), corresponding to half the lengths of the two axes of an ellipse.
- Arguments:
- hologramnumpy.ndarray
raw hologram, 2D real array
- Keyword Arguments:
- mask_fractionfloat
between 0 and 1, fraction of image around d.c. to mask to avoid the d.c. peak being detected (default = 0.1).
- real_fftbool
if True, then the real FFT will be used (default is False). This only works if the reference is tilted so that the modulation is at an angle of appoximately 45 degrees to the x and y axes, so that the shifted (modulated) signal is in one quadrant of the FFT.
- Returns:
tuple of (int, int) = (x radius, y radius)
- pyholoscope.off_axis_predict_mod(wavelength, pixel_size, num_pixels, tilt_angle, rotation=0, real_fft=False)
Predicts the location of the modulation peak in the FFT.
- Arguments:
- wavelegnthfloat
light wavelength in metres
- pixel_sizefloat
hologram physical pixel size in metres
- num_pixelsint or (int, int)
hologram size in pixels. If rectangular, provide a tuple of (h,w) or a 2D numpy array the same shape as the hologram.
- tilt_anglefloat
angle of reference beam on camera in radians
- Keyword Arguments:
- rotationfloat
rotation of tilt with respect to x axis, in radians (default is 0)
- real_fftbool
if True, then the position will be correct for a real FFT.
- Returns:
tuple of (int, int), location of modulation (x pixel, y pixel)
- pyholoscope.off_axis_predict_tilt_angle(hologram, wavelength, pixel_size, mask_fraction=0.1)
Returns the reference beam tilt based on the hologram modulation. The angle is returned in radians.
- Arguments:
- hologramndarray
2D numpy array, real, hologram
- wavelengthfloat
light wavelength in metres
- pixel_sizefloat
hologram physical pixel size in metres
- Optional Keyword Arguments:
- mask_fractionfloat
between 0 and 1, fraction of image around d.c. to mask to avoid the d.c. peak being detected (default = 0.1).
- Returns:
float : tilt angle in radians
- pyholoscope.off_axis_demod_pixel_size(hologram, pixel_size, crop_radius)
Return effective pixel size after off-axis demodulation.
The off-axis demodulated field is smaller than the hologram by a factor determined by the crop radius. Where a non-square crop area is used, the vertical dimensions are used - in practice this should not matter as the aspect ratio of the crop area and the full hologram are normally the same.
- Arguments:
- hologramtuple or ndarray
shape of the raw hologram (or the hologram itself)
- pixel_sizefloat
pixel size of the raw hologram
- crop_radiusint or (int, int)
crop radius used for off-axis demodulation
- Returns:
float : pixel size in the demodulated field
Numerical Refocusing
- pyholoscope.focus_score(img, method)
Returns score of how ‘in focus’ an amplitude image is. Score is returned as a float, the lower the better the focus.
- Arguments:
- imgnumpy.ndarray
image to score, 2D real array
- methodstr or callable
scoring method name, or a callable accepting a 2D array and returning a float (lower is better). Built-ins are: ‘Brenner’, ‘Sobel’, ‘SobelVariance’, ‘Var’, ‘DarkFocus’ or ‘Peak’.
- Returns:
float : focus score
- pyholoscope.find_focus(img, wavelength, pixel_size, depth_range, method, **kwargs)
Determines the refocus depth which maximises the focus metric on image.
To depth score using only a subset of the image, provide an instance of Roi as score_roi. Note that the entire image will still be refocused, i.e. this does not provide a speed improvement.
To refocus only a small region of the image around the ROI (which is faster), provide a margin in margin, a region with this margin around the ROI will then be refocused. A pre-computed propagator LUT, an instance of prop_lut, can be provided in prop_lut. Note that if margin is specified, the propagator LUT must be of the correct size, i.e. the same size as the area to be refocused.
- Parameters:
- pixel_sizefloat
real pixel size of hologram
- wavelengthfloat
wavelength of light source
- depth_rangetuple of (float, float)
min and max depths to search between
- methodstr or callable
scoring method (see focus_score for list)
- Keyword Arguments:
- backgroundndarray or None
background image (default is None)
- windowndarray or None
spatial window (default is None)
- score_roiROI or None
region of image to apply scoring to (default is None, in which case it applies to whole image.)
- marginint or None
if not none, only a region with this margin around the score_roi will be refocused prior to scoring
- prop_lutprop_lut or None
propagator look up table (default is None)
- use_numbaboolean
if True, uses Numba version of functions (default is False)
- use_cudaboolean
if True, uses GPU where available
- pyholoscope.focus_score_curve(img, wavelength, pixel_size, depth_range, nPoints, method, **kwargs)
Produces a plot of focus score against depth, mainly useful for debugging erroneous focusing.
- Arguments:
- imgndarray
2D numpy array, raw hologram
- wavelengthfloat
wavelength of light source
- pixel_sizefloat
real pixel size of hologram
- depth_rangetuple of (float, float)
min and max depths to search between
- nPointsint
number of points to search between depth_range
- methodfunc
scoring method (see focus_scores for list)
- Keyword Arguments:
- backgroundndarray or None
background image (default is None)
- windowndarray or None
spatial window (default is None)
- score_roiROI or None
region of image to apply scoring to (default is None, in which case it applies to whole image.)
- marginint or None
if not none, only a region with this margin around the score_roi will be refocused prior to scoring
- precisionstr
‘single’ (default) or ‘double’
- use_numbaboolean
if True, uses Numba version of functions (default is False)
- use_cudaboolean
if True, uses GPU where available
- pyholoscope.get_focus_score_methods()
Returns a list of available focus scoring method names.
- pyholoscope.propagator(grid_size, wavelength, pixel_size, depth, propagation_method='angular_spectrum', precision='single', use_numba=True, correct_pixel_size=False, source_distance=None)
Creates Fourier domain propagator for numerical refocusing. Returns the propagator as an instance of Propagator. Generation is sped up by only calculating top left quadrant and then duplicating (with flips) to create the other quadrants.
Wavelength, pixel_size and depth are all specified in the same units.
- Arguments:
- grid_sizefloat or (float, float)
size of square image (in pixels) to refocus, or if tuple of (float, float), size of rectangular image as height x width
- wavelengthfloat
wavelength of light
- pixel_sizefloat
physical size of pixels
- depthfloat
refocus distance
- Keyword Arguments:
- propagation_methodstr
wave propagation model, ‘angular_spectrum’ (default) or ‘fresnel’
- precisionstr
numerical precision of output, ‘single’ (default) or ‘double’
- use_numbaboolean
if True, uses Numba version of functions (default is True)
- correct_pixel_sizebool
if True, pixel_size is corrected for effective magnification from finite source distance
- source_distancefloat or None
source-to-image-plane distance in same units as pixel_size and depth. Required if correct_pixel_size is True
- Returns:
numpy.ndarray : 2D complex array, propagator
- pyholoscope.propagator_numba(grid_size, wavelength, pixel_size, depth, propagation_method='angular_spectrum', precision='single')
Numba optimised version of propagator(). Creates Fourier domain propagator for angular spectrum method. Returns the propagator as a complex 2D numpy array. Generation is sped up by only calculating top left quadrant and then duplicating (with flips) to create the other quadrants.
Note that ‘precision’ is currently not implemented in the numba version.
- Parameters:
- gridSize(int, int)
size of image (in pixels) to refocus, height x width
- pixelSizefloat
physical size of pixels
- wavelengthfloat
in same units as pixelSize
- depthfloat
refocus depth in same units as pixelSize
- Keyword Arguments:
- propagation_methodstr
wave propagation model, ‘angular_spectrum’ (default) or ‘fresnel’
- precisionstr
numerical precision of ouptut, ‘single’ (defualt) or ‘double’ [NOT IMPLEMENTED]
- pyholoscope.propagator_size_for_roi(img_shape, roi=None, margin=None)
Returns required propagator size for ROI + margin refocusing.
- Arguments:
- img_shapetuple or ndarray
shape of full image, or image itself
- roiRoi or None
region of interest used for scoring
- marginint or None
margin around the ROI used for refocusing
- Returns:
tuple (int, int) : (height, width) of propagator needed
- pyholoscope.refocus(img, propagator, **kwargs)
Refocuses a hologram using the angular spectrum method. Takes a hologram ‘hologram’ wich may be a real or complex 2D numpy array (with any pre-processing such as background removal already performed) and a pre-computed ‘propagator’ which can be generated using the function ‘propagator()’.
- Arguments:
- imgndarray
2D numpy array, raw hologram.
- propagatorinstance of Propagator
propagator object, containing the propagator as a 2D numpy array, as returned from propagator().
- Keyword Arguments:
- backgroundnumpy.ndarray or None
background image to subtract prior to refocus, same shape as img (default is None)
- normalisenumpy.ndarray or None
normalisation image to divide by prior to refocus, same shape as img (default is None)
- windownumpy.ndarray or None
spatial window to apply to image prior to refocus, same shape as img (default is None)
- downsampleint or None
downsample factor, if not None, the image will be downsampled by this factor prior to refocus (default is None)
- fourier_domainboolean
if True then img is assumed to be already the FFT of the hologram, useful for speed when performing multiple refocusing of the same hologram. (default is False)
- cudaboolean
if True (default) GPU will be used if available.
- otherspass any keyword arguments from pre_process() to
apply this pre-processing prior to refocusing
- Returns:
numpy.ndarray : 2D complex array, refocused image
- pyholoscope.refocus_and_score(depth, img_fft, pixel_size, wavelength, method, score_roi=None, prop_lut=None, use_numba=False, use_cuda=False, propagation_method='angular_spectrum', precision='single')
Refocuses an image to specificed depth and returns focus score, used by findFocus.
- Parameters:
- depthfloat
depth to focus to
- img_fftndarray, complex
FFT of hologram
- pixel_size: float
real pixel size of hologram
- wavelength: float
wavelength of light source
- methodlist of (str or callable) or str/callable,
scoring method (see focus_score for list). If a list is provided, a list of scores will be returned, one for each method, otherwise if a single method is provided as a string or callable, then a single score will be returned.
- Keyword Arguments:
- score_roiROI or None
region of image to apply scoring to (default is None, in which case it applies to whole image.)
- prop_lutprop_lut or None
propgator look-up table (default is None, propagator is calculate for each depth)
- use_numbaboolean
if True, uses Numba version of functions (default is False)
- use_cudaboolean
if True, uses GPU where available
- precisionstr
‘single’ (default) or ‘double’, precision of calculated propagator
- Returns:
list of floats or float : either a list of scores or a single score.
- pyholoscope.refocus_stack(img, wavelength, pixel_size, depth_range, num_depths, **kwargs)
Generates a stack of images by refocusing a hologram to multiple depths.
- Parameters:
- wavelengthfloat
wavelength of light source
- pixel_sizefloat
real pixel size of hologram
- depth_rangetuple of (float, float)
min and max depths of stack
- num_depthsint
number of depths to refocus to within depth_range
- Keyword Arguments:
- backgroundndarray or None
background hologram (default is None)
- windowndarray or None
spatial window (default is None)
- precisionstr
‘single’ (default) or ‘double’
- use_numbaboolean
if True, uses Numba version of functions (default is True)
- use_cudaboolean
if True, uses GPU where available
- Returns:
instance of FocusStack
Focus Scoring
- pyholoscope.brenner(img)
Brenner focus metric (lower is better).
- pyholoscope.dark_focus(img)
DarkFocus metric from Optics & Laser Eng. 2020 (lower is better).
- pyholoscope.get_focus_score_methods()
Returns a list of available focus scoring method names.
- pyholoscope.norm_var(img)
Normalised variance focus metric (lower is better).
- pyholoscope.peak(img)
Peak intensity focus metric (lower is better).
- pyholoscope.sobel(img)
Sobel gradient energy focus metric (lower is better).
- pyholoscope.sobel_variance(img)
Variance of Sobel energy focus metric (lower is better).
- pyholoscope.sum_focus(img)
Sum of pixel intensities (lower is better).
- pyholoscope.variance(img)
Intensity standard deviation focus metric (lower is better).
Phase Functions
- pyholoscope.mean_phase(img)
Returns the mean phase of a field or phase map.
- Parameters:
- imgndarray
2D array, real or complex, the field or phase map
- Returns:
float : mean phase of the image.
- pyholoscope.obtain_tilt(img)
Estimates the global tilt in the 2D unwrapped phase.
This can be used to correcte tilts in the phase due to, for example, a tilt in the coverglass. Returns a phase map approximating the tilt as a 2D real numpy array.
- Parameters:
- imgndarray
2D numpy array, real. Unwrapped phase.
- Returns:
numpy.ndarray : 2D real array, map of tilt.
- pyholoscope.phase_gradient(img)
Returns the amplitude of the phase gradient of an image.
This function is able to handle wrapped phase without finding an edge at the wrap points. Returns a 2D numpy array, real containing the amplitude of the gradient at each point.
- Parameters:
- imgndarray
2D numpy array, real or complex, the field or phase map
- Returns:
numpy.ndarray : 2D array of floats, maps of amplitudes of phase gradient.
- pyholoscope.phase_gradient_amp(img)
Returns the amplitude of the phase gradient of an image.
This isn’t very useful by itself if applied to wrapped phase as it find an edge whenever the phase is wrapped, phase_gradient avoids this problem.
- Parameters:
- imgndarray
2D numpy array, real or complex, the field or phase map
- Returns:
numpy.ndarray : 2D arrays of floats, maps of amplitudes of phase gradient.
- pyholoscope.phase_gradient_dir(img)
Returns the directional phase gradient of an image.
The output is a complex 2D numpy array, with the horizontal and vertical gradients encoded in the real and imaginary parts.
- Parameters:
- imgndarray
2D numpy array, real or complex, the field or phase map
- Returns:
numpy.ndarray : 2D complex array, phase gradient image.
- pyholoscope.phase_unwrap(img)
Returns unwrapped version of 2D phase map.
- Parameters:
- imgndarray
2D numpy array. Either complex (the complex field) or float (the wrapped phase).
- Returns:
numpy.ndarray : 2D array of floats, unwrapped phase.
- pyholoscope.relative_phase(img, background)
Removes global phase from image using reference (background) field.
The function works on both fields (complex arrays) and phase maps (real arrays), and returns a corrected field/phase map of the same type.
- Parameters:
- imgnumpy.ndarray
2D numpy array, real or complex. If real it is taken to be phase map, otherwise if complex it is the field.
- backgroundnumpy.ndarray
2D numpy array, real or complex. Backround phase/field to subtract. Must be same type and size as img.
- Returns:
numpy.ndarray : float or complex
- pyholoscope.relative_phase_self(img, roi=None)
Makes the phase in an image relative to the mean phase in either the whole image or a specified ROI of the image.
The function works on either fields (complex arrays) and phase maps (float arrays), and returns a corrected field/phase map of the same type.
- Parameters:
- imgnumpy.ndarray
2D array, real or complex. If real it is taken to be phase map, otherwise if complex it taken to be the complex field.
- Keyword Arguments:
- roipyholoscope.Roi
region of interest to make phase relative to. In the output image the mean phase in this region will be zero. (default = None)
- Returns:
numpy.ndarray : float or complex
- pyholoscope.synthetic_DIC(img, shear_angle=3.141592653589793)
Generates a simple, non-rigorous DIC-style image for display.
The ouput should appear similar to a relief map, with dark and light regions correspnding to positive and negative phase gradients along the shear angle direction (default is horizontal = 0 rad). The input must be the complex field, not a phase map.
- Parameters:
- imgndarray
2D numpy array, complex, the field.
- Keyword Arguments:
- shear_anglefloat
angle in radians of the shear direction. (default = pi)
- Returns:
numpy.ndarray : 2D arrays of floats, the DIC image.
Utility Functions : Loading and Saving
- pyholoscope.load_image(filename)
Loads an image or stack of images from a file. Supports all formats supported by PIL.
- Parameters:
- filenamestr or Path
path to file
- Returns:
numpy.ndarray : 2D, 3D or 4D numpy array representing image or stack
- pyholoscope.save_image(img, file, autoscale=True)
Saves an image stored as numpy array to an 8 bit image file.
- Parameters:
- imgnumpy.ndarray
image to save
- filestr
filename to save to, type will be determined by extension.
- Optional Keyword Arguments:
- autoscaleboolean
if True (default), image is scaled to use full bit depth
- pyholoscope.save_amplitude_image8(img, filename)
Saves amplitude information as an 8 bit tif.
- Parameters:
- imgnumpy.ndarray
image to save
- filestr
filename to load image from, including extension.
- pyholoscope.save_amplitude_image16(img, filename)
Saves amplitude information as a 16 bit tif.
- Parameters:
- imgnumpy.ndarray
image to save
- filestr
filename to load image from, including extension.
- pyholoscope.save_phase_image(img, filename)
Saves phase as 16 bit tif. The phase is scaled so that 2pi = 65536.
- Parameters:
- imgnumpy.ndarray
2D numpy array, either complex field or real (phase map)
- filenamestr
path to file to save to. If exists will be over-written.
Utility Functions : Display
- pyholoscope.cshow(img, dpi=100, figsize=(10, 5), phase_cmap='twilight', amp_cmap='gray', title=None)
Displays a complex image as two subplots, one for amplitude and one for phase.
- Parameters:
- imgnumpy.ndarray
complex image to display
- Keyword Arguments:
- dpiint
resolution of figure in dots per inch (default = 100)
- figsizetuple of (float, float)
size of figure in inches (default = (10, 5))
- phase_cmapstr
name of matplotlib colormap to use for phase (default = ‘twilight’)
- amp_cmapstr
name of matplotlib colormap to use for amplitude (default = ‘gray’)
- titlestr or None
title to set for whole figure (default = None)
- Returns:
tuple of (Figure, (Axes, Axes)) : figure and axes objects from matplotlib
Utility Functions : Image Types
- pyholoscope.get8bit(img)
Returns 8 bit representation of amplitude and phase of field.
Returns a tuple of amplitude and phase, both real 2D numpy arrays of type uint8. Amplitude is scaled between 0 and 255, phase is wrapped and mapped to between 0 and 255, with 0 = 0 radians and 255 = 2pi radians.
- Parameters:
- imgnumpy.ndarray
2D numpy array, complex or real
- Returns:
tuple of (ndarray, ndarray) : 8 bit amplitude and phase maps
- pyholoscope.get16bit(img)
Returns 16 bit representation of amplitude and phase of field.
Returns a tuple of amplitude and phase, both real 2D numpy arrays of type uint16. Amplitude is scaled between 0 and 2^16 -1, phase is mapped to between 0 and 2^16 - 1, with 0 = 0 radians and 2^16 - 1 = 2pi radians.
- Parameters:
- imgnumpy.ndarray
2D numpy array, complex or real
- Returns:
tuple of (ndarray, ndarray) : 16 bit amplitude and phase maps
- pyholoscope.magnitude(img)
Returns magnitude of complex image.
- Parameters:
- imgnumpy.ndarray
complex image
- Returns:
numpy.ndarray : magnitude image
- pyholoscope.amplitude(img)
Returns amplitude of complex image. Deprecated, use amp instead.
- Parameters:
- imgnumpy.ndarray
complex image
- Returns:
numpy.ndarray : amplitude image
- pyholoscope.phase(img)
Returns phase of complex image, between 0 and 2pi.
- Parameters:
- imgnumpy.ndarray
complex image
- Returns:
numpy.ndarray : phase map
Utility Functions : Windowing
- pyholoscope.extract_central(img, boxSize=None)
Extracts square of size boxSize*2 from centre of img. If boxSize is not specified, the largest possible square will be extracted.
- Parameters:
- imgnumpy.ndarray
complex or real image
- Keyword Arguments:
- boxSizeint or None
size of square to be extracted
- Returns:
numpy.ndarray : central square from image
- pyholoscope.circ_window(img_size, circle_radius, data_type='float32')
Produces a circular or elipitcal mask on grid of img_size as a numpy array.
- Parameters:
- img_sizeint or (int, int)
size of output array. Provide a single int to generate a square image of that size, otherwise provide (w,h) to produce a rectangular image, or 2D numpy array in which case the size of the array will be used.
- circle_radiusfloat or (float, float)
Pixel values inside this radius will be 1. Provide a tuple of (x,y) to have different x and y radii.
- Keyword Arguments:
- data_typestr
data type of returned array (default is ‘float32’)
- Returns:
numpy.ndarray : 2D numpy array containing mask
- pyholoscope.circ_cosine_window(img_size, circle_radius, skin_thickness, data_type='float32')
Produces a circular or elliptical cosine window mask on grid of img_size as a numpy array.
- Parameters:
- img_sizeint or (int, int)
size of output array. Provide a single int to generate a square
array of that size, otherwise provide (w,h) to produce a rectangular array, or 2D numpy array in which case the size of the array will be used.
- circle_radiusfloat or (float, float)
Pixel values inside this radius will be 1. Provide a tuple of (x,y) to have different x and y radii.
- skin_thicknessfloat
size of smoothed area inside circle/ellipse
- Keyword Arguments:
- data_typestr
data type of returned array (default is ‘float32’)
- Returns:
numpy.ndarray : 2D numpy array containing mask
- pyholoscope.square_cosine_window(img_size, radius=None, skin_thickness=0, data_type='float32')
Produces a square/rectangular cosine window mask on grid of img_size * img_size. Mask is 0 for pixels > radius and 1 for pixels < (radius - skin_thickness). The intermediate region is a smooth squared cosine function.
- Arguments:
- img_sizeint or (int, int)
size of output array. Provide a single int to generate a square
array of that size, otherwise provide (w,h) to produce a rectangular array, or 2D numpy array in which case the size of the array will be used.
- Keyword Arguments:
- radiusfloat or (float, float) or None
Pixel values inside this radius will be 1. Provide a tuple of (x,y) to have different x and y radii. If None (default), the radius will match the size of the image.
- skin_thicknessfloat or None
size of smoothed area inside circle/ellipse. Default is 0.
- data_typestr
data type of returned array (default is ‘float32’)
- Returns:
numpy.ndarray : 2D numpy array containing mask
Utility Functions : Other
- pyholoscope.invert(img)
Inverts an image, largest value becomes smallest and vice versa.
- Parameters:
- imgnumpy.ndarray
numpy array, input image
- Returns:
numpy.ndarray : inverted image
- pyholoscope.dimensions(inp)
Helper to obtain width and height in functions which accept multiple ways to send this information. The input may either be a single value, for a square image, a tuple of (h, w) or a 2D array.
- Parameters:
inp : int or (int, int) or ndarray
- Returns:
tuple of (int, int), height and width
Simulation
- pyholoscope.sim.off_axis(object_field, wavelength, pixel_size, tilt_angle, rotation=0.7853981633974483, OPD=0)
Generates simulated off-axis hologram.
- Arguments:
- object_fieldndarray, complex
complex field representing object
- wavelengthfloat
wavelength of simulated light source
- pixel_sizefloat
real size of pixels in hologram
- tilt_anglefloat
angle of reference beam on camera in radians
- Keyword Arguments:
- rotationfloat
rotation of the tilt with respect to x axis in rad (Default is pi/4 = 45 deg)
OPD : optical path difference between beams (Default is 0)