Code reference¶
Refocus 1D/2D fields¶
|
Propagates a 1D or 2D Fourier transformed field |
|
Refocus a 1D or 2D field |
|
Refocus a stack of 1D or 2D fields |
Fourier-domain propagation¶
-
nrefocus._propagate.
fft_propagate
(fftfield, d, nm, res, method='helmholtz', ret_fft=False)[source]¶ Propagates a 1D or 2D Fourier transformed field
- Parameters
fftfield (1-dimensional or 2-dimensional ndarray) – Fourier transform of 1D Electric field component
d (float) – Distance to be propagated in pixels (negative for backwards)
nm (float) – Refractive index of medium
res (float) – Wavelength 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ₘ)
ret_fft (bool) – Do not perform an inverse Fourier transform and return the field in Fourier space.
- Returns
Electric field at d. If ret_fft is True, then the
Fourier transform of the electric field will be returned (faster).
Refocus individual fields¶
-
nrefocus._propagate.
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._propagate.
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 (int) – 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¶
|
Numerical autofocusing of a field using the Helmholtz equation. |
|
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
ret_d (bool) – Return the autofocusing distance in pixels. Defaults to False.
ret_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
same_dist (bool) – Refocus entire sinogram with one distance.
ret_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.
ret_grads (bool) – Return the computed gradients as a list.
num_cpus (int) – Number of CPUs to use
copy (bool) – If False, overwrites input array.
- Returns
- Return type
The focused field (and the refocussing distance + data if d is None)