PDA

View Full Version : Deblock_QED updated (requires MaskTools 2.0a45 or later)


Bi11
25th May 2010, 19:28
According to MaskTools 2.0a43 change log:
* added : "biased" option to mt_lutspa
"biased" is placed between "relative" and "expr" parameters of mt_LutSpa. The current Deblock-QED script won't run because of this change.

Thus, I have modified Deblock_QED to account for the change. I have also modified Deblock_QED to pad the input clip with borders internally if the clip is not mod 16. The full script is shown below:

# Changes 2008-08-18: (Didée)
# - Replaced the ugly stackXXX cascade with mt_LutSpa() (requires MaskTools v2.0a35)
# - Changed Quant and Offset defaults to 24,28,2,4,4,8

# Changes 2010-05-25:
# - Explicitly specified parameters of mt_LutSpa()
# (required due to position of new 'biased' parameter, starting from MaskTools 2.0a43)
# - Non mod 16 input is now padded with borders internally

# Changes 2010-08-18:
# - Replaced AddBorders with PointResize
# - Changed Quant and Offset defaults to 18,19,3,4,1,1 to reduce blurring

# Changes 2010-10-16:
# - Replaced 'relative' with the new 'mode' parameter in mt_LutSpa(), starting from MaskTools 2.0a45
# - Changed Quant and Offset defaults to 24,26,1,1,2,2 to increase effectiveness, but still within sensible limits.
# (see for details: http://forum.doom9.org/showthread.php?p=810932#post810932)

function Deblock_QED ( clip clp, int "quant1", int "quant2",
\ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" )
{

quant1 = default( quant1, 24 ) # Strength of block edge deblocking
quant2 = default( quant2, 26 ) # Strength of block internal deblocking

aOff1 = default( aOff1, 1 ) # halfway "sensitivity" and halfway a strength modifier for borders
aOff2 = default( aOff2, 1 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
bOff1 = default( bOff1, 2 ) # "sensitivity to detect blocking" for borders
bOff2 = default( bOff2, 2 ) # "sensitivity to detect blocking" for block interiors

uv = default( uv, 3 ) # u=3 -> use proposed method for chroma deblocking
# u=2 -> no chroma deblocking at all (fastest method)
# u=1|-1 -> directly use chroma debl. from the normal|strong deblock()

# add borders if clp is not mod 8
padX = clp.width%8 == 0 ? 0 : (8 - clp.width%8)
padY = clp.height%8 == 0 ? 0 : (8 - clp.height%8)
clp=clp.pointresize(clp.width+padX, clp.height+padY, 0, 0, clp.width+padX, clp.height+padY)

# block
block = clp.mt_LutSpa(mode="absolute",expr="x 1 + 8 % 1 < x 8 % 1 < y 1 + 8 % 1 < y 8 % 1 < | | | 255 0 ?",U=3,V=3)

# create normal deblocking (for block borders) and strong deblocking (for block interiour)
normal = clp.deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1)
strong = clp.deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2)

# build difference maps of both
normalD = mt_makediff(clp,normal,chroma=uv>2?"process":"ignore")
strongD = mt_makediff(clp,strong,chroma=uv>2?"process":"ignore")

# separate border values of the difference maps, and set the interiours to '128'
normalD2 = mt_lutxy(normalD,block,expr="y 255 == x 128 ?",U=uv,V=uv)
strongD2 = mt_lutxy(StrongD,block,expr="y 255 == x 128 ?",U=uv,V=uv)

# interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
# (Note: this is not fully accurate, but a reasonable approximation.)
# add borders if clp is not mod 16
sw=strongD2.width sh=strongD2.height
remX = sw%16 == 0 ? 0 : (16 - sw%16)
remY = sh%16 == 0 ? 0 : (16 - sh%16)
strongD3 = strongD2.pointresize(sw+remX, sh+remY, 0, 0, sw+remX, sh+remY).mt_lut(expr="x 128 - 1.01 * 128 +",U=uv,V=uv)\
.dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0).crop(0,0,-remX,-remY)

# apply compensation from "normal" deblocking to the borders of
# the full-block-compensations calculated from "strong" deblocking ...
strongD4 = mt_lutxy(strongD3,normalD2,expr="y 128 == x y ?",U=uv,V=uv)

