Skip to content

fft

This module implements wrappers for FFT (Fast Fourier Transform) based plugins.

Classes:

  • DFTTest

    2D/3D frequency domain denoiser using Discrete Fourier transform.

Functions:

  • fft3d

    Applies FFT3DFilter, a 3D frequency-domain filter used for strong denoising and mild sharpening.

Attributes:

  • SLocationT

    A type that represents various ways to specify a location in the frequency domain for denoising operations.

Frequency module-attribute

Frequency: TypeAlias = float

Represents the frequency value in the frequency domain.

The value is a float that represents the magnitude or position in the frequency spectrum.

SLocationT module-attribute

A type that represents various ways to specify a location in the frequency domain for denoising operations.

The SLocationT type can be one of the following:

  • int or float: A single frequency value (for 1D frequency location).
  • DFTTest.SLocation: A structured class for defining frequency locations in a more complex manner.
  • Sequence[Frequency, Sigma]: A sequence (e.g., list or tuple) that alternates between Frequency and Sigma values. The sequence must have an even number of items, where each frequency is followed by its corresponding sigma. For example: [0.0, 8.0, 0.5, 16.0] where 0.0 is the frequency and 8.0 is its corresponding sigma, and so on.
  • Sequence[tuple[Frequency, Sigma]]: A sequence of tuples, where each tuple contains a Frequency and a Sigma.
  • Mapping[Frequency, Sigma]: A dictionary (Mapping) where each Frequency key maps to a corresponding Sigma value.

The sequence or mapping must represent a pairing of frequency and sigma values for denoising operations. In the case of a sequence like Sequence[Frequency, Sigma], it is essential that the number of items is even, ensuring every frequency has an associated sigma.

Sigma module-attribute

Sigma: TypeAlias = float

Represents the sigma value, which is typically associated with noise standard deviation.

Used to indicate the level of noise or variance in the signal, and it is represented as a float value. A higher sigma means more noise in the signal.

DFTTest

DFTTest(
    clip: VideoNode | None = None,
    backend: Backend = AUTO,
    sloc: SLocationT | MultiDim | None = None,
    **kwargs: Any
)

2D/3D frequency domain denoiser using Discrete Fourier transform.

Initializes the DFTTest class with the provided clip, backend, and frequency location.

Example:

dfttest = DFTTest(clip, DFTTest.Backend.OLD)
denoised_low_frequencies = dfttest.denoise({0: 16, 0.25: 8, 0.5:0, 1.0: 0})
denoised_high_frequencies = dfttest.denoise([(0, 0), (0.5, 0), (0.75, 16), (1.0, 32)])

Parameters:

  • clip

    (VideoNode | None, default: None ) –

    Source clip.

  • backend

    (Backend, default: AUTO ) –

    The backend to use processing.

  • sloc

    (SLocationT | MultiDim | None, default: None ) –

    The frequency location for denoising.

  • kwargs

    (Any, default: {} ) –

    Additional parameters to configure the denoising process.

Classes:

  • Backend

    Enum representing available backends on which to run the plugin.

  • FilterType

    Enumeration of filtering types used in DFTTest plugin.

  • SLocation

    A helper class for handling sigma values as functions of frequency in different dimensions.

  • SynthesisType

    Enumeration of synthesis window types used in DFTTest plugin.

Methods:

  • denoise

    Denoises a clip using Discrete Fourier Transform (DFT).

  • extract_freq

    Extracts the frequency domain from the given clip by subtracting the denoised clip from the original.

  • insert_freq

    Inserts the frequency domain from one clip into another by merging the frequency information.

  • merge_freq

    Merges the low and high-frequency components by applying denoising to the low-frequency component.

Attributes:

Source code
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
def __init__(
    self,
    clip: vs.VideoNode | None = None,
    backend: Backend = Backend.AUTO,
    sloc: SLocationT | SLocation.MultiDim | None = None,
    **kwargs: Any
) -> None:
    """
    Initializes the `DFTTest` class with the provided clip, backend, and frequency location.

    Example:
        ```py
        dfttest = DFTTest(clip, DFTTest.Backend.OLD)
        denoised_low_frequencies = dfttest.denoise({0: 16, 0.25: 8, 0.5:0, 1.0: 0})
        denoised_high_frequencies = dfttest.denoise([(0, 0), (0.5, 0), (0.75, 16), (1.0, 32)])
        ```

    :param clip:        Source clip.
    :param backend:     The backend to use processing.
    :param sloc:        The frequency location for denoising.
    :param kwargs:      Additional parameters to configure the denoising process.
    """
    self.clip = clip

    self.backend = backend

    self.default_slocation = sloc
    self.default_args = kwargs

backend instance-attribute

backend = backend

clip instance-attribute

clip = clip

default_args instance-attribute

default_args = kwargs

default_slocation instance-attribute

default_slocation = sloc

Backend

Backend(value: object, **kwargs: Any)

Bases: _BackendBase

Enum representing available backends on which to run the plugin.

Methods:

  • DFTTest

    Applies the DFTTest denoising filter using the plugin associated with the selected backend.

  • __call__

    This method is used to apply the specified backend configuration with provided keyword arguments.

  • resolve

    Resolves the appropriate DFTTest backend to use based on availability.

Attributes:

  • AUTO

    Automatically select the most appropriate backend based on system capabilities.

  • CPU

    Modern CPU backend using optimized multi-threaded CPU code.

  • GCC

    CPU backend compiled with GCC.

  • HIPRTC

    AMD GPU backend using HIPRTC (HIP Runtime Compilation).

  • NVRTC

    NVIDIA GPU backend using NVRTC (NVIDIA Runtime Compilation).

  • OLD

    Legacy DFTTest implementation by HolyWu.

  • cuFFT

    NVIDIA GPU backend using precompiled CUDA and cuFFT.

  • hipFFT

    AMD GPU backend using precompiled HIP and hipFFT.

  • kwargs
  • plugin (Plugin) –

    Returns the appropriate DFTTest plugin based on the current backend.

