Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th May 2010, 19:28   #1  |  Link
Bi11
Architect
 
Bi11's Avatar
 
Join Date: May 2010
Posts: 57
Deblock_QED updated (requires MaskTools 2.0a45 or later)

According to MaskTools 2.0a43 change log:
Quote:
* 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:

Code:
# 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:
Code:
# 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 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.

Last edited by Bi11; 16th October 2010 at 22:00. Reason: Updated defaults for greater effectiveness, but still within sensible limits
Bi11 is offline   Reply With Quote
Old 25th May 2010, 19:51   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Bi11 View Post
"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.
Gavino is offline   Reply With Quote
Old 30th May 2010, 21:38   #3  |  Link
Bi11
Architect
 
Bi11's Avatar
 
Join Date: May 2010
Posts: 57
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.
Bi11 is offline   Reply With Quote
Old 30th May 2010, 22:05   #4  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
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 ....
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 31st May 2010, 01:23   #5  |  Link
Bi11
Architect
 
Bi11's Avatar
 
Join Date: May 2010
Posts: 57
Code:
# (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.

Quote:
Originally Posted by Didée View Post
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.
Bi11 is offline   Reply With Quote
Old 31st May 2010, 07:51   #6  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Quote:
What settings would cause it to show up?
Try e.g. (quant1=50,quant2=10), and look closely.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 23rd June 2010, 23:32   #7  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 1,531
BTW, many thanks, Bi11 !
I just updated masktools and ran into the mt_lutspa error.
And your update helped.
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain)
"Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..."
Emulgator is offline   Reply With Quote
Old 13th January 2011, 01:35   #8  |  Link
DVDBob
Registered User
 
Join Date: May 2010
Posts: 120
Someone know where I can find version from 25 may 2010 ???
DVDBob is offline   Reply With Quote
Old 30th March 2012, 01:10   #9  |  Link
henryho_hk
Registered User
 
Join Date: Mar 2004
Posts: 889
Code:
# 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 )
}
henryho_hk is offline   Reply With Quote
Old 4th April 2012, 01:18   #10  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
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

Code:
# 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
}
Reel.Deel is offline   Reply With Quote
Old 2nd September 2012, 09:27   #11  |  Link
hydra3333
Registered User
 
Join Date: Oct 2009
Location: crow-land
Posts: 540
just a cross-reference, about strong settings: http://forum.doom9.org/showthread.php?p=1589519#post1589519
hydra3333 is offline   Reply With Quote
Old 4th March 2014, 02:34   #12  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
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?
lansing is offline   Reply With Quote
Old 21st October 2014, 00:56   #13  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 744
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:

Code:
# 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
}
GMJCZP is offline   Reply With Quote
Old 8th May 2016, 23:00   #14  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
modded a bit to avoid useless chroma processing

Code:
# 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
__________________
powered by Google Translator

Last edited by Motenai Yoda; 8th May 2016 at 23:13.
Motenai Yoda is offline   Reply With Quote
Old 11th June 2016, 04:20   #15  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
Quote:
Originally Posted by Motenai Yoda View Post
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...
Reel.Deel is offline   Reply With Quote
Old 11th June 2016, 13:30   #16  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
Code:
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
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 30th August 2017, 04:19   #17  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,559
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

Quote:
Originally Posted by Motenai Yoda View Post
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

Last edited by MysteryX; 30th August 2017 at 04:22.
MysteryX is offline   Reply With Quote
Old 28th September 2018, 22:10   #18  |  Link
Lirk
Registered User
 
Join Date: Jan 2018
Posts: 33
Quote:
Originally Posted by GMJCZP View Post
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.
Code:
 Script error: There is no function named 'Deblock_deblock'.
Lirk is offline   Reply With Quote
Old 28th September 2018, 22:59   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Post output of
Code:
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".
Quote:
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.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th September 2018 at 23:16.
StainlessS is offline   Reply With Quote
Old 28th September 2018, 23:39   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Further to above.
NOTE, Mismatch between docs and actuality.

Readme.md
Code:
## 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
Code:
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)]
Code:
        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
Code:
#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.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 29th September 2018 at 05:13.
StainlessS is offline   Reply With Quote
Reply

Tags
borders, deblock_qed, masktools, mod 8

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:04.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.