# ... and apply it.
deblocked= mt_makediff(clp,strongD4,chroma=uv>2?"process":"ignore")

# simple decisions how to treat chroma
deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked

deblocked.crop(0,0,-padX,-padY) # remove mod 8 borders
}
I would appreciate if someone (hopefully Didée) could check the modified script to confirm it is correct.

Also, Didée, in your comments you said:
# interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
# (Note: this is not fully accurate, but a reasonable approximation.)
What would a fully accurate interpolation look like? How long would it take to run?
I ask because Deblock requires mod 8 input but DCTFilter requires mod 16 input.

EDIT:
Since the change to mt_LutSpa will remain (http://forum.doom9.org/showthread.php?p=1403808#post1403808) in future versions of MaskTools 2.0, Deblock_QED must be updated to continue working with these new versions.

I have tested this script with several sources and haven't found any errors. If anyone has problems running the script then please post about it.

UPDATE (2010-10-16):
Deblock_QED now uses the new 'mode' parameter in mt_LutSpa(), which requires MaskTools 2.0a45 or later.

Gavino
25th May 2010, 19:51
"biased" is placed between "relative" and "expr" parameters of mt_LutSpa. The current Deblock-QED script won't run because of this change.
Thus, I have modified Deblock_QED to account for the change.
Many other scripts and script functions might be affected by this problem too.

A better solution, IMHO, would be for Manao to update Masktools, moving the 'biased' parameter to the end of the list. This should be standard practice when introducing new options, to preserve backwards compatibility.

Bi11
30th May 2010, 21:38
I would still like to know if there is an alternative to DCTFilter that does not require mod 16 input and would give a fully accurate interpolation.

Didée
30th May 2010, 22:05
In the given case it is not even clear what a "fully accurate" interpolation actually is. The kind of interpolation I used via DCTFilter certainly is of the sort "it does make sense". If it is "correct" or "accurate", that is playground for arguing.

If anything, I would be more concerned about the 6x6 -> 8x8 transition (which is ugly and can show up with some certain settings), or about why it's not possible to use one Deblock base for both processing paths (deblock is always called two times), or about directed border-postprocessing on the diff's, or .. or .. or ....

Bi11
31st May 2010, 01:23
# (Note: this is not fully accurate, but a reasonable approximation.)
By explicitly noting the interpolation wasn't fully accurate, I assumed it was possible to do a "fully accurate" or "correct" interpolation of the border values over the whole block by some other means. If that note wasn't there then by default (i.e. by convention) I would have assumed the interpolation would have some level of uncertainty and thus "is not fully accurate, but a reasonable approximation."

I simply wanted to avoid having a mod 16 restriction on the input because it seems unnecessarily stricter than the mod 8 restriction imposed by Deblock.
In any case, thanks for making such a useful deblocking script Didée.


If anything, I would be more concerned about the 6x6 -> 8x8 transition (which is ugly and can show up with some certain settings)
What settings would cause it to show up?

Off topic: Can someone compile a 64-bit version of DCTFilter please? Thanks. Deblock12_x64 can be found here (http://forum.doom9.org/showpost.php?p=1401648&postcount=415).

Didée
31st May 2010, 07:51
What settings would cause it to show up?
Try e.g. (quant1=50,quant2=10), and look closely.

Emulgator
23rd June 2010, 23:32
BTW, many thanks, Bi11 !
I just updated masktools and ran into the mt_lutspa error.
And your update helped.

DVDBob
13th January 2011, 01:35
Someone know where I can find version from 25 may 2010 ???

henryho_hk
30th March 2012, 01:10
# Changes 2008-08-18: (Didee)
# - Replaced the ugly stackXXX cascade with mt_LutSpa() (requires MaskTools v2.0a35)
# - Changed Quant and Offset defaults to 24,28,2,4,4,8

# Changes 2010-05-25:
# - Explicitly specified arguments to mt_LutSpa
# - Non mod 8 input is now padded with borders internally

function Deblock_QED ( clip clp, int "quant1", int "quant2",
\ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" )
{

quant1 = default( quant1, 24 ) # Strength of block edge deblocking.
quant2 = default( quant2, 28 ) # Strength of block internal deblocking.

aOff1 = default( aOff1, 2 ) # halfway "sensitivity" and halfway a strength modifier for borders
bOff1 = default( bOff1, 4 ) # "sensitivity to detect blocking" for borders
aOff2 = default( aOff2, 4 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
bOff2 = default( bOff2, 8 ) # "sensitivity to detect blocking" for block interiors

uv = default( uv, 3 ) # u=3 -> use proposed method for chroma deblocking
# u=2 -> no chroma deblocking at all (fastest method)
# u=1|-1 -> directly use chroma debl. from the normal|strong deblock()

# add borders if clp is not mod 8
padX = clp.width%8 == 0 ? 0 : (8 - clp.width%8)
padY = clp.height%8 == 0 ? 0 : (8 - clp.height%8)
clp=clp.addborders(0, 0, padX, padY)

# block
block = clp.mt_LutSpa(relative=false, expr="x 1 + 8 % 1 < x 8 % 1 < y 1 + 8 % 1 < y 8 % 1 < | | | 255 0 ?", U=3, V=3)

# create normal deblocking (for block borders) and strong deblocking (for block interiour)
normal = clp.deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1)
strong = clp.deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2)

# build difference maps of both
normalD = mt_makediff(clp,normal,chroma=uv>2?"process":"ignore")
strongD = mt_makediff(clp,strong,chroma=uv>2?"process":"ignore")

# separate border values of the difference maps, and set the interiours to '128'
normalD2 = mt_lutxy(normalD,block,expr="y 255 == x 128 ?",U=uv,V=uv)
strongD2 = mt_lutxy(StrongD,block,expr="y 255 == x 128 ?",U=uv,V=uv)

# interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
# (Note: this is not fully accurate, but a reasonable approximation.)
# add borders if clp is not mod 16
remX = strongD2.width%16 == 0 ? 0 : (16 - strongD2.width%16)
remY = strongD2.height%16 == 0 ? 0 : (16 - strongD2.height%16)
strongD3 = strongD2.addborders(0, 0, remX, remY).mt_lut(expr="x 128 - 1.01 * 128 +",U=uv,V=uv)\
.dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0).crop(0, 0, -remX, -remY)

# apply compensation from "normal" deblocking to the borders of
# the full-block-compensations calculated from "strong" deblocking ...
strongD4 = mt_lutxy(strongD3,normalD2,expr="y 128 == x y ?",U=uv,V=uv)

# ... and apply it.
deblocked= mt_makediff(clp,strongD4,chroma=uv>2?"process":"ignore")

# simple decisions how to treat chroma
deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked

deblocked.crop(0, 0, -padX, -padY) # remove mod 8 borders
return( last )
}

Reel.Deel
4th April 2012, 01:18
Hello, I came across an updated Deblock_QED (2011-11-29) by 06_taro.

http://www.nmm-hd.org/newbbs/viewtopic.php?f=7&t=475


# Changes 2008-08-18: (Didée)
# - Replaced the ugly stackXXX cascade with mt_LutSpa() (requires MaskTools v2.0a35)
# - Changed Quant and Offset defaults to 24,28,2,4,4,8

# Changes 2010-05-25:
# - Explicitly specified parameters of mt_LutSpa()
# (required due to position of new 'biased' parameter, starting from MaskTools 2.0a43)
# - Non mod 16 input is now padded with borders internally

# Changes 2010-08-18:
# - Replaced AddBorders with PointResize
# - Changed Quant and Offset defaults to 18,19,3,4,1,1 to reduce blurring

# Changes 2010-10-16:
# - Replaced 'relative' with the new 'mode' parameter in mt_LutSpa(), starting from MaskTools 2.0a45
# - Changed Quant and Offset defaults to 24,26,1,1,2,2 to increase effectiveness, but still within sensible limits.
# (see for details: http://forum.doom9.org/showthread.php?p=810932#post810932)

# Changes 2011-11-29: (06_taro)
# - Replaced (chroma=uv>2?"process":"ignore") by (chroma=uv>2?"process":"copy") to avoid garbage clip when uv=2.
# The formal parameter is not used by MaskTools2 any more, if ever used.
# Foxyshadis once mentioned chroma="ignore" but I had never found a document containing it.

function Deblock_QED ( clip clp, int "quant1", int "quant2",
\ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" )
{

quant1 = default( quant1, 24 ) # Strength of block edge deblocking
quant2 = default( quant2, 26 ) # Strength of block internal deblocking

aOff1 = default( aOff1, 1 ) # halfway "sensitivity" and halfway a strength modifier for borders
aOff2 = default( aOff2, 1 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
bOff1 = default( bOff1, 2 ) # "sensitivity to detect blocking" for borders
bOff2 = default( bOff2, 2 ) # "sensitivity to detect blocking" for block interiors

uv = default( uv, 3 ) # u=3 -> use proposed method for chroma deblocking
# u=2 -> no chroma deblocking at all (fastest method)
# u=1|-1 -> directly use chroma debl. from the normal|strong deblock()

# add borders if clp is not mod 8
padX = clp.width%8 == 0 ? 0 : (8 - clp.width%8)
padY = clp.height%8 == 0 ? 0 : (8 - clp.height%8)
clp=clp.pointresize(clp.width+padX, clp.height+padY, 0, 0, clp.width+padX, clp.height+padY)

# block
block = clp.mt_LutSpa(mode="absolute",expr="x 1 + 8 % 1 < x 8 % 1 < y 1 + 8 % 1 < y 8 % 1 < | | | 255 0 ?",U=3,V=3)

# create normal deblocking (for block borders) and strong deblocking (for block interiour)
normal = clp.deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1)
strong = clp.deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2)

# build difference maps of both
normalD = mt_makediff(clp,normal,chroma=uv>2?"process":"copy")
strongD = mt_makediff(clp,strong,chroma=uv>2?"process":"copy")

# separate border values of the difference maps, and set the interiours to '128'
normalD2 = mt_lutxy(normalD,block,expr="y 255 == x 128 ?",U=uv,V=uv)
strongD2 = mt_lutxy(StrongD,block,expr="y 255 == x 128 ?",U=uv,V=uv)

# interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
# (Note: this is not fully accurate, but a reasonable approximation.)
# add borders if clp is not mod 16
sw=strongD2.width sh=strongD2.height
remX = sw%16 == 0 ? 0 : (16 - sw%16)
remY = sh%16 == 0 ? 0 : (16 - sh%16)
strongD3 = strongD2.pointresize(sw+remX, sh+remY, 0, 0, sw+remX, sh+remY).mt_lut(expr="x 128 - 1.01 * 128 +",U=uv,V=uv)\
.dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0).crop(0,0,-remX,-remY)

# apply compensation from "normal" deblocking to the borders of
# the full-block-compensations calculated from "strong" deblocking ...
strongD4 = mt_lutxy(strongD3,normalD2,expr="y 128 == x y ?",U=uv,V=uv)

# ... and apply it.
deblocked= mt_makediff(clp,strongD4,chroma=uv>2?"process":"copy")

# simple decisions how to treat chroma
deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked

deblocked.crop(0,0,-padX,-padY) # remove mod 8 borders
}

