DctFilter

From Avisynth wiki
Jump to: navigation, search
Abstract
Author Chikuzen
Version v0.5.1
Download DCTFilter-0.5.1.7z
Category Other filters
License GPLv2
Discussion Doom9 Forum

Contents

Description

DctFiler is a filter that, for each 8x8 block, will do a Discrete Cosine Transform (DCT), scale down the selected frequency values, and then reverse the process with an Inverse Discrete Cosine Transform (IDCT).

This version is a rewrite of the original DctFilter by Tom Barry.

Requirements


*** vcredist_x86.exe is required for DctFilter-x86
*** vcredist_x64.exe is required for DctFilter-x64


Syntax and Parameters


DctFilter

Execute an 8x8 DCT to a clip.

For each 8x8 block it will do a Discrete Cosine Transform (DCT), scale down the selected frequency values, and then reverse the process with an Inverse Discrete Cosine Transform (IDCT).
In the following example the highest frequency components in each row and column will be zeroed while the 2nd highest would be cut in half.

DctFilter(1,1,1,1,1,1,.5,0)

The row & column parameters are multiplied together to get the scale factor for each of the 64 values in a block. So if the top left value was V[0,0] then in the example above the we would scale row 6, col 6 (V[6,6]) by .5 * .5 = .25.
Note that while they look like floating point parameters above they really now only have 3 bit accuracy so the only actual values used are 0, 1/8, 1/4, 3/8 ... 1.0. But you can specify any value and it will be rounded to the nearest one.



DCTFilter is just an alias for DCTFilter8 for backward compatibility.
DCTFilter8 (clip, float, float, float, float, float, float, float, float, float "x40", float "x41", float "x42", float "x43", int "chroma", int "opt")
DCTFilter (clip, float, float, float, float, float, float, float, float, float "x40", float "x41", float "x42", float "x43", int "chroma", int "opt")


clip   =
All planar formats(8/10/12/14/16bit and float, YUV/RGB with or without alpha) are supported.


float   =
There are 8 positional floating point parameters, all of which must be specified as in the range (0.0 <= x <= 1.0).
These correspond to scaling factors for the 8 rows and columns of the 8x8 DCT blocks.
The leftmost parameter corresponds to the top row, left column. This would be the DC component of the transform and should always be left as 1.0.


float  x40 = 1.0
float  x41 = 1.0
float  x42 = 1.0
float  x43 = 1.0
If planes's width and/or plane's height is not mod 8 but mod 4, DCTFilter8 execute 4x4 DCT to the most right/bottom 4 columns/rows.
These correspond to scaling factors for the 4 rows and columns of the 4x4 DCT blocks. The leftmost parameter corresponds to the top row, left column.


int  chroma = 1
Chroma processing:
  • 0 = copy from source (on RGB, B and R planes are copied).
  • 1 = process (default)
  • 2 = do not process nor copy, output will be trash.
Note: alpha channel will always be copied.


int  opt = MAX_INT
Choose which DCT to use (if you want to compare). Do not use fdct=2 or idct=3, it may crash!
  • Specify which CPU optimization are used.
  • 0 = use c++ routine.
  • 1 = use SSE2 + SSE routine if possible. when SSE2 can't be used, fallback to 0.
  • 2 = use SSE4.1 + SSE2 + SSE routine if possible. when SSE4.1 can't be used, fallback to 1.
  • others = use AVX2 + FMA3 + AVX routine if possible. WHen AVX2 can't be used, fallback to 2.(default)


Note: the first 9 parameters are unnamed and do not have a default so they must be specified.




DctFilter8D

DctFilter8D works similar to DctFilter8 but will zero out DiagCt number of the lower right diagonals of the DCT, leaving other values unchanged.
In an 8x8 DCT result matrix there are 15 possible diagonals (visualize a chess board), so if you specify DctFilter8D(4) then the 4 diagonals in the lower right corner of the DCT result will be set to 0.

