Filters¶
- cellector.filters.window(image: ndarray, kernel: str | callable | None = 'hanning')[source]¶
Apply a windowing kernel to an image.
- Parameters:
image (np.ndarray) – The image to be windowed. Must have at least 2 dimensions. The windowing will be applied to the last two dimensions of the image.
kernel (np.ndarray or callable (optional, default is "hanning")) – If 2D array, will apply to the image directly (the dimensions must match the last two dimensions of the image). If 1D array, will take the outer product of the array to create a 2D window and apply that to the image. In this case, the image must be square and the kernel must be the same size as the image. If callable (e.g., numpy.hanning), it will be used to create a 2D window kernel by applying it to the last two dimensions (e.g. height_kernel = kernel(height)). Then, the outer product of the height and width kernels will be applied to the image.
- Returns:
The windowed image.
- Return type:
np.ndarray
- cellector.filters.butterworth_bpf(image: ndarray, lowcut: float | None, highcut: float | None, order: float = 1.0)[source]¶
Filter an image using a Butterworth bandpass filter.
This function filters the image in frequency space using by applying a Butterworth transfer function to the image’s Fourier transform. By setting either lowcut or highcut to None, a highpass or lowpass filter can be achieved, respectively. The units of the cutoff frequencies are in pixels.
- Parameters:
image (np.ndarray) – The image to be filtered. Must have at least 2 dimensions. The filtering will be applied to the last two dimensions of the image.
lowcut (float or None) – The lowcut frequency for the bandpass filter. If None, will not filter out low frequencies. In units of pixels.
highcut (float or None) – The highcut frequency for the bandpass filter. If None, will not filter out high frequencies. In units of pixels.
order (float (optional, default is 1)) – The order of the Butterworth filter.
- Returns:
The filtered image.
- Return type:
np.ndarray
- cellector.filters.filter(image, name, **parameters)[source]¶
Filter an image using a particular method with parameters specific to that method.
The filter function is a one-size fits all function that can call any filter method registered in this module. The filtering method is specified by the name parameter, and any parameters required for each method are passed via the parameters dictionary.
Each filtering method uses different parameters, some of which are optional and some of which are required.
- Parameters:
image (np.ndarray) – The image to be filtered.
name (str) – The name of the filtering method to use.
instructions (dict) – A dictionary containing the parameters for the filtering method specified in name.
- Returns:
The filtered image.
- Return type:
np.ndarray
Examples
>>> hanning_windowed = filter(image, "window", kernel="hanning") >>> custom_windowed = filter(image, "window", kernel=custom_1D_window_kernel)