hydra3333
2nd September 2012, 09:27
just a cross-reference, about strong settings: http://forum.doom9.org/showthread.php?p=1589519#post1589519

lansing
4th March 2014, 02:34
for my vhs source, if i increase quant1 pass 40, it will introduce some small horizontal artifacts, but I need the high quant1 to remove the small blocks, how do I combat this?

GMJCZP
21st October 2014, 00:56
Inadvertently Deblock_QED called indifferently to plugin deblock or function deblock of DGDecode, this could be a problem if a value of 'quant'> 51 is required.

Here is the correction:

# Changes 2008-08-18: (Didée)
# - Replaced the ugly stackXXX cascade with mt_LutSpa() (requires MaskTools v2.0a35)
# - Changed Quant and Offset defaults to 24,28,2,4,4,8

# Changes 2010-05-25:
# - Explicitly specified parameters of mt_LutSpa()
# (required due to position of new 'biased' parameter, starting from MaskTools 2.0a43)
# - Non mod 16 input is now padded with borders internally

# Changes 2010-08-18:
# - Replaced AddBorders with PointResize
# - Changed Quant and Offset defaults to 18,19,3,4,1,1 to reduce blurring

# Changes 2010-10-16:
# - Replaced 'relative' with the new 'mode' parameter in mt_LutSpa(), starting from MaskTools 2.0a45
# - Changed Quant and Offset defaults to 24,26,1,1,2,2 to increase effectiveness, but still within sensible limits.
# (see for details: http://forum.doom9.org/showthread.php?p=810932#post810932)