Source code
668
669
670
def __init__(self, value: object, **kwargs: Any) -> None:
    self._value_ = value
    self.kwargs = kwargs

AUTO class-attribute instance-attribute

AUTO = 'auto'

Automatically select the most appropriate backend based on system capabilities. Typically prioritizes GPU backends if available, otherwise falls back to CPU.

CPU class-attribute instance-attribute

CPU = 'dfttest2_cpu'

Modern CPU backend using optimized multi-threaded CPU code.

GCC class-attribute instance-attribute

GCC = 'dfttest2_gcc'

CPU backend compiled with GCC.

HIPRTC class-attribute instance-attribute

HIPRTC = 'dfttest2_hiprtc'

AMD GPU backend using HIPRTC (HIP Runtime Compilation).

NVRTC class-attribute instance-attribute

NVRTC = 'dfttest2_nvrtc'

NVIDIA GPU backend using NVRTC (NVIDIA Runtime Compilation).

OLD class-attribute instance-attribute

OLD = 'dfttest'

Legacy DFTTest implementation by HolyWu.

cuFFT class-attribute instance-attribute

cuFFT = 'dfttest2_cuda'

NVIDIA GPU backend using precompiled CUDA and cuFFT.

hipFFT class-attribute instance-attribute

hipFFT = 'dfttest2_hip'

AMD GPU backend using precompiled HIP and hipFFT.

kwargs instance-attribute

kwargs = kwargs

plugin property

plugin: Plugin

Returns the appropriate DFTTest plugin based on the current backend.

Returns:

  • Plugin

    The corresponding DFTTest plugin for the resolved backend.

DFTTest

DFTTest(clip: VideoNode, *args: Any, **kwargs: Any) -> ConstantFormatVideoNode

Applies the DFTTest denoising filter using the plugin associated with the selected backend.

Parameters:

  • clip
    (VideoNode) –

    Source clip.

  • *args
    (Any, default: () ) –

    Positional arguments passed to the selected plugin.

  • **kwargs
    (Any, default: {} ) –

    Keyword arguments passed to the selected plugin.

Returns:

  • ConstantFormatVideoNode

    Denoised clip.

Raises:

  • CustomRuntimeError

    If the selected backend is not available or unsupported.

Source code
807
808
809
810
811
812
813
814
815
816
817
def DFTTest(self, clip: vs.VideoNode, *args: Any, **kwargs: Any) -> ConstantFormatVideoNode:
    """
    Applies the DFTTest denoising filter using the plugin associated with the selected backend.

    :param clip:                    Source clip.
    :param *args:                   Positional arguments passed to the selected plugin.
    :param **kwargs:                Keyword arguments passed to the selected plugin.
    :raises CustomRuntimeError:     If the selected backend is not available or unsupported.
    :return:                        Denoised clip.
    """
    ...

__call__

__call__(*, device_id: int = 0, num_streams: int = 1) -> Backend
__call__(*, device_id: int = 0, num_streams: int = 1) -> Backend
__call__(*, device_id: int = 0, in_place: bool = True) -> Backend
__call__(*, device_id: int = 0, in_place: bool = True) -> Backend
__call__(*, opt: int = ...) -> Backend
__call__() -> Backend
__call__(*, opt: int = ...) -> Backend
__call__(**kwargs: Any) -> Backend

This method is used to apply the specified backend configuration with provided keyword arguments.

Depending on the backend, the arguments may represent device IDs, streams, or other backend-specific settings.

Parameters:

  • kwargs
    (Any, default: {} ) –

    Additional configuration parameters for the backend.

Returns:

  • Backend

    The configured backend with applied parameters.

Source code
787
788
789
790
791
792
793
794
795
796
797
798
799
def __call__(self, **kwargs: Any) -> DFTTest.Backend:
    """
    This method is used to apply the specified backend configuration with provided keyword arguments.

    Depending on the backend, the arguments may represent device IDs, streams, or other backend-specific settings.

    :param kwargs:          Additional configuration parameters for the backend.
    :return:                The configured backend with applied parameters.
    """
    new_enum = _BackendBase(self.__class__.__name__, DFTTest.Backend.__members__)  # type: ignore
    member = getattr(new_enum, self.name)
    member.kwargs = kwargs
    return member

resolve cached

resolve() -> Self

Resolves the appropriate DFTTest backend to use based on availability.

If the current instance is not DFTTest.Backend.AUTO, it returns itself. Otherwise, it attempts to select the best available backend.

Returns:

  • Self

    The resolved DFTTest.Backend to use for processing.

Raises:

  • CustomRuntimeError

    If no supported DFTTest implementation is available on the system.

Source code
819
820
821
822
823
824
825
826
827
828
829
830
@cache
def resolve(self) -> Self:
    """
    Resolves the appropriate DFTTest backend to use based on availability.

    If the current instance is not DFTTest.Backend.AUTO, it returns itself.
    Otherwise, it attempts to select the best available backend.

    :raises CustomRuntimeError:     If no supported DFTTest implementation is available on the system.
    :return:                        The resolved DFTTest.Backend to use for processing.
    """
    ...

FilterType

Bases: CustomIntEnum

Enumeration of filtering types used in DFTTest plugin.

These filters define how the real and imaginary parts of each complex DFT coefficient are scaled (via mult) during denoising, based on their power spectrum density (PSD).

The term psd refers to the power spectral density, computed as psd = real² + imag².

Attributes:

  • MULT

    Constant multiplier.

  • MULT_PSD

    Conditional multiplier based on PSD range.

  • MULT_RANGE

    Smooth range-based multiplier.

  • THR

    Hard threshold filter.

  • WIENER

    Generalized Wiener filter.

MULT class-attribute instance-attribute

MULT = 2

Constant multiplier.

Applies a fixed scaling factor to all coefficients, regardless of PSD.

Formula:

mult = sigma

MULT_PSD class-attribute instance-attribute

MULT_PSD = 3

Conditional multiplier based on PSD range.

