drtk.filter2d#
Filter families supported by |
|
Options used to construct filter2d resampling kernels. |
|
Resample an NCHW tensor with a separable 1D filter. |
|
Filter an NCHW tensor without changing its spatial size. |
|
Low-pass filter an NCHW tensor without changing its spatial size. |
|
Downsample an NCHW tensor by |
|
Upsample an NCHW tensor by |
|
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 byn_tapsinput pixels during upsampling, and each input pixel affectsn_tapsoutput pixels during downsampling. The filter tensor size ism * 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 is0.0for compatibility. Frequencies are normalized to the input sampling rate. For a givenfreq_div, the usable bandlimit isbandlimit = 0.5 / freq_divand the transition half-width istransition_half_width = (sqrt(2) - 1) * bandlimit. The filter cutoff is placed atbandlimit - alias_guard_band * transition_half_width. Therefore0.0puts the cutoff at the bandlimit; this is the least blurry setting, but the transition band extends past the bandlimit.1.0puts the cutoff one transition half-width below the bandlimit, so the transition upper edge reaches the bandlimit. Values between0.0and1.0interpolate between those placements. Values above1.0leave extra guard band and blur more. This parameter does not directly set stopband attenuation; attenuation also depends onn_tapsandfilter_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
falong 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 byresample_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 is2.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 byresample_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 is2.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 == mwhen upsampling to preserve signal magnitude. Default is1.0.device – Device for the returned filter tensor. Default is CPU.