# Changes 2011-11-29: (06_taro)
# - Replaced (chroma=uv>2?"process":"ignore") by (chroma=uv>2?"process":"copy") to avoid garbage clip when uv=2.
# The formal parameter is not used by MaskTools2 any more, if ever used.
# Foxyshadis once mentioned chroma="ignore" but I had never found a document containing it.

# Changes 2014-10-20:
# - Now calling to plugin deblock exclusively and not to the older function deblock of DGDecode

function Deblock_QED ( clip clp, int "quant1", int "quant2",
\ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" )
{

quant1 = default( quant1, 24 ) # Strength of block edge deblocking
quant2 = default( quant2, 26 ) # Strength of block internal deblocking

aOff1 = default( aOff1, 1 ) # halfway "sensitivity" and halfway a strength modifier for borders
aOff2 = default( aOff2, 1 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
bOff1 = default( bOff1, 2 ) # "sensitivity to detect blocking" for borders
bOff2 = default( bOff2, 2 ) # "sensitivity to detect blocking" for block interiors

uv = default( uv, 3 ) # u=3 -> use proposed method for chroma deblocking
# u=2 -> no chroma deblocking at all (fastest method)
# u=1|-1 -> directly use chroma debl. from the normal|strong deblock()

# add borders if clp is not mod 8
padX = clp.width%8 == 0 ? 0 : (8 - clp.width%8)
padY = clp.height%8 == 0 ? 0 : (8 - clp.height%8)
clp=clp.pointresize(clp.width+padX, clp.height+padY, 0, 0, clp.width+padX, clp.height+padY)

# block
block = clp.mt_LutSpa(mode="absolute",expr="x 1 + 8 % 1 < x 8 % 1 < y 1 + 8 % 1 < y 8 % 1 < | | | 255 0 ?",U=3,V=3)

# create normal deblocking (for block borders) and strong deblocking (for block interiour)
normal = clp.Deblock_deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1)
strong = clp.Deblock_deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2)

# build difference maps of both
normalD = mt_makediff(clp,normal,chroma=uv>2?"process":"copy")
strongD = mt_makediff(clp,strong,chroma=uv>2?"process":"copy")

# separate border values of the difference maps, and set the interiours to '128'
normalD2 = mt_lutxy(normalD,block,expr="y 255 == x 128 ?",U=uv,V=uv)
strongD2 = mt_lutxy(StrongD,block,expr="y 255 == x 128 ?",U=uv,V=uv)

# interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
# (Note: this is not fully accurate, but a reasonable approximation.)
# add borders if clp is not mod 16
sw=strongD2.width sh=strongD2.height
remX = sw%16 == 0 ? 0 : (16 - sw%16)
remY = sh%16 == 0 ? 0 : (16 - sh%16)
strongD3 = strongD2.pointresize(sw+remX, sh+remY, 0, 0, sw+remX, sh+remY).mt_lut(expr="x 128 - 1.01 * 128 +",U=uv,V=uv)\
.dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0).crop(0,0,-remX,-remY)

