Mask Design¶
This module provides utilities to create different types of masks (CodedAperture,
PhaseContour,
FresnelZoneAperture) and simulate the corresponding PSF.
Abstract Mask Class¶
- class lensless.hardware.mask.Mask(resolution, distance_sensor=None, size=None, feature_size=None, psf_wavelength=[4.6e-07, 5.5e-07, 6.4e-07], use_torch=False, torch_device='cpu', centered=True, **kwargs)[source]¶
Parent
Maskclass. Attributes common to each type of mask.- __init__(resolution, distance_sensor=None, size=None, feature_size=None, psf_wavelength=[4.6e-07, 5.5e-07, 6.4e-07], use_torch=False, torch_device='cpu', centered=True, **kwargs)[source]¶
Constructor from parameters of the user’s choice.
- Parameters
resolution (array_like) – Resolution of the mask (px).
distance_sensor (float) – Distance between the mask and the sensor (m). Needed to simulate PSF.
size (array_like) – Size of the mask (m). Only one of
sizeorfeature_sizeneeds to be specified.feature_size (float or array_like) – Size of the feature (m). Only one of
sizeorfeature_sizeneeds to be specified.psf_wavelength (list, optional) – List of wavelengths to simulate PSF (m). Default is [460e-9, 550e-9, 640e-9] nm (blue, green, red).
use_torch (bool, optional) – If True, the mask is created as a torch tensor. Default is False.
torch_device (str, optional) – Device to use for torch tensor. Default is ‘cpu’.
centered (bool, optional) – If True, the mask is centered. Default is True.
- compute_psf(distance_sensor=None, wavelength=None, intensity=True)[source]¶
Compute the intensity PSF with bandlimited angular spectrum (BLAS) for each wavelength. Common to all types of masks.
- abstract create_mask()[source]¶
Abstract mask creation method that creates mask with subclass-specific function.
- classmethod from_sensor(sensor_name, downsample=None, **kwargs)[source]¶
Constructor from an existing virtual sensor that copies over the sensor parameters (sensor resolution, sensor size, feature size).
- Parameters
sensor_name (str) – Name of the sensor. See
SensorOptions.downsample (float, optional) – Downsampling factor.
**kwargs – Additional arguments for the mask constructor. See the abstract class
Maskand the corresponding subclass for more details.
Example
mask = CodedAperture.from_sensor(sensor_name=SensorOptions.RPI_HQ, downsample=8, ...)
Coded Aperture (FlatCam)¶
- class lensless.hardware.mask.CodedAperture(method='MLS', n_bits=8, **kwargs)[source]¶
Coded aperture mask as in FlatCam.
- __init__(method='MLS', n_bits=8, **kwargs)[source]¶
Coded aperture mask contructor (FlatCam).
- Parameters
method (str) – Pattern generation method (MURA or MLS). Default is
MLS.n_bits (int, optional) – Number of bits for pattern generation, must be prime for MURA. Results in
2^n - 1``x``2^n - 1for MLS. Default is 8 (for a 255x255 MLS mask).**kwargs – The keyword arguments are passed to the parent class
Mask.
- get_conv_matrices(img_shape)[source]¶
Get theoretical left and right convolution matrices for the separable mask.
Such that measurement model is given
P @ img @ Q.T.
- is_prime(n)[source]¶
Assess whether a number is prime or not.
- Parameters
n (int) – The number we want to check.
Phase Contour (PhlatCam)¶
- class lensless.hardware.mask.PhaseContour(noise_period=(16, 16), refractive_index=1.2, n_iter=10, design_wv=5.32e-07, **kwargs)[source]¶
Phase contour mask as in PhlatCam.
- __init__(noise_period=(16, 16), refractive_index=1.2, n_iter=10, design_wv=5.32e-07, **kwargs)[source]¶
Phase contour mask contructor (PhlatCam).
- Parameters
noise_period (array_like, optional) – Noise period of the Perlin noise (px). Default is (8, 8).
refractive_index (float, optional) – Refractive index of the mask substrate. Default is 1.2.
n_iter (int, optional) – Number of iterations for the phase retrieval algorithm. Default is 10.
design_wv (float, optional) – Wavelength used to design the mask (m). Default is 532e-9, as in the PhlatCam paper.
**kwargs – The keyword arguments are passed to the parent class
Mask.
Fresnel Zone Aperture¶
Trainable Mask¶
- class lensless.hardware.trainable_mask.TrainableMask(optimizer='Adam', lr=0.001, **kwargs)[source]¶
Abstract class for defining trainable masks.
The following abstract methods need to be defined:
get_psf: returning the PSF of the mask.project: projecting the mask parameters to a valid space (should be a subspace of [0,1]).
- __init__(optimizer='Adam', lr=0.001, **kwargs)[source]¶
Base constructor. Derived constructor may define new state variables
- abstract get_psf()[source]¶
Abstract method for getting the PSF of the mask. Should be fully compatible with pytorch autograd.
- Returns
The PSF of the mask.
- Return type
- class lensless.hardware.trainable_mask.TrainablePSF(initial_psf, grayscale=False, **kwargs)[source]¶
Class for defining an object that directly optimizes the PSF, without any constraints on what can be realized physically.
- Parameters
grayscale (bool, optional) – Whether mask should be returned as grayscale when calling
get_psf. Otherwise PSF will be returned as RGB. By default False.
- __init__(initial_psf, grayscale=False, **kwargs)[source]¶
Base constructor. Derived constructor may define new state variables