Utility functions

Filtering

Functions for filtering individual images.

PyLorentz.utils.filter.filter_hotpix(image: numpy.ndarray, thresh: float = 30, show: bool = False, maxiters: int = 3, kernel_size: int = 3, fast: bool = False, _current_iter: int = 0, verbose: bool = False) numpy.ndarray[source]

Look for pixel values with an intensity > thresh std outside of the mean of surrounding pixels. If found, replace with the median value of those pixels.

Parameters:
  • image (np.ndarray) – The input image.

  • thresh (float) – Threshold for identifying hot pixels. Default is 30.

  • show (bool) – Whether to display the image with hot pixels identified. Default is False.

  • maxiters (int) – Maximum number of iterations for filtering. Default is 3.

  • kernel_size (int) – Size of the kernel used for local mean calculation. Default is 3.

  • fast (bool) – Whether to use a faster, less accurate method. Default is False.

  • _current_iter (int) – Current iteration count (for internal use). Default is 0.

  • verbose (bool) – Whether to print verbose messages. Default is False.

Returns:

The filtered image.

Return type:

np.ndarray

PyLorentz.utils.filter.extract_patches(array: numpy.ndarray, indices: numpy.ndarray, patch_size: int = 3) numpy.ndarray[source]

Extract patches from an array around the given indices.

Parameters:
  • array (np.ndarray) – The input array.

  • indices (np.ndarray) – The indices around which to extract patches.

  • patch_size (int) – The size of the patches to extract. Default is 3.

Returns:

The extracted patches.

Return type:

np.ndarray

PyLorentz.utils.filter.bandpass_filter(image: numpy.ndarray, sampling: float = 1, q_lowpass: float | None = None, q_highpass: float | None = None, filter_type: str = 'butterworth', butterworth_order: int = 2) numpy.ndarray[source]

Apply a bandpass filter to an image.

Parameters:
  • image (np.ndarray) – The input image.

  • sampling (float) – Scale of the image in pix/nm. Default is 1.

  • q_lowpass (Optional[float]) – Low-pass filter cutoff frequency. Default is None.

  • q_highpass (Optional[float]) – High-pass filter cutoff frequency. Default is None.

  • filter_type (str) – Type of filter to use (“butterworth” or “gaussian”). Default is “butterworth”.

  • butterworth_order (int) – Order of the Butterworth filter. Default is 2.

Returns:

The filtered image.

Return type:

np.ndarray

Other utilties

PyLorentz.utils.utils.dist4(dim, shifted=True) numpy.ndarray[source]

4-fold symmetric distance map (center is 0) even at small radii centered in the middle (i.e. fft shifted) by default

PyLorentz.utils.utils.circ4(dim: int, rad: float)[source]

4-fold symmetric circle even at small dimensions

PyLorentz.utils.utils.norm_image(image: numpy.ndarray | list)[source]

Normalize image intensities to between 0 and 1. Returns copy

PyLorentz.utils.utils.Tukey2D(shape: Tuple[int, int], alpha: float = 0.5, sym: bool = True) numpy.ndarray[source]

Create a 2D Tukey window.

Parameters:
  • shape – Shape of the window (height, width).

  • alpha – Shape parameter of the Tukey window.

  • sym – If True, makes the window symmetric.

Returns:

2D Tukey window.