Switches between two scaling values depending on whether psd falls within a specific range.

Formula:

mult = sigma  if (pmin <= psd <= pmax)
    sigma2 otherwise

MULT_RANGE class-attribute instance-attribute

MULT_RANGE = 4

Smooth range-based multiplier.

Computes a smooth gain based on PSD and specified min/max bounds.

Formula:

mult = sigma * sqrt((psd * pmax) / ((psd + pmin) * (psd + pmax)))

THR class-attribute instance-attribute

THR = 1

Hard threshold filter.

Removes frequency components below a given PSD threshold.

Formula:

mult = 0.0 if psd < sigma else 1.0

WIENER class-attribute instance-attribute

WIENER = 0

Generalized Wiener filter.

Suppresses noise while preserving signal using an adaptive formula.

Formula:

mult = max((psd - sigma) / psd, 0) ** f0beta

SLocation

Bases: Mapping[Frequency, Sigma]

A helper class for handling sigma values as functions of frequency in different dimensions.

This class allows you to specify and interpolate sigma values at different frequency locations. The frequency range is normalized to [0.0,1.0] with 0.0 being the lowest frequency and 1.0 being the highest. The class also supports handling sigma values as a function of horizontal (ssx), vertical (ssy), and temporal (sst) frequencies.

Initializes the SLocation object by processing frequency-sigma pairs and sorting them.

Example:

sloc = DFTTest.SLocation(
    [(0.0, 4), (0.25, 8), (0.5, 10), (0.75, 32), (1.0, 64)], DFTTest.SLocation.InterMode.SPLINE
)
>>> sloc  # rounded to 3 digits
>>> {
    0.0: 4, 0.053: 4.848, 0.105: 5.68, 0.158: 6.528, 0.211: 7.376, 0.25: 8, 0.263: 8.104, 0.316: 8.528,
    0.368: 8.944, 0.421: 9.368, 0.474: 9.792, 0.5: 10, 0.526: 12.288, 0.579: 16.952, 0.632: 21.616, 0.684: 26.192,
    0.737: 30.856, 0.75: 32, 0.789: 36.992, 0.842: 43.776, 0.895: 50.56, 0.947: 57.216, 1.0: 64
}

Parameters:

  • locations

    (Sequence[Frequency | Sigma] | Sequence[tuple[Frequency, Sigma]] | Mapping[Frequency, Sigma]) –

    A sequence of tuples or a dictionary that specifies frequency and sigma pairs.

  • interpolate

    (InterMode | None, default: None ) –

    The interpolation method to be used for sigma values. If None, no interpolation is done.

  • strict

    (bool, default: True ) –

    If True, raises an error if values are out of bounds. If False, it will clamp values to the bounds.

Raises:

  • CustomValueError

    If locations has not an even number of items.

Classes:

  • InterMode

    Interpolation modes for sigma values in SLocation.

  • MultiDim

    A helper class for handling multi-dimensional frequency-sigma mappings for horizontal, vertical,

Methods:

  • NoProcess

    Returns a pre-defined SLocation instance that performs no processing (i.e., sigma is zero for all locations).

  • bounds_check

    Checks and bounds the sigma values to the specified limits.

  • from_param

    Converts a frequency-sigma pair or a literal False to an SLocation instance.

  • interpolate

    Interpolates the sigma values across a specified resolution.

Attributes:

Source code
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
def __init__(
    self,
    locations: Sequence[Frequency | Sigma] | Sequence[tuple[Frequency, Sigma]] | Mapping[Frequency, Sigma],
    interpolate: InterMode | None = None,
    strict: bool = True
) -> None:
    """
    Initializes the SLocation object by processing frequency-sigma pairs and sorting them.

    Example:
        ```py
        sloc = DFTTest.SLocation(
            [(0.0, 4), (0.25, 8), (0.5, 10), (0.75, 32), (1.0, 64)], DFTTest.SLocation.InterMode.SPLINE
        )
        >>> sloc  # rounded to 3 digits
        >>> {
            0.0: 4, 0.053: 4.848, 0.105: 5.68, 0.158: 6.528, 0.211: 7.376, 0.25: 8, 0.263: 8.104, 0.316: 8.528,
            0.368: 8.944, 0.421: 9.368, 0.474: 9.792, 0.5: 10, 0.526: 12.288, 0.579: 16.952, 0.632: 21.616, 0.684: 26.192,
            0.737: 30.856, 0.75: 32, 0.789: 36.992, 0.842: 43.776, 0.895: 50.56, 0.947: 57.216, 1.0: 64
        }
        ```

    :param locations:           A sequence of tuples or a dictionary that specifies frequency and sigma pairs.
    :param interpolate:         The interpolation method to be used for sigma values. If `None`, no interpolation is done.
    :param strict:              If `True`, raises an error if values are out of bounds.
                                If `False`, it will clamp values to the bounds.
    :raises CustomValueError:   If `locations` has not an even number of items.
    """
    if isinstance(locations, Mapping):
        frequencies, sigmas = list(locations.keys()), list(locations.values())
    else:
        locations = list[float](flatten(locations))

        if len(locations) % 2:
            raise CustomValueError(
                "locations must resolve to an even number of items, pairing frequency and sigma respectively",
                self.__class__
            )

        frequencies, sigmas = list(locations[0::2]), list(locations[1::2])

    frequencies = self.bounds_check(frequencies, (0, 1), strict)
    sigmas = self.bounds_check(sigmas, (0, math.inf), strict)

    self.frequencies, self.sigmas = (t for t in zip(*sorted(zip(frequencies, sigmas))))

    if interpolate:
        interpolated = self.interpolate(interpolate)

        self.frequencies, self.sigmas = interpolated.frequencies, interpolated.sigmas

frequencies instance-attribute

frequencies: tuple[Frequency, ...]

The list of frequency locations.

sigmas instance-attribute

sigmas: tuple[Sigma, ...]

The corresponding sigma values for each frequency.

InterMode

Bases: CustomEnum

