DiffractionBlurGenerator
- class deepinv.physics.generator.DiffractionBlurGenerator(psf_size: tuple, num_channels: int = 1, device: str = 'cpu', dtype: type = torch.float32, rng: Generator | None = None, list_param: List[str] = ['Z4', 'Z5', 'Z6', 'Z7', 'Z8', 'Z9', 'Z10', 'Z11'], fc: float = 0.2, max_zernike_amplitude: float = 0.15, pupil_size: Tuple[int] = (256, 256))[source]
Bases:
PSFGenerator
Diffraction limited blur generator.
Generates 2D diffraction kernels in optics using Zernike decomposition of the phase mask (Fresnel/Fraunhoffer diffraction theory).
Zernike polynomials are ordered following the Noll’s sequential indices convention (https://en.wikipedia.org/wiki/Zernike_polynomials#Noll’s_sequential_indices for more details).
- Parameters:
psf_size (tuple) – the shape
H x W
of the generated PSF in 2Dnum_channels (int) – number of images channels. Defaults to 1.
list_param (list[str]) – list of activated Zernike coefficients in Noll’s convention, defaults to
["Z4", "Z5", "Z6","Z7", "Z8", "Z9", "Z10", "Z11"]
fc (float) – cutoff frequency (NA/emission_wavelength) * pixel_size. Should be in
[0, 0.25]
to respect the Shannon-Nyquist sampling theorem, defaults to0.2
.pupil_size (tuple[int]) – this is used to synthesize the super-resolved pupil. The higher the more precise, defaults to
(256, 256)
. If a singleint
is given, a square pupil is considered.
- Examples:
>>> from deepinv.physics.generator import DiffractionBlurGenerator >>> generator = DiffractionBlurGenerator((5, 5), num_channels=3) >>> blur = generator.step() # dict_keys(['filter', 'coeff', 'pupil']) >>> print(blur['filter'].shape) torch.Size([1, 3, 5, 5])
- generate_coeff(batch_size)[source]
Generates random coefficients of the decomposition in the Zernike polynomials.
- Parameters:
batch_size (int) – batch_size.
- Returns:
a tensor of shape (batch_size, len(list_param)) coefficients in the Zernike decomposition.
- step(batch_size: int = 1, coeff: Tensor | None = None, seed: int | None = None)[source]
Generate a batch of PFS with a batch of Zernike coefficients
- Parameters:
batch_size (int) – batch_size.
coeff (torch.Tensor) – batch_size x len(list_param) coefficients of the Zernike decomposition (defaults is None)
seed (int) – the seed for the random number generator.
- Returns:
dictionary with keys ‘filter’: tensor of size (batch_size x num_channels x psf_size[0] x psf_size[1]) batch of psfs, ‘coeff’: list of sampled Zernike coefficients in this realization, ‘pupil’: the pupil function
- Return type: