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 6th November 2011, 02:28   #341  |  Link
redfordxx
Registered User
 
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 791
I made a function for convolutions, so I am sharing it here.
Code:
function Convolve(clip c, val hor, val ver, float "tot", bool "lsb", int "hctr", int "vctr", int "y", int "u", int "v", bool "info")
{
#Performs flat convolution of given dimensions...v0.1 by redfordxx 
#needed Dither 1.12
# issues: Dither_resize16 applies kernel in reverse 
#         Dither_resize16 normalizes kernel, so tot parameter is ignored in 16bits
#Usage parameters:
#hor, ver arguments...dimensions of the convolution or kernels
#tot...divider, negative values are relative to sum of elements, so for 3x3 convo and tot=-2 the resul is tot=18, tot=0 is automatic. Doesnot work in 16bits
#lsb...is input stacked 16bit?
#hctr,vctr...centerpoints of the convolution string, by default in the middle...ignored if given hor and ver are kernels
#info...shows convolution strings on screen
y=default(y,3)
u=default(u,3)
v=default(v,3)
htext = IsString(hor) ? hor : "" 
vtext = IsString(ver) ? ver : "" 
hi = IsString(hor) ? 1 : int(hor) 
vi = IsString(ver) ? 1 : int(ver) 
lsb=default(lsb,false)
info=default(info,false)
horcenter=default(hctr,(hi+1)/2)
vercenter=default(vctr,(vi+1)/2)
sum=hi*vi
tot=default(tot,0.0)
tot   = (tot>0)      ? tot
    \ : (tot<0)      ? -sum*tot 
    \                : 0
hcoef = 1
vcoef = 1
uh = " "+ string(hcoef)
uv = " "+ string(vcoef)
uhl =strlen(uh)
uvl =strlen(uv)
flt=((int(tot)!=tot)&&(lsb==false)) ? ".0" : ""
shl=(hi-2*horcenter+1)*(lsb ? -1 : 1 )          #Dither applies convolution in reverse 
svl=(vi-2*vercenter+1)*(lsb ? -1 : 1 )
strh=uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh+uh
strv=uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv+uv
str0=" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
hh=leftstr(str0,max(2*shl,0))+leftstr(strh,uhl*hi)+flt+leftstr(str0,max(-2*shl,0))
vv=leftstr(str0,max(2*svl,0))+leftstr(strv,uvl*vi)+flt+leftstr(str0,max(-2*svl,0))
hh=(htext=="") ? hh : htext
vv=(vtext=="") ? vv : vtext
hvsame=(hh==vv)   # when hor and vertical is same, do 16bit in one pass
c
(!lsb && tot==0) ? mt_convolution(horizontal=hh,vertical=vv,y=y,u=u,v=v) : nop 
(!lsb && tot>0)  ? mt_convolution(horizontal=hh,vertical=vv,total=tot,y=y,u=u,v=v) : nop 
(lsb && hh!="1" &&  hvsame) ? Dither_resize16 (Width(), Height()/2, kernel="impulse "+hh, fh=-1, fv=-1, center=false) : nop
(lsb && hh!="1" && !hvsame) ? Dither_resize16 (Width(), Height()/2, kernel="impulse "+hh, fh=-1, center=false) : nop
(lsb && vv!="1" && !hvsame) ? Dither_resize16 (Width(), Height()/2, kernel="impulse "+vv, fv=-1, center=false) : nop
info ? Subtitle(" h=("+hh+") v=("+vv+")") : nop
info ? Subtitle(" 16bit="+string(lsb)+"    total=("+string(tot)+")  size=("+string(hor)+","+string(ver)+")  center=("+string(horcenter)+","+string(vercenter)+") ",y=24) : nop
return last
}
I hope it is understandable what it does, so won't comment more, if you wanna know just play with parameters with info=true, see what is the difference eg on the following
Code:
convolve(5, 4, info=true)
convolve(5, 4, tot=-2, lsb=false, hctr=-3, vctr=1, info=true)
convolve(5, 4, tot=0, lsb=true, hctr=-3, vctr=1, info=true)
convolve("1 0 -1 0 1", 4, tot=0, lsb=false, hctr=-3, vctr=1, info=true)
There are two issues introduced by dither, see them in the comments
@cretindesalpes: I wonder whether these are intents or bugs
Now I believe that it was main reason why I was confused with using Dither_resize16