Interpolation modes for sigma values in SLocation.

Defines how sigma values should be interpolated across frequency locations.

Methods:

  • __call__

    Interpolates sigma values for given frequency locations. Can handle multiple locations for horizontal,

Attributes:

  • CUBIC

    Cubic Interpolation:

  • LINEAR

    Linear Interpolation:

  • NEAREST

    Nearest Neighbor Interpolation:

  • NEAREST_UP

    Nearest Neighbor with Rounding Up:

  • QUADRATIC

    Quadratic Interpolation:

  • SPLINE

    Spline Interpolation:

  • SPLINE_LINEAR

    Spline-Linear Interpolation:

  • ZERO

    Zero Order Hold (ZOH):

CUBIC class-attribute instance-attribute
CUBIC = 'cubic'

Cubic Interpolation:

Performs cubic interpolation, fitting a third-degree polynomial through the data points.

This is commonly used to produce smooth and visually appealing curves, especially when higher smoothness is needed between data points.

LINEAR class-attribute instance-attribute
LINEAR = 'linear'

Linear Interpolation:

Performs a linear interpolation between given frequency and sigma values. This is the default interpolation method.

This method connects adjacent points with straight lines and is typically used when data points change at a constant rate.

NEAREST class-attribute instance-attribute
NEAREST = 'nearest'

Nearest Neighbor Interpolation:

Uses the nearest value for interpolation. This method does not smooth the data, but rather uses the value closest to the target frequency.

This can result in discontinuous transitions, especially if the data is not uniform.

NEAREST_UP class-attribute instance-attribute
NEAREST_UP = 'nearest-up'

Nearest Neighbor with Rounding Up:

A variation of nearest neighbor interpolation where the value is always rounded up.

This can be useful when you want to ensure that the sigma value is never lower than a certain threshold, avoiding underestimation.

QUADRATIC class-attribute instance-attribute
QUADRATIC = 'quadratic'

Quadratic Interpolation:

Performs quadratic interpolation, fitting a second-degree polynomial through the data points.

This method creates a parabolic curve between points, which can provide better smoothness for certain types of data.

SPLINE class-attribute instance-attribute
SPLINE = 1

Spline Interpolation:

Performs a spline interpolation between given frequency and sigma values.

This method fits a smooth curve (using spline functions) through the given data points, resulting in a smoother transition between values than linear interpolation.

SPLINE_LINEAR class-attribute instance-attribute
SPLINE_LINEAR = 'slinear'

Spline-Linear Interpolation:

A combination of spline interpolation with linear interpolation for smoother transitions.

This method combines spline interpolation with linear methods, making it useful for smoother transitions but retaining linear simplicity where needed.

ZERO class-attribute instance-attribute
ZERO = 'zero'

Zero Order Hold (ZOH):

A simple method that holds the last value before the target frequency location.

This is equivalent to piecewise constant interpolation, where the sigma value is "held" at the last known value until the next point.

__call__
__call__(
    location: SLocationT, /, *, res: int = 20, digits: int = 3
) -> SLocation
__call__(
    location: SLocationT | None, /, *, res: int = 20, digits: int = 3
) -> SLocation | None
__call__(
    h_loc: SLocationT | None,
    v_loc: SLocationT | None,
    t_loc: SLocationT | None,
    /,
    *,
    res: int = 20,
    digits: int = 3,
) -> MultiDim
__call__(
    *locations: SLocationT | None, res: int = 20, digits: int = 3
) -> SLocation | None | MultiDim

Interpolates sigma values for given frequency locations. Can handle multiple locations for horizontal, vertical, and temporal frequencies.

Parameters:

  • locations
    (SLocationT | None, default: () ) –

    The frequency locations for interpolation.

  • res
    (int, default: 20 ) –

    The resolution of the interpolation (default is 20).

  • digits
    (int, default: 3 ) –

    The precision of the frequency values (default is 3 decimal places).

Returns:

  • SLocation | None | MultiDim

    The interpolated SLocation object or a MultiDim object if multiple locations are provided.

Source code
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def __call__(
    self, *locations: SLocationT | None, res: int = 20, digits: int = 3
) -> DFTTest.SLocation | None | DFTTest.SLocation.MultiDim:
    """
    Interpolates sigma values for given frequency locations. Can handle multiple locations for horizontal,
    vertical, and temporal frequencies.

    :param locations: The frequency locations for interpolation.
    :param res: The resolution of the interpolation (default is 20).
    :param digits: The precision of the frequency values (default is 3 decimal places).
    :return: The interpolated `SLocation` object or a `MultiDim` object if multiple locations are provided.
    """
    if len(locations) == 1:
        sloc = DFTTest.SLocation.from_param(locations[0])

        if sloc is not None:
            sloc = sloc.interpolate(self, res, digits)

        return sloc

    return DFTTest.SLocation.MultiDim(*(self(x, res=res, digits=digits) for x in locations))

MultiDim

MultiDim(
    horizontal: SLocationT | Literal[False] | None = None,
    vertical: SLocationT | Literal[False] | None = None,
    temporal: SLocationT | Literal[False] | None = None,
)

A helper class for handling multi-dimensional frequency-sigma mappings for horizontal, vertical, and temporal dimensions.

Initializes a MultiDim object with specified frequency-sigma mappings for horizontal, vertical, and temporal dimensions.

Example: Denoise only on the vertical dimension:

sloc = DFTTest.SLocation.MultiDim(vertical=[(0.0, 8.0), (0.25, 16.0), (0.5, 0.0), (0.75, 16.0), (1.0, 0.0)])

denoised = DFTTest(clip).denoise(sloc)

Parameters:

  • horizontal
    (SLocationT | Literal[False] | None, default: None ) –

    The sigma values for horizontal frequency locations.

  • vertical
    (SLocationT | Literal[False] | None, default: None ) –

    The sigma values for vertical frequency locations.

  • temporal
    (SLocationT | Literal[False] | None, default: None ) –

    The sigma values for temporal frequency locations.

