Code reference¶
Refocus 1D/2D fields¶
fft_propagate |
|
refocus (field, d, nm, res[, method, …]) |
Refocus a 1D or 2D field |
refocus_stack (fieldstack, d, nm, res[, …]) |
Refocus a stack of 1D or 2D fields |
Fourier-domain propagation¶
Refocus individual fields¶
-
nrefocus.
refocus
(field, d, nm, res, method='helmholtz', num_cpus=1, padding=True)[source]¶ Refocus a 1D or 2D field
Parameters: - field (1d or 2d array) – 1D or 2D background corrected electric field (Ex/BEx)
- d (float) – Distance to be propagated in pixels (negative for backwards)
- nm (float) – Refractive index of medium
- res (float) – Wavelenth in pixels
- method (str) –
Defines the method of propagation; one of
- ”helmholtz” : the optical transfer function exp(idkₘ(M-1))
- ”fresnel” : paraxial approximation exp(idk²/kₘ)
- num_cpus (int) – Not implemented. Only one CPU is used.
- padding (bool) –
perform padding with linear ramp from edge to average to reduce ringing artifacts.
New in version 0.1.4.
Returns: Return type: Electric field at d.
Refocus field stacks¶
-
nrefocus.
refocus_stack
(fieldstack, d, nm, res, method='helmholtz', num_cpus=2, copy=True, padding=True)[source]¶ Refocus a stack of 1D or 2D fields
Parameters: - fieldstack (2d or 3d array) – Stack of 1D or 2D background corrected electric fields (Ex/BEx). The first axis iterates through the individual fields.
- d (float) – Distance to be propagated in pixels (negative for backwards)
- nm (float) – Refractive index of medium
- res (float) – Wavelenth in pixels
- method (str) –
Defines the method of propagation; one of
- ”helmholtz” : the optical transfer function exp(idkₘ(M-1))
- ”fresnel” : paraxial approximation exp(idk²/kₘ)
- num_cpus (str) – Defines the number of CPUs to be used for refocusing.
- copy (bool) – If False, overwrites input stack.
- padding (bool) –
Perform padding with linear ramp from edge to average to reduce ringing artifacts.
New in version 0.1.4.
Returns: Return type: Electric field stack at d.
Autofocus 1D/2D fields¶
autofocus (field, nm, res, ival[, roi, …]) |
Numerical autofocusing of a field using the Helmholtz equation. |
autofocus_stack (fieldstack, nm, res, ival[, …]) |
Numerical autofocusing of a stack using the Helmholtz equation. |
Metrics¶
-
nrefocus.metrics.
spectral
(data, lambd, *kwargs)[source]¶ Compute spectral contrast of image
Performs bandpass filtering in Fourier space according to optical limit of detection system, approximated by twice the wavelength.
Parameters: - data (2d ndarray) – the image to compute the norm from
- lambd (float) – wavelength of the light in pixels
Autofocus single fields¶
-
nrefocus.
autofocus
(field, nm, res, ival, roi=None, metric='average gradient', padding=True, ret_d=False, ret_grad=False, num_cpus=1)[source]¶ Numerical autofocusing of a field using the Helmholtz equation.
Parameters: - field (1d or 2d ndarray) – Electric field is BG-Corrected, i.e. field = EX/BEx
- nm (float) – Refractive index of medium.
- res (float) – Size of wavelength in pixels.
- ival (tuple of floats) – Approximate interval to search for optimal focus in px.
- roi (rectangular region of interest (x1, y1, x2, y2)) – Region of interest of field for which the metric will be minimized. If not given, the entire field will be used.
- metric (str) –
- “average gradient” : average gradient metric of amplitude
- ”rms contrast” : RMS contrast of phase data
- ”spectrum” : sum of filtered Fourier coefficients
- padding (bool) –
Perform padding with linear ramp from edge to average to reduce ringing artifacts.
Changed in version 0.1.4: improved padding value and padding location
- red_d (bool) – Return the autofocusing distance in pixels. Defaults to False.
- red_grad (bool) – Return the computed gradients as a list.
- num_cpus (int) – Not implemented.
Returns: - field, [d, [grad]]
- The focused field and optionally, the optimal focusing distance and
- the computed gradients.
Autofocus field stacks¶
-
nrefocus.
autofocus_stack
(fieldstack, nm, res, ival, roi=None, metric='average gradient', padding=True, same_dist=False, ret_ds=False, ret_grads=False, num_cpus=2, copy=True)[source]¶ Numerical autofocusing of a stack using the Helmholtz equation.
Parameters: - fieldstack (2d or 3d ndarray) – Electric field is BG-Corrected, i.e. Field = EX/BEx
- nm (float) – Refractive index of medium.
- res (float) – Size of wavelength in pixels.
- ival (tuple of floats) – Approximate interval to search for optimal focus in px.
- metric (str) – see autofocus_field.
- padding (bool) –
Perform padding with linear ramp from edge to average to reduce ringing artifacts.
Changed in version 0.1.4: improved padding value and padding location
- ret_dopt (bool) – Return optimized distance and gradient plotting data.
- same_dist (bool) – Refocus entire sinogram with one distance.
- red_ds (bool) – Return the autofocusing distances in pixels. Defaults to False. If sam_dist is True, still returns autofocusing distances of first pass. The used refocusing distance is the average.
- red_grads (bool) – Return the computed gradients as a list.
- copy (bool) – If False, overwrites input array.
Returns: Return type: The focused field (and the refocussing distance + data if d is None)