Last edited by redfordxx; 6th November 2011 at 09:02. Reason: Bug
redfordxx is offline   Reply With Quote
Old 6th November 2011, 03:10   #342  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Quote:
dfttest keeps more detail than dctfilter
Ah, interesting. I am certainly not that well-versed in all the available denoisers for AviSynth. I will have to check it out. My comment was not really intended to suggest that FFT was the best way, but rather the concept of blending the denoised output with the original video in small degrees as a method of reducing visible banding.
vampiredom is offline   Reply With Quote
Old 6th November 2011, 10:54   #343  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Quote:
Originally Posted by redfordxx View Post
Dither_resize16 applies kernel in reverse
Dither_resize16 normalizes kernel, so tot parameter is ignored in 16bits
[...]
I wonder whether these are intents or bugs
Not really a bug nor an intent. I implemented the convolution in the simplest possible way, and didn't care about the kernel traversal sign, because resizing kernels are symmetric. I'll fix these issues in the next release.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 7th November 2011, 22:32   #344  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 769
Quote:
Avisynth open failure:
Evaluate: operands of '==' and '!=' must be comparable
(dither.avsi, line 850)
(dither.avsi, line 814)
I tried to set u=3,v=3 in dither_lut8.
In the function dither_lut8_lsb, line 850, it checks if u or v are defined, but if they are, it then tries to check what y is. But if y is not defined, it fails. You need to set y=default(y,3) somewhere.
Don't know if there are other places with this error.

Also, a feature request...
Would it be possible to convert into any colorspace by defining the matrix yourself?

Last edited by ajp_anton; 7th November 2011 at 22:35.
ajp_anton is offline   Reply With Quote
Old 9th November 2011, 23:23   #345  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Dither updated to v1.13.0:
  • Added kernelh, kernelv, totalh and totalv to Dither_resize16. Please note that the custom convolution coefficients are now read in the correct order.
  • Fixed an error with the plane selectors in the Dither_lut*8 functions.
  • Updated MVTools to v2.5.13.1:
    • MAnalyse, MRecalculate: added an SATD approximation for blksize > 16 and dct >= 5. Previously, the SATD calculation was silently bypassed and always returned a null SAD value. Actually this is more a mixed SAD-SATD calculation, because the SATD for large blocks is implemented as a sum of the SATD of smaller blocks, instead as a SAD of the Hadamard transform of the whole block. It was already the case for blksize=8 or above.
    • Functions now check that the pel setting is the same in the superclip and the motion vectors, instead of crashing if not.

Quote:
Originally Posted by ajp_anton View Post
Would it be possible to convert into any colorspace by defining the matrix yourself?
Do you have a specific use in mind? I could add other standard matrices, if required. Or give control over the kr, kg and kr parameters. But defining the 9 matrix coefficients + 3 constants would be a bit more complex.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 11th November 2011, 17:57   #346  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 769
Well I was thinking of YCgCo, but then thought there might be others so a more general solution might be possible.
ajp_anton is offline   Reply With Quote
Old 13th November 2011, 19:06   #347  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 949
I'd like to ask if currently the staticnoise option of ditherpost works like the wOxxOm workflow, or instead noise is spread evenly in the image. Ideally one would want noise only where ditherpost is dithering more aggresively.

I also noticed gradfun3 needs the staticnoise option. It could be a RAM problem but gradfun for smode=2 at least feels very unstable I usually have crashes, raising ampo over 1 also makes it unstable but I'm not sure which one is the trigger. My tests are in 16bit pipeline. I'm tackling fine banding here.
GradFun3(0.6,14,lsb_in=true,smode=2,lsb=true)
ditherpost(mode=0,ampn=0.5,staticnoise=true,ampo=1.2)

BTW I'd like to know if it's ok to use ampn with ampo at the same time when using ordered dither as in the example.

Another idea I had is to use floyd-steingberg on detailed areas to shoot for accuracy, but ordered dither on low gradients, if it leaves banding then use the staticnoise as mentioned. The drawback is having to use 2 ditherposts. I don't know if mixing 2 different algos harms too much.

At last to confirm something I didnt get clear:
Code:
(interlaced source)
separatefields
dfttest(lsb=true,tbsize=1)
ditherpost(mode=6,interlaced=true)
weave
Is this ok?