# apply compensation from "normal" deblocking to the borders of
# the full-block-compensations calculated from "strong" deblocking ...
strongD4 = mt_lutxy(strongD3,normalD2,expr="y 128 == x y ?",U=uv,V=uv)

# ... and apply it.
deblocked= mt_makediff(clp,strongD4,chroma=uv>2?"process":"copy")

# simple decisions how to treat chroma
deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked

deblocked.crop(0,0,-padX,-padY) # remove mod 8 borders
}

Motenai Yoda
8th May 2016, 23:00
modded a bit to avoid useless chroma processing

# Changes 2008-08-18: (Didée)
# - Replaced the ugly stackXXX cascade with mt_LutSpa() (requires MaskTools v2.0a35)
# - Changed Quant and Offset defaults to 24,28,2,4,4,8

# Changes 2010-05-25:
# - Explicitly specified parameters of mt_LutSpa()
# (required due to position of new 'biased' parameter, starting from MaskTools 2.0a43)
# - Non mod 16 input is now padded with borders internally

# Changes 2010-08-18:
# - Replaced AddBorders with PointResize
# - Changed Quant and Offset defaults to 18,19,3,4,1,1 to reduce blurring

# Changes 2010-10-16:
# - Replaced 'relative' with the new 'mode' parameter in mt_LutSpa(), starting from MaskTools 2.0a45
# - Changed Quant and Offset defaults to 24,26,1,1,2,2 to increase effectiveness, but still within sensible limits.
# (see for details: http://forum.doom9.org/showthread.php?p=810932#post810932)