Raises:

  • CustomValueError

    If no dimension is specified.

Attributes:

Source code
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
def __init__(
    self,
    horizontal: SLocationT | Literal[False] | None = None,
    vertical: SLocationT | Literal[False] | None = None,
    temporal: SLocationT | Literal[False] | None = None
) -> None:
    """
    Initializes a `MultiDim` object with specified frequency-sigma mappings for horizontal,
    vertical, and temporal dimensions.

    Example:
        Denoise only on the vertical dimension:
        ```py
        sloc = DFTTest.SLocation.MultiDim(vertical=[(0.0, 8.0), (0.25, 16.0), (0.5, 0.0), (0.75, 16.0), (1.0, 0.0)])

        denoised = DFTTest(clip).denoise(sloc)
        ```

    :param horizontal:          The sigma values for horizontal frequency locations.
    :param vertical:            The sigma values for vertical frequency locations.
    :param temporal:            The sigma values for temporal frequency locations.
    :raise CustomValueError:    If no dimension is specified.
    """
    if not (horizontal or vertical or temporal):
        raise CustomValueError('You must specify at least one dimension!', self.__class__)

    self.horizontal = DFTTest.SLocation.from_param(horizontal)
    self.vertical = DFTTest.SLocation.from_param(vertical)
    self.temporal = DFTTest.SLocation.from_param(temporal)
horizontal instance-attribute
horizontal = from_param(horizontal)
temporal instance-attribute
temporal = from_param(temporal)
vertical instance-attribute
vertical = from_param(vertical)

NoProcess classmethod

NoProcess() -> Self

Returns a pre-defined SLocation instance that performs no processing (i.e., sigma is zero for all locations).

Returns:

  • Self

    A SLocation instance with no processing.

Source code
451
452
453
454
455
456
457
458
459
@classproperty
@classmethod
def NoProcess(cls) -> Self:
    """
    Returns a pre-defined `SLocation` instance that performs no processing (i.e., sigma is zero for all locations).

    :return: A `SLocation` instance with no processing.
    """
    return cls({0: 0, 1: 0})

bounds_check classmethod

bounds_check(
    values: Sequence[float],
    bounds: tuple[float | None, float | None],
    strict: bool = False,
) -> list[float]

Checks and bounds the sigma values to the specified limits.

Parameters:

  • values
    (Sequence[float]) –

    The list of sigma values to check.

  • bounds
    (tuple[float | None, float | None]) –

    The valid bounds for the sigma values.

  • strict
    (bool, default: False ) –

    If True, raises an error for out-of-bounds values, otherwise clamps them to bounds.

Returns:

  • list[float]

    A list of sigma values that are within the specified bounds.

Source code
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
@classmethod
def bounds_check(
    cls, values: Sequence[float], bounds: tuple[float | None, float | None], strict: bool = False
) -> list[float]:
    """
    Checks and bounds the sigma values to the specified limits.

    :param values:      The list of sigma values to check.
    :param bounds:      The valid bounds for the sigma values.
    :param strict:      If `True`, raises an error for out-of-bounds values, otherwise clamps them to bounds.
    :return:            A list of sigma values that are within the specified bounds.
    """
    if not values:
        raise CustomValueError('"values" can\'t be empty!', cls)

    values = list(values)

    of_error = CustomOverflowError(
        "Invalid value at index {i}, not in ({bounds})", cls,
        bounds=list(math.inf if x is None else x for x in bounds)
    )

    low_bound, up_bound = bounds

    for i, value in enumerate(values):
        if low_bound is not None and value < low_bound:
            if strict:
                raise of_error(i=i)

            values[i] = low_bound

        if up_bound is not None and value > up_bound:
            if strict:
                raise of_error(i=i)

            values[i] = up_bound

    return values

from_param classmethod

from_param(location: SLocationT | Literal[False]) -> Self
from_param(location: SLocationT | Literal[False] | None) -> Self | None
from_param(location: SLocationT | Literal[False] | None) -> Self | None

Converts a frequency-sigma pair or a literal False to an SLocation instance. Returns None if no processing.

Parameters:

  • location
    (SLocationT | Literal[False] | None) –

    A frequency-sigma pair, False for no processing, or None.

Returns:

  • Self | None

    An SLocation instance or None.

Source code
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
@classmethod
def from_param(cls, location: SLocationT | Literal[False] | None) -> Self | None:
    """
    Converts a frequency-sigma pair or a literal `False` to an `SLocation` instance.
    Returns `None` if no processing.

    :param location:    A frequency-sigma pair, `False` for no processing, or `None`.
    :return:            An `SLocation` instance or `None`.
    """
    if isinstance(location, SupportsFloatOrIndex) and location is not False:
        location = float(location)
        location = {0: location, 1: location}

    if location is None:
        return None

    if location is False:
        return cls.NoProcess

    return cls(location)

interpolate

interpolate(
    method: InterMode = LINEAR, res: int = 20, digits: int = 3
) -> SLocation

Interpolates the sigma values across a specified resolution.

Parameters:

  • method
    (InterMode, default: LINEAR ) –

    The interpolation method to use.

  • res
    (int, default: 20 ) –

    The resolution of the interpolation (default is 20).

  • digits
    (int, default: 3 ) –

    The precision of the frequency values (default is 3 decimal places).

Returns:

  • SLocation

    A new SLocation instance with interpolated sigma values.

Source code
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
def interpolate(
    self, method: InterMode = InterMode.LINEAR, res: int = 20, digits: int = 3
) -> DFTTest.SLocation:
    """
    Interpolates the sigma values across a specified resolution.

    :param method:      The interpolation method to use.
    :param res:         The resolution of the interpolation (default is 20).
    :param digits:      The precision of the frequency values (default is 3 decimal places).
    :return:            A new `SLocation` instance with interpolated sigma values.
    """
    from scipy.interpolate import interp1d

    frequencies = list({round(x / (res - 1), digits) for x in range(res)})
    sigmas = interp1d(  # FIXME: interp1d is deprecated
        list(self.frequencies), list(self.sigmas), method.value, fill_value='extrapolate'
    )(frequencies)

    return self.__class__(dict(zip(frequencies, (float(s) for s in sigmas))) | dict(self), strict=False)