Last edited by Dogway; 19th November 2011 at 10:55.
Dogway is offline   Reply With Quote
Old 19th November 2011, 18:42   #348  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Quote:
Originally Posted by Dogway View Post
I'd like to ask if currently the staticnoise option of ditherpost works like the wOxxOm workflow, or instead noise is spread evenly in the image. Ideally one would want noise only where ditherpost is dithering more aggresively.
No, currently the noise (static or not) is global. If the mask is active, only the non-edge area will be debanded and dithered, whatever the noise settings. The function is very basic actually.

Quote:
I also noticed gradfun3 needs the staticnoise option. It could be a RAM problem but gradfun for smode=2 at least feels very unstable I usually have crashes, raising ampo over 1 also makes it unstable but I'm not sure which one is the trigger. My tests are in 16bit pipeline. I'm tackling fine banding here.
GradFun3(0.6,14,lsb_in=true,smode=2,lsb=true)
ditherpost(mode=0,ampn=0.5,staticnoise=true,ampo=1.2)
I couldn't reproduce any crash here. Could you post the full script? What is the size of your input clip? Which Avisynth version do you run?

Quote:
BTW I'd like to know if it's ok to use ampn with ampo at the same time when using ordered dither as in the example.
Yes, the noise will just add to the dither pattern before bit reduction.

Quote:
Another idea I had is to use floyd-steingberg on detailed areas to shoot for accuracy, but ordered dither on low gradients, if it leaves banding then use the staticnoise as mentioned. The drawback is having to use 2 ditherposts. I don't know if mixing 2 different algos harms too much.
There shouldn't any problem with this.

Quote:
At last to confirm something I didnt get clear:
Code:
(interlaced source)
separatefields
dfttest(lsb=true,tbsize=1)
ditherpost(mode=6,interlaced=true)
weave
Is this ok?
Noting that tbsize=1, yes it should work but Weave() before DitherPost(), that's how it is intended to work in interlaced mode.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 29th November 2011, 00:03   #349  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
The Dither package has been updated to v1.13.1:
  • Fixed height checks in DitherPost with interlaced content.
  • Updated dfttest to v1.9: added the quiet parameter to deactivate the filter spectrum output when sigma is specified with sstring/ssx/ssy/sst.
  • Updated MVTools to v2.5.14.0: Added MStoreVect, MRestoreVect and MScaleVect, from the Vit's MVExtras plugin. Function names have been changed to avoid collisions with MVExtras.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 29th November 2011, 00:39   #350  |  Link
Nevilne
Registered User
 
Join Date: Aug 2010
Posts: 134
This is very sweet!
Seeing as vector scaling is being developed again, can I ask if this is possible:

Manalyze on half size clip with pel=1
Mflow/blur/whatever on full clip with pel 2 or 4

I've tried tinkering with adjustSubPel and other settings but there seems to be no way,
and using pelsearch=0 + blank pel clip is not very clean.

Also, vector scaling doesn't work with divide>0.
I didn't want to bug Vit with this but since you've included vector scaling it would be great if you could look into it :o
Nevilne is offline   Reply With Quote
Old 30th November 2011, 17:24   #351  |  Link
-Vit-
Registered User
 
Join Date: Jul 2010
Posts: 448
Quote:
Originally Posted by Nevilne View Post
Manalyze on half size clip with pel=1
Mflow/blur/whatever on full clip with pel 2 or 4
That's the wrong way round. The idea behind adjustSubPel is that vectors measured in half-pixels (pel=2) on a half-size clip can be left unchanged and treated as measured in full pixels (pel=1) on a full size clip. Only the pel setting in the vectors changes. I was experimenting with this before I had to stop avisynth development for more important things. My initial observations were that it worked, but did not provide any advantage over scaling the vectors and leaving the pel alone.

Maybe you had a different idea...?

Quote:
Originally Posted by Nevilne View Post
Also, vector scaling doesn't work with divide>0.
Yes, this is true and should be added to the documentation. I'd had enough after deciphering the internal layout/format of standard multilevel blocks/padding. I guess I'll add that final (rarely used) layer at some stage.
-Vit- is offline   Reply With Quote
Old 4th December 2011, 18:35   #352  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 949
I had a look to your workaround to make yuy2 colorspace sources be processed by ditherpost, but I'm having a hard time to understand how it works.

