rkalwaitis
26th January 2010, 14:05
I was looking at a script by Caroliano; SMDegrain. It is a rather simple clip and straight forward. I added contrasharpening by Didee and was attempting to incorporate an occlusion mask as I have problems with blocking, with this script. I tried to use the example from MVtools documentation as shown below, but I was not smart enough to use it. So I opted for an easier way for me at least by calling Deblock_QED. Still trying to figure out the best settings but that is okay. I would really like to incorporate the "blocky blur problem" way below. But my real question is would this method be worth it? I have never seen it used. Everyone usually uses deblock_qed. But I was thinking that the version using compensation from mvtools may be the way to go since the mdegrain is from the same package of goodies. So based on the vast knowledge base out there, who has tried it and was it worth it?
From Mvtools documentation. To blur problem (blocky) areas of compensated frame with occlusion mask: I would love to try this way for deblocking.
AVISource("c:\test.avi") # or MPEG2Source, DirectShowSource, some previous filter, etc
super = MSuper()
vectors = MAnalyse(super, isb = false)
compensation = MCompensate(super,vectors) # or use MFlow function here
# prepare blurred frame with some strong blur or deblock function:
blurred = compensation.DeBlock(quant=51) # Use DeBlock function here
badmask = MMask(vectors, kind = 2, ml=50)
overlay(compensation,blurred,mask=badmask) # or use faster MaskedMerge function of MaskTools
Here is the script
###########################################################################################
### ###
### Simple MDegrain - SMDegrain() ###
### ###
### By Caroliano ###
### ###
### Special Thanks: Sagekilla, Didée and MVtools people ###
### ###
### v0.2 - 24 Jan 2010 ###
### ###
################################################################################################
###
### +-----------+
### | CHANGELOG |
### +-----------+
###
### v0.2 : - Added this introductory section
### - Added more parameters
###
### v0.1 : - Basic working version
### - Not released
###
###
### +--------------+
### | DEPENDENCIES |
### +--------------+
###
### -> MVtools2 (v2.5.8.1 or higher)
### -> MVtools depends on anything?? If yes, those things.
###
###
###
### +------------------+
### | BASIC PARAMETERS |
### +------------------+
###
###
### tr [int: 1, 2, 3]
### --------------
### Temporal radius. Select between MDegrain 1, 2 or 3. Higher is better, but also much slower.
### Default is 2.
###
###
### thSAD [int]
### --------------
### Strenght of denoising. Low values can result in staggered denoising,
### large values can result in ghosting and artefactes. Default is 400.
###
###
### plane [int: 1, 2, 3, 4]
### --------------
### Select the color planes you wish to process:
### 0 - luma only, 1 - chroma U, 2 - chroma V, 3 - both chromas, 4 - all.
### Default is 4 - all.
###
###
###
### +---------------------+
### | ADVANCED PARAMETERS |
### +---------------------+
###
###
### limit [int: 1 - 255]
### --------------
### Maximal change of pixel luma (post-process like DeGrainMedian plugin
### and LimitChange function of SSETools plugin, to prevent some artefactes).
### Default is 255 (no limit).
###
###
### limitc [int: 1 - 255]
### --------------
### Maximal change of pixel chroma. Default value = limit.
###
###
### pel [int: 1, 2, 4]
### --------------
### Accuracy of the motion estimation. 1 means a precision to the pixel.
### 2 means a precision to half a pixel. 4 means a precision to quarter a pixel, produced by
### spatial interpolation (more accurate but slower and not always better due to big level scale step).
### Default is 2.
###
###
### sharp [int: 0, 1, 2]
### --------------
### Subpixel interpolation method for pel=2,4.
### Use 0 for soft interpolation (bilinear), 1 for bicubic interpolation (4 tap Catmull-Rom),
### 2 for sharper Wiener interpolation (6 tap, similar to Lanczos. Default is 2.
###
###
### blksize [int: 4, 8, 16]
### --------------
### Size of a block (horizontal). Default is 8.
### Larger blocks are less sensitive to noise, are faster, but also less accurate.
###
###
### overlap [int]
### --------------
### Must be *even* and *less* than block size. Try use overlap value from blksize/4 to blksize/2.
### The greater overlap, the more blocks number, and the lesser the processing speed.
### Default is 2
###
###
### Search [int= 0, 1, 2, 3, 4, 5]
### --------------
### 0= 'OneTimeSearch', 1 = 'NStepSearch', 2= Logarithmic, 3= Exhaustive, 4= Hexagon, 5= Uneven Multi Hexagon
### Default is 4. See details at MVtools documentation.
### http://avisynth.org.ru/mvtools/mvtools2.html
###
###
###
###
### +-------------+
### | FINAL NOTES |
### +-------------+
###
### If there is an important parameter not implemented, please ask.
### Or better yet, implement it yourself and post in the Doom9 thread.
###
### Many paremeters will likely never be implemented,
### and you are better off using the original MVtools way.
###
################################################################################################
function SMDegrain ( clip input, int "tr", int "thSAD", int "plane", int "limit", int "limitc", int "frames", int "strength", \
int "pel", int "sharp", int "blksize", int "overlap", int "search", \
bool "contrasharp", bool "unblock")
{
clip = input
tr = default( tr, 2 )
thSAD = default( thSAD, 400 )
plane = default( plane, 4 )
limit = default( limit, 255 )
limitc = default( limitc,limit)
pel = default( pel, 2 )
sharp = default( sharp, 2 )
blksize = default( blksize, 8 )
overlap = default( overlap, 2 )
search = default( search, 4 )
contrasharp = default(contrasharp, false)
unblock = default(unblock, false)
#quant1 = default( quant1 , 0 ) # quant 1 for deblock_qed
#quant2 = default( quant2 , 45 ) # quant 2 for deblock_qed
#uv = default( uv , 1 ) # uv for deblock_qed
FUNCTION ContraSharpening(denoised, clip)
{
# contra-sharpening: sharpen the denoised clip, but don't add more to any pixel than what was removed previously.
# script function from Didee from the VERY GRAINY thread
s = denoised.minblur(1,1) # Damp down remaining spots of the denoised clip.
allD = mt_makediff(clip,denoised) # The difference achieved by the denoising.
ssD = mt_makediff(s,s.removegrain(11,-1)) # The difference of a simple kernel blur.
ssDD = ssD.repair(allD,1) # Limit the difference to the max of what the denoising removed locally.
ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?") # abs(diff) after limiting may not be bigger than before.
denoised.mt_adddiff(ssDD,U=2,V=2) # Apply the limited difference. (Sharpening is just inverse blurring.)
RETURN (last)
}
# Motion vector search
super = input.MSuper(pel=pel, sharp=sharp)
bv3 = (tr > 2) ?
\ super.MAnalyse(isb = true, delta = 3, overlap=overlap, blksize=blksize, search=search) : BlankClip
bv2 = (tr > 1) ?
\ super.MAnalyse(isb = true, delta = 2, overlap=overlap, blksize=blksize, search=search) : BlankClip
bv1 = super.MAnalyse(isb = true, delta = 1, overlap=overlap, blksize=blksize, search=search)
fv1 = super.MAnalyse(isb = false, delta = 1, overlap=overlap, blksize=blksize, search=search)
fv2 = (tr > 1) ?
\ super.MAnalyse(isb = false, delta = 2, overlap=overlap, blksize=blksize, search=search) : BlankClip
fv3 = (tr > 2) ?
\ super.MAnalyse(isb = false, delta = 3, overlap=overlap, blksize=blksize, search=search) : BlankClip
# Finally, MDegrain
output= (tr == 3) ? input.MDegrain3(super, bv1, fv1, bv2, fv2, bv3, fv3, thSAD=thSAD, limit=limit, limitc=limitc) :
\ (tr == 2) ? input.MDegrain2(super, bv1, fv1, bv2, fv2, thSAD=thSAD, limit=limit, limitc=limitc) :
\ input.MDegrain1(super, bv1, fv1, thSAD=thSAD, limit=limit, limitc=limitc)
output = contrasharp ? ContraSharpening(output,clip) : output
# Make the call to deblock_qed if asked
output = (unblock) ? input.deblock_qed(quant1=24,quant2=28,uv=3) : output
return (output)
}
As you may have noticed I could not get it to get my attempted incorporated QED_Deblock to work properly and ended up changing the values myself.
Thanks
From Mvtools documentation. To blur problem (blocky) areas of compensated frame with occlusion mask: I would love to try this way for deblocking.
AVISource("c:\test.avi") # or MPEG2Source, DirectShowSource, some previous filter, etc
super = MSuper()
vectors = MAnalyse(super, isb = false)
compensation = MCompensate(super,vectors) # or use MFlow function here
# prepare blurred frame with some strong blur or deblock function:
blurred = compensation.DeBlock(quant=51) # Use DeBlock function here
badmask = MMask(vectors, kind = 2, ml=50)
overlay(compensation,blurred,mask=badmask) # or use faster MaskedMerge function of MaskTools
Here is the script
###########################################################################################
### ###
### Simple MDegrain - SMDegrain() ###
### ###
### By Caroliano ###
### ###
### Special Thanks: Sagekilla, Didée and MVtools people ###
### ###
### v0.2 - 24 Jan 2010 ###
### ###
################################################################################################
###
### +-----------+
### | CHANGELOG |
### +-----------+
###
### v0.2 : - Added this introductory section
### - Added more parameters
###
### v0.1 : - Basic working version
### - Not released
###
###
### +--------------+
### | DEPENDENCIES |
### +--------------+
###
### -> MVtools2 (v2.5.8.1 or higher)
### -> MVtools depends on anything?? If yes, those things.
###
###
###
### +------------------+
### | BASIC PARAMETERS |
### +------------------+
###
###
### tr [int: 1, 2, 3]
### --------------
### Temporal radius. Select between MDegrain 1, 2 or 3. Higher is better, but also much slower.
### Default is 2.
###
###
### thSAD [int]
### --------------
### Strenght of denoising. Low values can result in staggered denoising,
### large values can result in ghosting and artefactes. Default is 400.
###
###
### plane [int: 1, 2, 3, 4]
### --------------
### Select the color planes you wish to process:
### 0 - luma only, 1 - chroma U, 2 - chroma V, 3 - both chromas, 4 - all.
### Default is 4 - all.
###
###
###
### +---------------------+
### | ADVANCED PARAMETERS |
### +---------------------+
###
###
### limit [int: 1 - 255]
### --------------
### Maximal change of pixel luma (post-process like DeGrainMedian plugin
### and LimitChange function of SSETools plugin, to prevent some artefactes).
### Default is 255 (no limit).
###
###
### limitc [int: 1 - 255]
### --------------
### Maximal change of pixel chroma. Default value = limit.
###
###
### pel [int: 1, 2, 4]
### --------------
### Accuracy of the motion estimation. 1 means a precision to the pixel.
### 2 means a precision to half a pixel. 4 means a precision to quarter a pixel, produced by
### spatial interpolation (more accurate but slower and not always better due to big level scale step).
### Default is 2.
###
###
### sharp [int: 0, 1, 2]
### --------------
### Subpixel interpolation method for pel=2,4.
### Use 0 for soft interpolation (bilinear), 1 for bicubic interpolation (4 tap Catmull-Rom),
### 2 for sharper Wiener interpolation (6 tap, similar to Lanczos. Default is 2.
###
###
### blksize [int: 4, 8, 16]
### --------------
### Size of a block (horizontal). Default is 8.
### Larger blocks are less sensitive to noise, are faster, but also less accurate.
###
###
### overlap [int]
### --------------
### Must be *even* and *less* than block size. Try use overlap value from blksize/4 to blksize/2.
### The greater overlap, the more blocks number, and the lesser the processing speed.
### Default is 2
###
###
### Search [int= 0, 1, 2, 3, 4, 5]
### --------------
### 0= 'OneTimeSearch', 1 = 'NStepSearch', 2= Logarithmic, 3= Exhaustive, 4= Hexagon, 5= Uneven Multi Hexagon
### Default is 4. See details at MVtools documentation.
### http://avisynth.org.ru/mvtools/mvtools2.html
###
###
###
###
### +-------------+
### | FINAL NOTES |
### +-------------+
###
### If there is an important parameter not implemented, please ask.
### Or better yet, implement it yourself and post in the Doom9 thread.
###
### Many paremeters will likely never be implemented,
### and you are better off using the original MVtools way.
###
################################################################################################
function SMDegrain ( clip input, int "tr", int "thSAD", int "plane", int "limit", int "limitc", int "frames", int "strength", \
int "pel", int "sharp", int "blksize", int "overlap", int "search", \
bool "contrasharp", bool "unblock")
{
clip = input
tr = default( tr, 2 )
thSAD = default( thSAD, 400 )
plane = default( plane, 4 )
limit = default( limit, 255 )
limitc = default( limitc,limit)
pel = default( pel, 2 )
sharp = default( sharp, 2 )
blksize = default( blksize, 8 )
overlap = default( overlap, 2 )
search = default( search, 4 )
contrasharp = default(contrasharp, false)
unblock = default(unblock, false)
#quant1 = default( quant1 , 0 ) # quant 1 for deblock_qed
#quant2 = default( quant2 , 45 ) # quant 2 for deblock_qed
#uv = default( uv , 1 ) # uv for deblock_qed
FUNCTION ContraSharpening(denoised, clip)
{
# contra-sharpening: sharpen the denoised clip, but don't add more to any pixel than what was removed previously.
# script function from Didee from the VERY GRAINY thread
s = denoised.minblur(1,1) # Damp down remaining spots of the denoised clip.
allD = mt_makediff(clip,denoised) # The difference achieved by the denoising.
ssD = mt_makediff(s,s.removegrain(11,-1)) # The difference of a simple kernel blur.
ssDD = ssD.repair(allD,1) # Limit the difference to the max of what the denoising removed locally.
ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?") # abs(diff) after limiting may not be bigger than before.
denoised.mt_adddiff(ssDD,U=2,V=2) # Apply the limited difference. (Sharpening is just inverse blurring.)
RETURN (last)
}
# Motion vector search
super = input.MSuper(pel=pel, sharp=sharp)
bv3 = (tr > 2) ?
\ super.MAnalyse(isb = true, delta = 3, overlap=overlap, blksize=blksize, search=search) : BlankClip
bv2 = (tr > 1) ?
\ super.MAnalyse(isb = true, delta = 2, overlap=overlap, blksize=blksize, search=search) : BlankClip
bv1 = super.MAnalyse(isb = true, delta = 1, overlap=overlap, blksize=blksize, search=search)
fv1 = super.MAnalyse(isb = false, delta = 1, overlap=overlap, blksize=blksize, search=search)
fv2 = (tr > 1) ?
\ super.MAnalyse(isb = false, delta = 2, overlap=overlap, blksize=blksize, search=search) : BlankClip
fv3 = (tr > 2) ?
\ super.MAnalyse(isb = false, delta = 3, overlap=overlap, blksize=blksize, search=search) : BlankClip
# Finally, MDegrain
output= (tr == 3) ? input.MDegrain3(super, bv1, fv1, bv2, fv2, bv3, fv3, thSAD=thSAD, limit=limit, limitc=limitc) :
\ (tr == 2) ? input.MDegrain2(super, bv1, fv1, bv2, fv2, thSAD=thSAD, limit=limit, limitc=limitc) :
\ input.MDegrain1(super, bv1, fv1, thSAD=thSAD, limit=limit, limitc=limitc)
output = contrasharp ? ContraSharpening(output,clip) : output
# Make the call to deblock_qed if asked
output = (unblock) ? input.deblock_qed(quant1=24,quant2=28,uv=3) : output
return (output)
}
As you may have noticed I could not get it to get my attempted incorporated QED_Deblock to work properly and ended up changing the values myself.
Thanks