# Changes 2011-11-29: (06_taro)
# - Replaced (chroma=uv>2?"process":"ignore") by (chroma=uv>2?"process":"copy") to avoid garbage clip when uv=2.
# The formal parameter is not used by MaskTools2 any more, if ever used.
# Foxyshadis once mentioned chroma="ignore" but I had never found a document containing it.

# Changes 2014-10-20:
# - Now calling to plugin deblock exclusively and not to the older function deblock of DGDecode

# Changes 2016-5-8: (Motenai Yoda)
# - Added internal variable uvp for skip chroma post processing when uv!=3
# - Replaced most (chroma=uv>2?"process":"copy") and all U=uv,V=uv by U=uvp,V=uvp to trash chroma planes when uv!=3
# - Replaced last (chroma=uv>2?"process":"copy") by (U= uv<2 ? 1 : uv,V= uv<2 ? 1 : uv) to trash chroma planes when uv=1|-1

function Deblock_QED ( clip clp, int "quant1", int "quant2",
\ int "aOff1", int "bOff1", int "aOff2", int "bOff2", int "uv" )
{

quant1 = default( quant1, 24 ) # Strength of block edge deblocking
quant2 = default( quant2, 26 ) # Strength of block internal deblocking

aOff1 = default( aOff1, 1 ) # halfway "sensitivity" and halfway a strength modifier for borders
aOff2 = default( aOff2, 1 ) # halfway "sensitivity" and halfway a strength modifier for block interiors
bOff1 = default( bOff1, 2 ) # "sensitivity to detect blocking" for borders
bOff2 = default( bOff2, 2 ) # "sensitivity to detect blocking" for block interiors

uv = default( uv, 3 ) # u=3 -> use proposed method for chroma deblocking
# u=2 -> no chroma deblocking at all (fastest method)
# u=1|-1 -> directly use chroma debl. from the normal|strong deblock()

#select once if chroma will be post-processed or not
uvp = uv==3 ? 3 : 1

# add borders if clp is not mod 8
padX = clp.width%8 == 0 ? 0 : (8 - clp.width%8)
padY = clp.height%8 == 0 ? 0 : (8 - clp.height%8)
clp=clp.pointresize(clp.width+padX, clp.height+padY, 0, 0, clp.width+padX, clp.height+padY)

# block
block = clp.mt_LutSpa(mode="absolute",expr="x 1 + 8 % 1 < x 8 % 1 < y 1 + 8 % 1 < y 8 % 1 < | | | 255 0 ?",U=3,V=3)

# create normal deblocking (for block borders) and strong deblocking (for block interiour)
normal = clp.Deblock_deblock(quant=quant1,aOffset=aOff1,bOffset=bOff1)
strong = clp.Deblock_deblock(quant=quant2,aOffset=aOff2,bOffset=bOff2)

# build difference maps of both
normalD = mt_makediff(clp,normal,U=uvp,V=uvp)
strongD = mt_makediff(clp,strong,U=uvp,V=uvp)

# separate border values of the difference maps, and set the interiours to '128'
normalD2 = mt_lutxy(normalD,block,expr="y 255 == x 128 ?",U=uvp,V=uvp)
strongD2 = mt_lutxy(StrongD,block,expr="y 255 == x 128 ?",U=uvp,V=uvp)

# interpolate the border values over the whole block: DCTFilter can do it. (Kiss to Tom Barry!)
# (Note: this is not fully accurate, but a reasonable approximation.)
# add borders if clp is not mod 16
sw=strongD2.width sh=strongD2.height
remX = sw%16 == 0 ? 0 : (16 - sw%16)
remY = sh%16 == 0 ? 0 : (16 - sh%16)
strongD3 = strongD2.pointresize(sw+remX, sh+remY, 0, 0, sw+remX, sh+remY).mt_lut(expr="x 128 - 1.01 * 128 +",U=uv,V=uv)\
.dctfilter(1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0).crop(0,0,-remX,-remY)

# apply compensation from "normal" deblocking to the borders of
# the full-block-compensations calculated from "strong" deblocking ...
strongD4 = mt_lutxy(strongD3,normalD2,expr="y 128 == x y ?",U=uvp,V=uvp)

# ... and apply it.
deblocked= mt_makediff(clp,strongD4,U= uv<2 ? 1 : uv,V= uv<2 ? 1 : uv)

# simple decisions how to treat chroma
deblocked = (uv<0) ? deblocked.mergechroma(strong) : uv<2 ? deblocked.mergechroma(normal) : deblocked

deblocked.crop(0,0,-padX,-padY) # remove mod 8 borders
}