Do you apply that code to an 8 bit interleaved yuy2 ?

I'm testing by comparing the next to its yv12 counterpart:

Code:
(interleaved 8 bit yuy2 source)

y = ConvertToYV12 ()
u = UToY ().ConvertToYV12 ()
v = VToY ().ConvertToYV12 ()
YToUV (u, v, StackVertical (y, y))

dfttest(lsb=true)
ditherpost(mode=0)

y = Crop (0, 0, 0, Height () / 2).ConvertToYUY2 ()
u = UToY ().ConvertToYUY2 ()
v = VToY ().ConvertToYUY2 ()
YToUV (u, v, y)
But there's something different in the chroma planes so I wouldn't call that lossless, maybe I'm doing something wrong?
Dogway is offline   Reply With Quote
Old 4th December 2011, 22:13   #353  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Yes this code applies to standard YUY2. It works by copying the chroma planes from the YUY2 clip to the YV12. Therefore the overall height must be doubled, so I have to stack two original luma planes. The filtering will work only if each plane is processed separately because chroma and luma are not synchronized. Fortunately, this is the case with dfttest and DitherPost.

If you compare the result with a YV12 source, it's normal you get something different on the chroma planes: regular YV12 to YUY2 conversions are not lossless because of the chroma placement and the interpolation method. If you bypass the dfttest/DitherPost lines in your code, you should obtain the exact source clip.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 12th December 2011, 16:20   #354  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 949
I almost finished implementing it to my script but there's something that doesn't work.
Code:
separatefields
interleaved2planar
super_search=MSuper(planar=true)
bv2=super_search.MAnalyse(isb = true, delta = 2)
fv2=super_search.MAnalyse(isb = false, delta = 2)
MDegrain1(super_search, bv2, fv2, thSAD=300,planar=true,lsb=true)
It only happens when I use separatefields with lsb=true. Even setting assumeframebased doesn't fix it and always throws an error. This is the base for interlaced YUY2 denoising but I don't know what else to try.
Dogway is offline   Reply With Quote
Old 13th December 2011, 15:22   #355  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Indeed, there was a bug with planar=true and lsb=true. Fixed in Dither 1.13.2.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 13th December 2011, 17:53   #356  |  Link
Stephen R. Savage
Registered User
 
Stephen R. Savage's Avatar
 
Join Date: Nov 2009
Posts: 337
cretindesalpes,

Where are these custom versions of dfttest and mvtools you use coming from? I can't find any information about a dfttest 1.9 or mvtools 2.5.14. Can you provide a link to the original versions of these filters or are they solely your creation?
Stephen R. Savage is offline   Reply With Quote
Old 13th December 2011, 19:32   #357  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 949
It works like charm now! I forgot to ask, do you think if by adding a blankclip to the below stacked luma can save processing for ditherpost?
YToUV (u, v, StackVertical (y, blank_clip))
Dogway is offline   Reply With Quote
Old 14th December 2011, 15:39   #358  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Quote:
Originally Posted by Stephen R. Savage View Post
Where are these custom versions of dfttest and mvtools you use coming from? I can't find any information about a dfttest 1.9 or mvtools 2.5.14. Can you provide a link to the original versions of these filters or are they solely your creation?
Yes, these are my own updated versions of these tools. It seems they are no longer updated by their authors (excepted occasional bugfixes for mvtools) so I took the liberty to continue their development. I hope it doesn't hurt anyone.

Quote:
Originally Posted by Dogway View Post
do you think if by adding a blankclip to the below stacked luma can save processing for ditherpost?
No, I don't think it will change anything.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 15th December 2011, 14:57   #359  |  Link
mastrboy
Registered User
 
Join Date: Sep 2008
Posts: 287
Do the modified MVtools in the dither package contain the threading fixes from the QTGMC modded plugins package by -Vit- ?

Little annoying that there are multiple forks of mvtools2 out there now, the official one, one from the dither package, one from QTGMC and one from www.svp-team.com
mastrboy is offline   Reply With Quote
Old 15th December 2011, 15:43   #360  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Yes, this version has the QTGMC threading fixes.
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Reply

Tags
color banding, deblocking, noise reduction

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 18:34.


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