torchcvnn.transforms.FFTResize

class torchcvnn.transforms.FFTResize(size: Tuple[int, ...], axis: Tuple[int, ...] = (-2, -1), scale: bool = False, dtype: str | None = 'complex64')[source]

Resizes an input image in spectral domain with Fourier Transformations.

This transform first applies a 2D FFT to the input array/tensor of shape CHW along specified axes, followed by padding or center cropping to achieve the target size, then applies an inverse FFT to go back to spatial domain. Optionally, it scales the output amplitudes to maintain energy consistency between original and resized images.

Parameters:
  • size – Tuple[int, int] Target dimensions (height, width) for resizing.

  • axis – Tuple[int, …], optional The axes over which to apply FFT. Default is (-2, -1). For a array / tensor of shape CHW, it corresponds to the Height and Width axes.

  • scale – bool, optional If True, scales the output amplitudes to maintain energy consistency with respect to input size. Default is False.

  • dtype – torch.dtype or numpy.dtype, optional Output data type. If None, maintains the input data type. For PyTorch tensors: torch.complex64 or torch.complex128 For NumPy arrays: numpy.complex64 or numpy.complex128

Returns:

numpy.ndarray or torch.Tensor

Resized image as a complex-valued array/tensor, maintaining shape (C, height, width).

Examples

>>> transform = FFTResize((128, 128))
>>> resized_image = transform(input_tensor)  # Resize to 128x128 using FFT

Notes

  • Input must be a multi-dimensional array/tensor of shape Channel x Height x Width.

  • Spectral domain resizing preserves frequency characteristics better than spatial interpolation

  • Operates on complex-valued data, preserving phase information

  • Memory efficient for large downsampling ratios

  • Based on the Fourier Transform properties of scaling and periodicity

  • The output is complex-valued due to the nature of FFT operations. If you are working with real-valued data,

it is recommended to call ToReal after applying this transform.

__init__(size: Tuple[int, ...], axis: Tuple[int, ...] = (-2, -1), scale: bool = False, dtype: str | None = 'complex64') None[source]

Methods

__init__(size[, axis, scale, dtype])