Edit: foxyshadis's dctfilter 1.5.0 version seems to be still a bit bugged

Reel.Deel
11th June 2016, 04:20
Edit: foxyshadis's dctfilter 1.5.0 version seems to be still a bit bugged

Care to share more information? I know the parameters fdct, idct, offx, and offy are very unstable. I'd be nice to have a modern rewrite...

Motenai Yoda
11th June 2016, 13:30
setmtmode(3)
mpeg2source("animaniacs_intro.demuxed.d2v")
setmtmode(2)
tfm()
DctFilter(1, 0, 1, 0, 1, 0, 1, 0)
Distributor()


https://i.imgur.com/shH5fBA.png
https://i.imgur.com/RSzGQ4v.png

MysteryX
30th August 2017, 04:19
Is there a version of Deblock that works in 16-bit?

Running Deblock on its own on 16-bit content adds blocks instead of removing them

Edit: foxyshadis's dctfilter 1.5.0 version seems to be still a bit bugged
Chikuzen's version is probably more stable
https://github.com/chikuzen/DCTFilter

Lirk
28th September 2018, 22:10
Inadvertently Deblock_QED called indifferently to plugin deblock or function deblock of DGDecode, this could be a problem if a value of 'quant'> 51 is required.

This doesn't work with the last version (1.3) of Deblock filter.
Script error: There is no function named 'Deblock_deblock'.

StainlessS
28th September 2018, 22:59
Post output of
AvsMeter avsinfo

EDIT: If 1.3 is v2.6 plug, and you are using avs v2.58, then will produce " Script error: There is no function named 'Deblock_deblock'."
EDIT: v1.3 is a v2.60 dll, will not work for avs v2.58.

EDIT: Requires "VcRuntime140.dll".
vcruntime140.dll is a part of "Microsoft Visual C++ Redistributable Packages for Visual Studio 2015" and is often required for running programs
developed with Visual C++. Some games or applications may need the file in the game/application installation folder. ...
If using a 64bit Windows, install both.

StainlessS
28th September 2018, 23:39
Further to above.
NOTE, Mismatch between docs and actuality.

Readme.md

## Deblock

Simple deblocking filter by Manao and Fizick. It does a deblocking of the picture, using the deblocking filter of h264.

This version has been back-ported from VapourSynth with high-bit-depth support. All credits go to those who wrote the code.

### Usage
```
Deblock (clip, quant=25, aOffset=0, bOffset=0, planes="yuv")
```
* *quant* - the higher the quant, the stronger the deblocking. It can range from 0 to 60.
* *aOffset* - quant modifier to the blocking detector threshold. Setting it higher means than more edges will deblocked.
* *bOffset* - another quant modifier, for block detecting and for deblocking's strength. There again, the higher, the stronger.
* *planes* - specifies which planes to process between y, u and v.


Changelog.txt

v1.3 (2018-05-29) - Etienne Charland
- Back-ported code from VapourSynth
- Added high-bit-depth support
- Added Planes parameter to specify which planes to process


Actuality [EDIT: Extracted from dll (EDIT: 32bit)]


Deblock_ORDERED_Function_List


