# DctFilter

Abstract | |
---|---|

Author | Tom Barry, Chikuzen |

Version | v0.0.1.5 |

Download | DctFilter_015.zip |

Category | Other filters |

License | GPLv2 |

Discussion | Doom9 Thread |

## Contents |

## Description

DctFiler is an experimental 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).

## Requirements

- AviSynth 2.5.8 or greater
- Supported color formats: YUY2, YV12
- Width and height need to be a multiple of 16 (mod16)

## Known Issues

- Stripe bug - both variants are buggy at calculating DC, additional information here and here.

## Syntax and Parameters

### DctFilter

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 (clip, float, float, float, float, float, float, float, float, int "chroma", int "fdct", int "idct", int "offx", int "offy")

*clip*=

- Input clip.

*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.

*int*chroma =*1*

- Chroma processing:
- 0 : do not process nor copy, output will be trash
- 1 : process

- Chroma processing:

*int*fdct =*-1*

*int*idct =*-1*

- Choose which DCT to use (if you want to compare). Do not use fdct=2 or idct=3, it may crash!

*int*offx =*0*

*int*offy =*0*

- Specify offsets, only use when the input clip's dimensions are mod16, otherwise it may crash.

**Note:**the first 9 parameters are unnamed and do not have a default so they must be specified. The last 5 parameters are only available in`DctFilter v0.0.1.5`, consider them as experimental so use with caution (except for`chroma`).

### DctFilterD

DctFilterD works similar to DctFilter 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 `DctFilterD(4)`

then the 4 diagonals in the lower right corner of the DCT result will be set to 0.

I haven't tested this much but, like my results with custom quant tables, it appears if you set DiagCt very large you will start to get edge noise, something like ringing.[1]

- DctFilterD (clip, int)

*clip*=

- Input clip.

*int*=

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

**Note:**all parameters are unnamed and do not have a default so they must be specified.

### DctAddConstant

Not much is known about this filter...

- DctAddConstant (clip, float, float, float, float)

*clip*=

- Input clip.

*float*=

*float*=

*float*=

*float*=

**Note:**all parameters are unnamed and do not have a default so they must be specified.

## Examples

#### DctFilter

The following example should effectively do nothing, due to a possible bug that's not the case.[2]

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:[3]

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?[4]

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:[5]

DCTFilterD(14)

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

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

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

## Changelog

Version Date Developer Changes

v0.0.1.5 2007/02/09 foxyshadis - Better memory management in DctFilter, chroma=0 to disable chroma. v0.0.1.4 2003/02/21 Tom Barry - Add DctFilterD, diagonal support v0.0.1.3 2003/01/30 Tom Barry - Avisynth 2.5 beta, plugininit2, vs6 v0.0.1.2 2002/11/2? SansGrip - YUY2 support v ? 2002/11/25 Tom Barry - Initial test release for Avisynth 2.5 alpha only

## Archived Downloads

Version | Download | Mirror | Mirror 2 |
---|---|---|---|

v0.0.1.5 | DctFilter15 | ||

v0.0.1.4 | DctFilter.zip | dctfilter_dll_20030221.zip |

## External Links

- AquilineStudios - Additional information on usage.
- Doom9Forum - Another advanced usage example.
- Doom9 Forum - Original DctFilter discussion.
- Doom9 Forum - DctFilter v0.0.1.5 discussion.
- Doom9 Forum - DctFilter VapourSynth port.

**Back to External Filters ←**