SynthesisType

Bases: CustomIntEnum

Enumeration of synthesis window types used in DFTTest plugin.

These constants are used with the swin (spatial) and twin (temporal) parameters to specify the window function applied during frequency-domain processing.

Attributes:

  • BARLETT

    Bartlett window (8). Also known as a triangular window; moderate leakage reduction.

  • BARLETT_HANN

    Bartlett-Hann window (9). Hybrid of Bartlett and Hanning with a smoother taper.

  • BLACKMAN

    Blackman window (2). Better side lobe attenuation than Hamming or Hanning at the cost of wider main lobe.

  • BLACKMAN_HARRIS_4TERM

    4-term Blackman-Harris window (3). Low side lobes, ideal for high dynamic range applications.

  • BLACKMAN_HARRIS_7TERM

    7-term Blackman-Harris window (5). Extended version with even greater side lobe suppression.

  • BLACKMAN_NUTTALL

    Blackman-Nuttall window (11). Variant of Nuttall with even stronger side lobe suppression.

  • FLAT_TOP

    Flat top window (6). Optimized for amplitude accuracy and minimizing scalloping loss.

  • HAMMING

    Hamming window (1). Similar to Hanning but with slightly reduced side lobe attenuation.

  • HANNING

    Hanning window (0). A raised cosine window with good frequency resolution and low spectral leakage.

  • KAISER_BESSEL

    Kaiser-Bessel window (4). Adjustable window (beta parameter) balancing resolution and leakage.

  • NUTTALL

    Nuttall window (10). Four-term cosine window with very low side lobes.

  • RECTANGULAR

    Rectangular window (7). Equivalent to no windowing; highest resolution, but worst leakage.

BARLETT class-attribute instance-attribute

BARLETT = 8

Bartlett window (8). Also known as a triangular window; moderate leakage reduction.

See: https://en.wikipedia.org/wiki/Window_function#Bartlett_window

BARLETT_HANN class-attribute instance-attribute

BARLETT_HANN = 9

Bartlett-Hann window (9). Hybrid of Bartlett and Hanning with a smoother taper.

See: https://en.wikipedia.org/wiki/Window_function#Bartlett%E2%80%93Hann_window

BLACKMAN class-attribute instance-attribute

BLACKMAN = 2

Blackman window (2). Better side lobe attenuation than Hamming or Hanning at the cost of wider main lobe.

See: https://en.wikipedia.org/wiki/Window_function#Blackman_window

BLACKMAN_HARRIS_4TERM class-attribute instance-attribute

BLACKMAN_HARRIS_4TERM = 3

4-term Blackman-Harris window (3). Low side lobes, ideal for high dynamic range applications.

See: https://en.wikipedia.org/wiki/Window_function#Blackman%E2%80%93Harris_window

BLACKMAN_HARRIS_7TERM class-attribute instance-attribute

BLACKMAN_HARRIS_7TERM = 5

7-term Blackman-Harris window (5). Extended version with even greater side lobe suppression.

See: - https://ccrma.stanford.edu/~jos/Windows/Blackman_Harris_Window_Family.html - https://github.com/hukenovs/blackman_harris_win

BLACKMAN_NUTTALL class-attribute instance-attribute

BLACKMAN_NUTTALL = 11

Blackman-Nuttall window (11). Variant of Nuttall with even stronger side lobe suppression.

See: https://en.wikipedia.org/wiki/Window_function#Blackman%E2%80%93Nuttall_window

FLAT_TOP class-attribute instance-attribute

FLAT_TOP = 6

Flat top window (6). Optimized for amplitude accuracy and minimizing scalloping loss.

See: https://en.wikipedia.org/wiki/Window_function#Flat_top_window

HAMMING class-attribute instance-attribute

HAMMING = 1

Hamming window (1). Similar to Hanning but with slightly reduced side lobe attenuation.

See: https://en.wikipedia.org/wiki/Window_function#Hamming_window

HANNING class-attribute instance-attribute

HANNING = 0

Hanning window (0). A raised cosine window with good frequency resolution and low spectral leakage.

See: https://en.wikipedia.org/wiki/Window_function#Hann_(Hanning)_window

KAISER_BESSEL class-attribute instance-attribute

KAISER_BESSEL = 4

Kaiser-Bessel window (4). Adjustable window (beta parameter) balancing resolution and leakage.

See: https://en.wikipedia.org/wiki/Window_function#Kaiser_window

NUTTALL class-attribute instance-attribute

NUTTALL = 10

Nuttall window (10). Four-term cosine window with very low side lobes.

See: https://en.wikipedia.org/wiki/Window_function#Nuttall_window,_continuous_first_derivative

RECTANGULAR class-attribute instance-attribute

RECTANGULAR = 7

Rectangular window (7). Equivalent to no windowing; highest resolution, but worst leakage.

See: https://en.wikipedia.org/wiki/Window_function#Rectangular_window

denoise

denoise(
    clip: VideoNode,
    sloc: SLocationT | MultiDim | None = None,
    /,
    tr: int = 0,
    ftype: int = WIENER,
    swin: int | SynthesisType | None = None,
    twin: int | SynthesisType | None = None,
    planes: PlanesT = None,
    func: FuncExceptT | None = None,
    **kwargs: Any,
) -> VideoNode
denoise(
    sloc: SLocationT | MultiDim,
    /,
    *,
    tr: int = 0,
    ftype: int = WIENER,
    swin: int | SynthesisType | None = None,
    twin: int | SynthesisType | None = None,
    planes: PlanesT = None,
    func: FuncExceptT | None = None,
    **kwargs: Any,
) -> VideoNode
denoise(
    clip_or_sloc: VideoNode | SLocationT | MultiDim,
    sloc: SLocationT | MultiDim | None = None,
    /,
    tr: int = 0,
    ftype: int = WIENER,
    swin: int | SynthesisType | None = None,
    twin: int | SynthesisType | None = None,
    planes: PlanesT = None,
    func: FuncExceptT | None = None,
    **kwargs: Any,
) -> VideoNode