DCTFilterD is just an alias for DCTFilter8D for backward compatibility.
DCTFilter8D (clip, int diagonals_count, int "x4", int "chroma", int "opt")
DCTFilterD (clip, int diagonals_count, int "x4", int "chroma", int "opt")


clip   =
Input clip, same as DCTFilter8.


int   =
diagonals_count: must be an integer from 1-14 saying how many of these diagonals must be zeroed, starting from the lower right hand corner.


int  x4 = 1
diagonals count for 4x4DCT.
  • 1 <= x <= 6, default=1


int  chroma = 1
same as DCTFilter8.


int  opt = MAX_INT
same as DCTFilter8.


Note: the first 2 parameters are unnamed and do not have a default so they must be specified.




DCTFilter4

Execute a 4x4 DCT to a clip.

DCTFilter4 (clip, float, float, float, float, int "chroma", int "opt")


clip   =
Input clip, same as DCTFilter8.


float   =
float   =
float   =
float   =
There are 4 positional floating point parameters, all of which must be specified as in the range (0.0 <= x <= 1.0).
These correspond to scaling factors for the 4 rows and columns of the 4x4 DCT blocks. The leftmost parameter corresponds to the top row, left column.
This would be the DC component of the transform and should always be left as 1.0.


int  chroma = 1
same as DCTFilter8.


int  opt = MAX_INT
same as DCTFilter8.


Note: the first 5 parameters are unnamed and do not have a default so they must be specified.




DctFilter4D


DCTFilter4D (clip, int diagonals_count, int "chroma", int "opt")


clip   =
Input clip, same as DCTFilter8.


int   =
diagonals_count: must be an integer from 1-6 saying how many of these diagonals must be zeroed, starting from the lower right hand corner.


int  chroma = 1
same as DCTFilter8.


int  opt = MAX_INT
same as DCTFilter8.


Note: the first 2 parameters are unnamed and do not have a default so they must be specified.


Examples

DctFilter

The following example should effectively do nothing:

AviSource("blah.avi")
DctFilter(1,1,1,1,1,1,1,1)


Subtle softening:

DctFilter(1,1,1,1,1,0.75,0.25,0) 


Remove high frequency components:[1]

DctFilter(1,1,1,.8,.4,0,0,0) #these settings may be prone to slight blocking


Measure luma variance within block (e.g. 8x8) of pixels?[2]
The easiest somewhat correct "amount of variation for each block" you can get is using STD for each pixel and applying DctFilter to it (adjust the radius of STD calculation area for possibly better results).

mt_luts(last, "std", mt_square(1), "y").mt_lut("x 15 *")
DctFilter(1,0,0,0,0,0,0,0).Greyscale()

A reasonably close approximation with a lot better performance is an edge mask:

mt_edge("min/max", 0, 255, 0, 255).mt_lut("x 5 *")
DctFilter(1,0,0,0,0,0,0,0).Greyscale()


DctFilterD

DctFilterD can be used as a fast way to average 8x8 blocks:[3]

DCTFilterD(14)
#DctFilter(1,0,0,0,0,0,0,0) #keeps the topmost line and leftmost row.[4]


Very easy way to get the normalized SAD over 8x8 blocks:[5]

mt_lutxy(clip1,clip2,"x y - abs")
DctFilterD(14)


Changelog

Version      Date            Changes
v0.5.1 2020/05/13 - Changes by asd-g - Update to AviSynth+'s v8 interface v0.5.0 2016/08/17 - add avs+'s new colorspaces support. v0.4.0 2016/08/03 - add 4x4 DCT mode. - also add DCTFilter4(), DCTFilter4D v0.3.0 2016/08/01 - add avs2.6 support - add version resource. v0.2.0 2016/08/01 - add SSE4.1 code and more optimization. v0.1.0 2016/07/31 - add "DCTFilterD" - optimized SIMD code. v0.0.1 2016/07/31 - fix wrong chroma processing. v0.0.0 2016/07/31 - Initial release


External Links

  • GitHub - Source code repository.
  • GitHub - Source code repository (update).
  • Doom9 Forum - DctFilter VapourSynth port.




Back to External Filters

Personal tools