redfordxx
8th May 2006, 22:13
Hi,
I tried Deblock_QED but it seemed a bit weak for my purposes, so I used some of its ideas and produced something as follows (first version, probably needs tuning, your ideas are welcome, I you find it interesting to bother with). It should be stronger than QED, but still should preserve detail.
BTW: I several times refer to QED here, because who knows it might faster understand this...
ReDeblock.avsi:
###################################
# ReDeblock 0.1 by Redford
#
# Thanx to all doom9 members and non-members for tools and inspiration,
# especially to Didee (QED presence here is obvious)
#
# imported Patterns.avsi
# plugged mt_masktools.dll and LinearBlock_02Nov05.dll
#
###################################
function ReDeblock(clip "orig",clip "debl", int "correction", int "q", int "a", int "b", int "reduce", int "test")
{
test=default(test,0) #to set different outputs for testing purposes
correction=default(correction,2) #correction of wildly shifted values 0=off, else acc. to convolutions
reduce=default(reduce,1) #reducing the second deblocking, 0=off
q=default(q,0) #parameters for Deblock, by default, the deblocker does nothing
a=default(a,10)
b=default(b,10)
#find blocking
ptrn1=PtrnBlock(orig,3,0,1,2,4)
diff1=mt_makediff(debl,orig,y=3,u=3,v=3)
diff2=mt_lutxy(diff1,ptrn1,"y 0 == x 128 ?",y=3,u=3,v=3)
linb=diff2.LinearBlock()
#try to restore medium-size detail
mask1=linb.mt_convolution("1 2 2 2 1","1 2 2 2 1",y=3,u=3,v=3)
mask2=linb.mt_convolution("1 1 1 1 1 1 1","1 1 1 1 1 1 1",y=3,u=3,v=3)
mask3=mask2 # future --- nice to have an adaptive one, coz on really hard blocking the mask1 is contraproductive, on small and normal blocking the mask2 doesnot restore the detail so much
linb2=Select(correction,linb,mt_makediff(linb,mask1,y=3,u=3,v=3),mt_makediff(linb,mask2,y=3,u=3,v=3),mt_makediff(linb,mask3,y=3,u=3,v=3))
#apply deblocking
debl2=mt_adddiff(orig,linb2,y=3,u=3,v=3)
#here maybe some spatial smoothing, not to confuse the second deblocker
debl3=debl2
#second deblocking
debl4=debl3.Deblock(q,a,b)
#reducing the second deblocking
diff3=mt_lutxy(debl4,debl3,"x y > x y - 1 - 128 + x y == 128 x y - 1 + 128 + ? ?",y=3,u=3,v=3)
debl5=Select(reduce,debl4,mt_adddiff(debl3,diff3,y=3,u=3,v=3))
return(Select(test, debl5, \
debl4, \
debl3, \
debl2, \
linb2.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
linb.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
diff3.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
diff2.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
diff1.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3)))
#return(debl5)
}
function ReDeblockLite(clip "orig",clip "debl", int "correction")
{
correction=default(correction,2)
#find blocking
ptrn1=PtrnBlock(orig,3,0,1,2,4)
diff1=mt_makediff(debl,orig,y=3,u=3,v=3)
diff2=mt_lutxy(diff1,ptrn1,"y 0 == x 128 ?",y=3,u=3,v=3)
linb=diff2.LinearBlock()
#try to restore medium-size detail
mask1=linb.mt_convolution("1 2 2 2 1","1 2 2 2 1",y=3,u=3,v=3)
mask2=linb.mt_convolution("1 1 1 1 1 1 1","1 1 1 1 1 1 1",y=3,u=3,v=3)
mask3=mask2 # future --- nice to have an adaptive one, coz on really hard blocking the mask1 is contraproductive, on small and normal blocking the mask2 doesnot restore the detail so much
linb2=Select(correction,linb,mt_makediff(linb,mask1,y=3,u=3,v=3),mt_makediff(linb,mask2,y=3,u=3,v=3),mt_makediff(linb,mask3,y=3,u=3,v=3))
#apply deblocking
debl2=mt_adddiff(orig,linb2,y=3,u=3,v=3)
return(debl2)
}
There are two versions of it. Originally it was intended as the non-lite version, but it seems already the lite version does pretty good job.
[EDIT] 30.5.2006: I discovered some issues in this deblockers performance and I don't recommend using it. If you are searching for something new to try, I'll appreciate feedback on SmoothDeblock (http://forum.doom9.org/showthread.php?t=111526) which is still under developement but IMHO safe to use.
I tried Deblock_QED but it seemed a bit weak for my purposes, so I used some of its ideas and produced something as follows (first version, probably needs tuning, your ideas are welcome, I you find it interesting to bother with). It should be stronger than QED, but still should preserve detail.
BTW: I several times refer to QED here, because who knows it might faster understand this...
ReDeblock.avsi:
###################################
# ReDeblock 0.1 by Redford
#
# Thanx to all doom9 members and non-members for tools and inspiration,
# especially to Didee (QED presence here is obvious)
#
# imported Patterns.avsi
# plugged mt_masktools.dll and LinearBlock_02Nov05.dll
#
###################################
function ReDeblock(clip "orig",clip "debl", int "correction", int "q", int "a", int "b", int "reduce", int "test")
{
test=default(test,0) #to set different outputs for testing purposes
correction=default(correction,2) #correction of wildly shifted values 0=off, else acc. to convolutions
reduce=default(reduce,1) #reducing the second deblocking, 0=off
q=default(q,0) #parameters for Deblock, by default, the deblocker does nothing
a=default(a,10)
b=default(b,10)
#find blocking
ptrn1=PtrnBlock(orig,3,0,1,2,4)
diff1=mt_makediff(debl,orig,y=3,u=3,v=3)
diff2=mt_lutxy(diff1,ptrn1,"y 0 == x 128 ?",y=3,u=3,v=3)
linb=diff2.LinearBlock()
#try to restore medium-size detail
mask1=linb.mt_convolution("1 2 2 2 1","1 2 2 2 1",y=3,u=3,v=3)
mask2=linb.mt_convolution("1 1 1 1 1 1 1","1 1 1 1 1 1 1",y=3,u=3,v=3)
mask3=mask2 # future --- nice to have an adaptive one, coz on really hard blocking the mask1 is contraproductive, on small and normal blocking the mask2 doesnot restore the detail so much
linb2=Select(correction,linb,mt_makediff(linb,mask1,y=3,u=3,v=3),mt_makediff(linb,mask2,y=3,u=3,v=3),mt_makediff(linb,mask3,y=3,u=3,v=3))
#apply deblocking
debl2=mt_adddiff(orig,linb2,y=3,u=3,v=3)
#here maybe some spatial smoothing, not to confuse the second deblocker
debl3=debl2
#second deblocking
debl4=debl3.Deblock(q,a,b)
#reducing the second deblocking
diff3=mt_lutxy(debl4,debl3,"x y > x y - 1 - 128 + x y == 128 x y - 1 + 128 + ? ?",y=3,u=3,v=3)
debl5=Select(reduce,debl4,mt_adddiff(debl3,diff3,y=3,u=3,v=3))
return(Select(test, debl5, \
debl4, \
debl3, \
debl2, \
linb2.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
linb.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
diff3.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
diff2.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3), \
diff1.mt_lut("x 128 - 20 * 128 +",y=3,u=3,v=3)))
#return(debl5)
}
function ReDeblockLite(clip "orig",clip "debl", int "correction")
{
correction=default(correction,2)
#find blocking
ptrn1=PtrnBlock(orig,3,0,1,2,4)
diff1=mt_makediff(debl,orig,y=3,u=3,v=3)
diff2=mt_lutxy(diff1,ptrn1,"y 0 == x 128 ?",y=3,u=3,v=3)
linb=diff2.LinearBlock()
#try to restore medium-size detail
mask1=linb.mt_convolution("1 2 2 2 1","1 2 2 2 1",y=3,u=3,v=3)
mask2=linb.mt_convolution("1 1 1 1 1 1 1","1 1 1 1 1 1 1",y=3,u=3,v=3)
mask3=mask2 # future --- nice to have an adaptive one, coz on really hard blocking the mask1 is contraproductive, on small and normal blocking the mask2 doesnot restore the detail so much
linb2=Select(correction,linb,mt_makediff(linb,mask1,y=3,u=3,v=3),mt_makediff(linb,mask2,y=3,u=3,v=3),mt_makediff(linb,mask3,y=3,u=3,v=3))
#apply deblocking
debl2=mt_adddiff(orig,linb2,y=3,u=3,v=3)
return(debl2)
}
There are two versions of it. Originally it was intended as the non-lite version, but it seems already the lite version does pretty good job.
[EDIT] 30.5.2006: I discovered some issues in this deblockers performance and I don't recommend using it. If you are searching for something new to try, I'll appreciate feedback on SmoothDeblock (http://forum.doom9.org/showthread.php?t=111526) which is still under developement but IMHO safe to use.