Denoises a clip using Discrete Fourier Transform (DFT).

More informations: - VapourSynth DFTTest plugin: https://github.com/HomeOfVapourSynthEvolution/VapourSynth-DFTTest/blob/master/README.md - AviSynth DFTTest docs: http://avisynth.nl/index.php/Dfttest - vs-dfttest2 docstring: https://github.com/AmusementClub/vs-dfttest2/blob/573bb36c53df93c46a38926c7c654569e3679732/dfttest2.py#L614-L764

Examples: Apply a constant sigma:

denoised = DFTTest().denoise(clip, sigma=16)

Use frequency-dependent sigma values:
```py
denoised = DFTTest().denoise(clip, {0: 0, 0.25: 4, 0.5: 8, 0.75: 16, 1.0: 32})
```

Parameters:

  • clip_or_sloc

    (VideoNode | SLocationT | MultiDim) –

    Either a video clip or frequency location.

  • sloc

    (SLocationT | MultiDim | None, default: None ) –

    Frequency location (used if clip_or_sloc is a video clip).

  • tr

    (int, default: 0 ) –

    Temporal radius for denoising (equivalent to tbsize).

  • ftype

    (int, default: WIENER ) –

    Filter type for denoising (see FilterType enum, e.g.).

  • swin

    (int | SynthesisType | None, default: None ) –

    Synthesis window size (can use SynthesisType enum).

  • twin

    (int | SynthesisType | None, default: None ) –

    Temporal window size (can use SynthesisType enum).

  • planes

    (PlanesT, default: None ) –

    Planes to apply the denoising filter.

  • func

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

  • kwargs

    (Any, default: {} ) –

    Additional parameters for the denoising process.

Returns:

  • VideoNode

    The denoised video node.

Source code
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
def denoise(
    self,
    clip_or_sloc: vs.VideoNode | SLocationT | SLocation.MultiDim,
    sloc: SLocationT | SLocation.MultiDim | None = None,
    /,
    tr: int = 0,
    ftype: int = FilterType.WIENER,
    swin: int | SynthesisType | None = None,
    twin: int | SynthesisType | None = None,
    planes: PlanesT = None,
    func: FuncExceptT | None = None,
    **kwargs: Any
) -> vs.VideoNode:
    """
    Denoises a clip using Discrete Fourier Transform (DFT).

    More informations:
        - VapourSynth DFTTest plugin: https://github.com/HomeOfVapourSynthEvolution/VapourSynth-DFTTest/blob/master/README.md
        - AviSynth DFTTest docs: http://avisynth.nl/index.php/Dfttest
        - vs-dfttest2 docstring: https://github.com/AmusementClub/vs-dfttest2/blob/573bb36c53df93c46a38926c7c654569e3679732/dfttest2.py#L614-L764

    Examples:
        Apply a constant sigma:
        ```py
        denoised = DFTTest().denoise(clip, sigma=16)
        ```

        Use frequency-dependent sigma values:
        ```py
        denoised = DFTTest().denoise(clip, {0: 0, 0.25: 4, 0.5: 8, 0.75: 16, 1.0: 32})
        ```

    :param clip_or_sloc:    Either a video clip or frequency location.
    :param sloc:            Frequency location (used if `clip_or_sloc` is a video clip).
    :param tr:              Temporal radius for denoising (equivalent to `tbsize`).
    :param ftype:           Filter type for denoising (see [FilterType][vsdenoise.fft.DFTTest.FilterType] enum, e.g.).
    :param swin:            Synthesis window size (can use [SynthesisType][vsdenoise.fft.DFTTest.SynthesisType] enum).
    :param twin:            Temporal window size (can use [SynthesisType][vsdenoise.fft.DFTTest.SynthesisType] enum).
    :param planes:          Planes to apply the denoising filter.
    :param func:            Function returned for custom error handling.
    :param kwargs:          Additional parameters for the denoising process.
    :return:                The denoised video node.
    """
    func = func or self.denoise

    nclip: vs.VideoNode | None

    if isinstance(clip_or_sloc, vs.VideoNode):
        nclip = clip_or_sloc
        nsloc = self.default_slocation if sloc is None else sloc
    else:
        nclip = self.clip
        nsloc = clip_or_sloc

    if nclip is None:
        raise CustomValueError('You must pass a clip!', func)

    assert check_progressive(nclip, func)

    ckwargs = dict[str, Any](
        tbsize=tr * 2 + 1,
        ftype=ftype,
        swin=swin,
        twin=twin,
        planes=planes
    )

    if isinstance(nsloc, DFTTest.SLocation.MultiDim):
        ckwargs.update(ssx=nsloc.horizontal, ssy=nsloc.vertical, sst=nsloc.temporal)
    else:
        ckwargs.update(slocation=DFTTest.SLocation.from_param(nsloc))

    for k, v in ckwargs.items():
        if isinstance(v, DFTTest.SLocation):
            ckwargs[k] = list(v)

    return self.backend.DFTTest(nclip, **KwargsNotNone(ckwargs) | self.default_args | kwargs)

extract_freq

extract_freq(
    clip: VideoNode, sloc: SLocationT | MultiDim, **kwargs: Any
) -> VideoNode

Extracts the frequency domain from the given clip by subtracting the denoised clip from the original.

Parameters:

  • clip

    (VideoNode) –

    The clip from which the frequency domain is to be extracted.

  • sloc

    (SLocationT | MultiDim) –

    The frequency location for the extraction process.

  • kwargs

    (Any, default: {} ) –

    Additional parameters for the extraction process.

Returns:

  • VideoNode

    The clip with the extracted frequency domain.

