Image Processing Functions

High-level image processing operations using FFT.

Kernels

spectrograms.gaussian_kernel_2d()

Create 2D Gaussian kernel for blurring.

Parameters

sizeint

Kernel size (must be odd, e.g., 3, 5, 7, 9)

sigmafloat

Standard deviation of the Gaussian

Returns

numpy.typing.NDArray[numpy.float64]

Normalized Gaussian kernel with shape (size, size)

Examples

>>> import spectrograms as sg
>>> kernel = sg.gaussian_kernel_2d(5, 1.0)
>>> kernel.shape
(5, 5)
>>> kernel.sum()  # Should be ~1.0
1.0

Convolution

spectrograms.convolve_fft(image, kernel)

Convolve 2D image with kernel using FFT.

Parameters

imagenumpy.typing.NDArray[numpy.float64]

Input image with shape (nrows, ncols)

kernelnumpy.typing.NDArray[numpy.float64]

Convolution kernel (must be smaller than image)

Returns

numpy.typing.NDArray[numpy.float64]

Convolved image (same size as input)

Examples

>>> import spectrograms as sg
>>> import numpy as np
>>> image = np.random.randn(256, 256)
>>> kernel = sg.gaussian_kernel_2d(9, 2.0)
>>> blurred = sg.convolve_fft(image, kernel)

Spatial Filtering

spectrograms.lowpass_filter(image, cutoff_fraction)

Apply low-pass filter to suppress high frequencies.

Parameters

imagenumpy.typing.NDArray[numpy.float64] or Spectrogram

Input image

cutoff_fractionfloat

Cutoff radius as fraction (0.0 to 1.0)

Returns

numpy.typing.NDArray[numpy.float64]

Filtered image

spectrograms.highpass_filter(image, cutoff_fraction)

Apply high-pass filter to suppress low frequencies.

Parameters

imagenumpy.typing.NDArray[numpy.float64]

Input image

cutoff_fractionfloat

Cutoff radius as fraction (0.0 to 1.0)

Returns

numpy.typing.NDArray[numpy.float64]

Filtered image with edges emphasized

spectrograms.bandpass_filter(image, low_cutoff, high_cutoff)

Apply band-pass filter to keep frequencies in a range.

Parameters

imagenumpy.typing.NDArray[numpy.float64] or Spectrogram

Input image

low_cutofffloat

Lower cutoff as fraction (0.0 to 1.0)

high_cutofffloat

Upper cutoff as fraction (0.0 to 1.0)

Returns

numpy.typing.NDArray[numpy.float64]

Filtered image

Feature Enhancement

spectrograms.detect_edges_fft(image)

Detect edges using high-pass filtering.

Parameters

imagenumpy.typing.NDArray[numpy.float64] or Spectrogram

Input image

Returns

numpy.typing.NDArray[numpy.float64]

Edge-detected image

spectrograms.sharpen_fft(image, amount)

Sharpen image by enhancing high frequencies.

Parameters

imagenumpy.typing.NDArray[numpy.float64]

Input image

amountfloat

Sharpening strength (typical range: 0.5 to 2.0)

Returns

numpy.typing.NDArray[numpy.float64]

Sharpened image