drtk.filter2d#

FilterType

Filter families supported by make_resampling_kernel().

FilterOptions

Options used to construct filter2d resampling kernels.

resample_filter

Resample an NCHW tensor with a separable 1D filter.

filter

Filter an NCHW tensor without changing its spatial size.

low_pass_filter

Low-pass filter an NCHW tensor without changing its spatial size.

downsample

Downsample an NCHW tensor by downsample_factor.

upsample

Upsample an NCHW tensor by upsample_factor.

make_resampling_kernel

Build a 1D low-pass resampling filter.

class drtk.FilterType(*values)[source]#

Filter families supported by make_resampling_kernel().

Kaiser = 0#
Lanczos = 1#
class drtk.FilterOptions(n_taps=6, filter_type=FilterType.Kaiser, alias_guard_band=None, alias_suppression_level=None)[source]#

Options used to construct filter2d resampling kernels.

__init__(n_taps=6, filter_type=FilterType.Kaiser, alias_guard_band=None, alias_suppression_level=None)[source]#
Parameters:
  • n_taps – Number of taps. Default is 6. This is not the size of the filter tensor: each output pixel is affected by n_taps input pixels during upsampling, and each input pixel affects n_taps output pixels during downsampling. The filter tensor size is m * n_taps.

  • filter_type – Filter family to build. Default is FilterType.Kaiser.

  • alias_guard_band – Cutoff placement knob for the alias-free GAN low-pass filter design. Must be non-negative; the recommended range is [0, 1]. Default is 0.0 for compatibility. Frequencies are normalized to the input sampling rate. For a given freq_div, the usable bandlimit is bandlimit = 0.5 / freq_div and the transition half-width is transition_half_width = (sqrt(2) - 1) * bandlimit. The filter cutoff is placed at bandlimit - alias_guard_band * transition_half_width. Therefore 0.0 puts the cutoff at the bandlimit; this is the least blurry setting, but the transition band extends past the bandlimit. 1.0 puts the cutoff one transition half-width below the bandlimit, so the transition upper edge reaches the bandlimit. Values between 0.0 and 1.0 interpolate between those placements. Values above 1.0 leave extra guard band and blur more. This parameter does not directly set stopband attenuation; attenuation also depends on n_taps and filter_type.

  • alias_suppression_level – Backward-compatible alias for alias_guard_band.

drtk.resample_filter(x, f, up=1, down=1, padding_mode='reflection')[source]#

Resample an NCHW tensor with a separable 1D filter.

The input is upsampled by interleaving zeros, convolved with f along both spatial dimensions, and downsampled by dropping sample points. The CUDA tensors use the fused kernel. CPU tensors use the native ATen fallback with the same padding and adjoint alignment.

Parameters:
  • x – Input tensor with shape (N, C, H, W).

  • f – 1D filter tensor.

  • up – Upsampling factor. Default is 1, which leaves the input sampling rate unchanged.

  • down – Downsampling factor. Default is 1, which leaves the output sampling rate unchanged.

  • padding_mode – Border handling. Supported values are "zeros" and "reflection". Default is "reflection".

drtk.filter(x, f, padding_mode='reflection')[source]#

Filter an NCHW tensor without changing its spatial size.

Parameters:
  • x – Input tensor with shape (N, C, H, W).

  • f – 1D filter tensor.

  • padding_mode – Border handling. Supported values are "zeros" and "reflection". Default is "reflection".

drtk.low_pass_filter(x, filter_options, freq_div=1.0, padding_mode='reflection')[source]#

Low-pass filter an NCHW tensor without changing its spatial size.

Parameters:
  • x – Input tensor with shape (N, C, H, W).

  • filter_options – Interpolation filter options.

  • freq_div – Frequency divider. The cutoff frequency is reduced by this factor. Default is 1.0.

  • padding_mode – Border handling. Supported values are "zeros" and "reflection". Default is "reflection".

drtk.downsample(x, filter_options, downsample_factor=2, padding_mode='reflection')[source]#

Downsample an NCHW tensor by downsample_factor.

This is the fused equivalent of make_resampling_kernel() followed by resample_filter().

Parameters:
  • x – Input tensor with shape (N, C, H, W).

  • filter_options – Interpolation filter options.

  • downsample_factor – Downsampling factor. Must be at least 1. Default is 2.

  • padding_mode – Border handling. Supported values are "zeros" and "reflection". Default is "reflection".

drtk.upsample(x, filter_options, upsample_factor=2, padding_mode='reflection')[source]#

Upsample an NCHW tensor by upsample_factor.

This is the fused equivalent of make_resampling_kernel() followed by resample_filter().

Parameters:
  • x – Input tensor with shape (N, C, H, W).

  • filter_options – Interpolation filter options.

  • upsample_factor – Upsampling factor. Must be at least 1. Default is 2.

  • padding_mode – Border handling. Supported values are "zeros" and "reflection". Default is "reflection".

drtk.make_resampling_kernel(filter_options, m=1, freq_div=1.0, gain=1.0, device=None)[source]#

Build a 1D low-pass resampling filter.

Parameters:
  • filter_options – Interpolation filter options.

  • m – Upsampling or downsampling factor. Default is 1.

  • freq_div – Frequency divider. The cutoff frequency is reduced by this factor. Default is 1.0.

  • gain – Kernel values sum to this value. Use gain == m when upsampling to preserve signal magnitude. Default is 1.0.

  • device – Device for the returned filter tensor. Default is CPU.