Source code
980
981
982
983
984
985
986
987
988
989
990
991
992
def extract_freq(
    self, clip: vs.VideoNode, sloc: SLocationT | SLocation.MultiDim, **kwargs: Any
) -> vs.VideoNode:
    """
    Extracts the frequency domain from the given clip by subtracting the denoised clip from the original.

    :param clip:    The clip from which the frequency domain is to be extracted.
    :param sloc:    The frequency location for the extraction process.
    :param kwargs:  Additional parameters for the extraction process.
    :return:        The clip with the extracted frequency domain.
    """
    kwargs = dict(func=self.extract_freq) | kwargs
    return clip.std.MakeDiff(self.denoise(clip, sloc, **kwargs))

insert_freq

insert_freq(
    low: VideoNode, high: VideoNode, sloc: SLocationT | MultiDim, **kwargs: Any
) -> VideoNode

Inserts the frequency domain from one clip into another by merging the frequency information.

Parameters:

  • low

    (VideoNode) –

    The low-frequency component clip.

  • high

    (VideoNode) –

    The high-frequency component clip.

  • sloc

    (SLocationT | MultiDim) –

    The frequency location for the merging process.

  • kwargs

    (Any, default: {} ) –

    Additional parameters for the merging process.

Returns:

  • VideoNode

    The merged clip with the inserted frequency domain.

Source code
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
def insert_freq(
    self, low: vs.VideoNode, high: vs.VideoNode, sloc: SLocationT | SLocation.MultiDim, **kwargs: Any
) -> vs.VideoNode:
    """
    Inserts the frequency domain from one clip into another by merging the frequency information.

    :param low:     The low-frequency component clip.
    :param high:    The high-frequency component clip.
    :param sloc:    The frequency location for the merging process.
    :param kwargs:  Additional parameters for the merging process.
    :return:        The merged clip with the inserted frequency domain.
    """
    return low.std.MergeDiff(self.extract_freq(high, sloc, **dict(func=self.insert_freq) | kwargs))

merge_freq

merge_freq(
    low: VideoNode, high: VideoNode, sloc: SLocationT | MultiDim, **kwargs: Any
) -> VideoNode

Merges the low and high-frequency components by applying denoising to the low-frequency component.

Parameters:

  • low

    (VideoNode) –

    The low-frequency component clip.

  • high

    (VideoNode) –

    The high-frequency component clip.

  • sloc

    (SLocationT | MultiDim) –

    The frequency location for the merging process.

  • kwargs

    (Any, default: {} ) –

    Additional parameters for the merging process.

Returns:

  • VideoNode

    The merged clip with the denoised low-frequency and high-frequency components.

Source code
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
def merge_freq(
    self, low: vs.VideoNode, high: vs.VideoNode, sloc: SLocationT | SLocation.MultiDim, **kwargs: Any
) -> vs.VideoNode:
    """
    Merges the low and high-frequency components by applying denoising to the low-frequency component.

    :param low:     The low-frequency component clip.
    :param high:    The high-frequency component clip.
    :param sloc:    The frequency location for the merging process.
    :param kwargs:  Additional parameters for the merging process.
    :return:        The merged clip with the denoised low-frequency and high-frequency components.
    """
    return self.insert_freq(
        self.denoise(low, sloc, **kwargs), high, sloc, **dict(func=self.merge_freq) | kwargs
    )

fft3d

fft3d(clip: VideoNode, **kwargs: Any) -> ConstantFormatVideoNode

Applies FFT3DFilter, a 3D frequency-domain filter used for strong denoising and mild sharpening.

This filter processes frames using the Fast Fourier Transform (FFT) in the frequency domain. Unlike local filters, FFT3DFilter performs block-based, non-local processing.

Official documentation: https://github.com/myrsloik/VapourSynth-FFT3DFilter/blob/master/doc/fft3dfilter.md

Possibly faster implementation: https://github.com/AmusementClub/VapourSynth-FFT3DFilter/releases

Note: Sigma values are internally scaled according to bit depth, unlike when using the plugin directly.

Parameters:

  • clip

    (VideoNode) –

    Input video clip.

  • **kwargs

    (Any, default: {} ) –

    Additional parameters passed to the FFT3DFilter plugin.

Returns:

  • ConstantFormatVideoNode

    A heavily degraded version of DFTTest, with added banding and color shifts.

Source code
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
@deprecated("`fft3d` is permanently deprecated and known to contain many bugs. Use with caution.")
def fft3d(clip: vs.VideoNode, **kwargs: Any) -> ConstantFormatVideoNode:
    """
    Applies FFT3DFilter, a 3D frequency-domain filter used for strong denoising and mild sharpening.

    This filter processes frames using the Fast Fourier Transform (FFT) in the frequency domain.
    Unlike local filters, FFT3DFilter performs block-based, non-local processing.

    Official documentation:
    https://github.com/myrsloik/VapourSynth-FFT3DFilter/blob/master/doc/fft3dfilter.md

    Possibly faster implementation:
    https://github.com/AmusementClub/VapourSynth-FFT3DFilter/releases

    Note: Sigma values are internally scaled according to bit depth, unlike when using the plugin directly.

    :param clip:        Input video clip.
    :param **kwargs:    Additional parameters passed to the FFT3DFilter plugin.
    :return:            A heavily degraded version of DFTTest, with added banding and color shifts.
    """
    kwargs |= dict(interlaced=FieldBased.from_video(clip, False, fft3d).is_inter)

    # fft3dfilter requires sigma values to be scaled to bit depth
    # https://github.com/myrsloik/VapourSynth-FFT3DFilter/blob/master/doc/fft3dfilter.md#scaling-parameters-according-to-bit-depth
    sigma_multiplier = 1.0 / 256.0 if get_sample_type(clip) is vs.FLOAT else 1 << (get_depth(clip) - 8)

    for sigma in ['sigma', 'sigma2', 'sigma3', 'sigma4', 'smin ', 'smax']:
        if sigma in kwargs:
            kwargs[sigma] *= sigma_multiplier

    return core.fft3dfilter.FFT3DFilter(clip, **kwargs)