There follows a list of all function names together with CPP style argument specifiers that inform
Avisynth the argument types and optional names. Optional arguments have square brackets surrounding
their name as in [name] and are followed by a type specifier character that gives the type.
Unnamed arguments are not optional. eg "cc[arg1]b[arg2]i" would be two compulsory unnamed clip args,
followed by optional 'arg1' of type bool and optional 'arg2' of type int.

# Argument type specifier strings.
c - Video Clip
i - Integer number
f - Float number
s - String
b - boolean
. - Any type (dot)
# Array Specifiers
i* - Integer Array, zero or more
i+ - Integer Array, one or more
.* - Any type Array, zero or more
.+ - Any type Array, one or more
# Etc
###################################


Deblock "c[quant]i[aOffset]i[bOffset]i[mmx]b[isse]b"


EDIT:
init.cpp

#define WIN32_LEAN_AND_MEAN
#include "avisynth.h"
#include "deblock.h"

AVSValue __cdecl Create_Deblock(AVSValue args, void*, IScriptEnvironment* env) {
enum { CLIP, QUANT, AOFFSET, BOFFSET, _PLANES };
PClip input = args[CLIP].AsClip();
VideoInfo vi = input->GetVideoInfo();

const int padWidth = (vi.width & 7) ? 8 - vi.width % 8 : 0;
const int padHeight = (vi.height & 7) ? 8 - vi.height % 8 : 0;

if (padWidth || padHeight) {
AVSValue sargs[5] = { input, vi.width + padWidth, vi.height + padHeight, vi.width + padWidth, vi.height + padHeight };
const char *nargs[5] = { 0, 0, 0, "src_width", "src_height" };
input = env->Invoke("PointResize", AVSValue(sargs, 5), nargs).AsClip();
}

return new Deblock(input, args[QUANT].AsInt(25), args[AOFFSET].AsInt(0), args[BOFFSET].AsBool(0), args[_PLANES].AsString(), env);
}

const AVS_Linkage *AVS_linkage = nullptr;

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors) {
AVS_linkage = vectors;
env->AddFunction("Deblock", "c[quant]i[aOffset]i[bOffset]i[planes]s", Create_Deblock, 0);
return "Blocks are kawaii uguu~!";
}

Seems that dll and source code are only distantly related ???

EDIT: Perhaps someone with VS2015 can re-compile.

EDIT: Looks like 64 bit dll might be correct version, 32 bit borked.

GMJCZP
24th May 2021, 17:33
I am having a problem with the script, I am using Deblock 1.3, dctfilter 0.5.1 and masktools2 2.2.26, the image looks like a plaid.

Sample (http://www.filedropper.com/sample_10)

Script:

LwLibavVideoSource ("Sample.mp4")
Deblock_QED()

Edit: I have the last version of Lsmash and Avs+.

kedautinh12
25th May 2021, 00:05
Here for new ver: Deblock_QED()
https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/Deblock_QED_MT2.avsi

GMJCZP
25th May 2021, 02:11
It works, thanks!

GMJCZP
25th May 2021, 02:18
Now I have a question, does the script take into account the difference between the Deblock plugin and DGDecode's Deblock() function? I ask because I made a correction on it, see post # 13.

real.finder
25th May 2021, 10:16
Now I have a question, does the script take into account the difference between the Deblock plugin and DGDecode's Deblock() function? I ask because I made a correction on it, see post # 13.

I think no, but why? last DGDecode I think was ported from https://github.com/Asd-g/MPEG2DecPlus so it should has no other than the Decoder

GMJCZP
25th May 2021, 12:11
Some tests should be done to see if the difference in behavior is maintained or not when Quant> 51.

Thanks for the script real.finder.

Atlantis
29th July 2021, 14:28
Does Deblock_QED work with 10bit input? I get garbage unless I convert to 8bit. What deblocking filters do?

real.finder
30th July 2021, 12:31
Does Deblock_QED work with 10bit input? I get garbage unless I convert to 8bit. What deblocking filters do?

my edit of it should work if you got the uptodate plugins

if you have DGDecode.dll then maybe it the problem since it have deblock function too

GMJCZP
30th July 2021, 23:57
if you have DGDecode.dll then maybe it the problem since it have deblock function too

Sip, see post #13 (https://forum.doom9.org/showthread.php?p=1697386#post1697386)