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 2nd October 2008, 12:02   #21  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
@ CruNcher: We're talking about burning wood here. You are talking about vacuum energy. Yes, vacuum energy is much more fertile, no doubt. Problem is that it hasn't been implemented yet. Burning wood works right here, right now.


@ pitch.fr: I used bicubic for good resons. Look at this chart:



In brief: Using any other resizer in GrainFactory() ...

... offers no benefit at all

... is slower (though not much)

... breaks the "sharpness" settings (they're not functional anymore, then)


When will people finally learn that amongst Avisynth's resizers there are no "bad / good / better / best" ones. A 10mm spanner is neither better nor worse than a 16mm spanner. The trick is you have to use the one that fits to the screw.
__________________
- 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 2nd October 2008, 12:22   #22  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
are you sure we can draw so many conclusions from your test charts

you use "bicubicresize" in your original script, so is it -0.6/-0.75/-1 ?

is it also a bad idea to upgrade LSF with spline36 ?

anyway, I guess you agree that the same grainsize for bright and dark areas is a problem ? you don't wanna have huge grains in open skies for instance

and what is "grain_texture" supposed to do ?
pitch.fr is offline   Reply With Quote
Old 2nd October 2008, 13:25   #23  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
Quote:
are you sure we can draw so many conclusions from your test charts
The picture is only for visualation, and to proof the theory. Think about what is actually processed in the script: a greyscale map with per-pixel noise (zero mean gaussian noise). The point is that there is basically no correlation between any of the generated noise pixels. When there is no spatial correlation, then the "advantages" of the higher-order sampling algorithms don't bite anything. Bicubic deals kind of perfectly for the given purpose, AND it has the advantage that the "crispness" can be controlled via the bicubc b+c parameters. Ringing is no issue at all in this context - you can't see any ringing in the noise.
The chart should give the idea that whatever any of the other resizers do achieve, can be achieved by bicubic just as well - and even *more*, if you're after "sharp" grain.

Of course, if you feel better when filling your lawnmower with super-duper-$$$$-120octane gasoline, then by all means do so. My lawnmower gets only standard gasoline, and it runs very well.


Quote:
you use "bicubicresize" in your original script, so is it -0.6/-0.75/-1 ?
Code:
bicubic( 1.0,0.00) -> grainX_sharpness =   0
bicubic( 0.0,0.50) -> grainX_sharpness =  50
bicubic(-0.5,0.75) -> grainX_sharpness =  75
bicubic(-1.0,1.00) -> grainX_sharpness = 100

Quote:
is it also a bad idea to upgrade LSF with spline36 ?
For LSF it's another story. There, it's actual image content that gets resized, with lots of correlation between pixels. Therefore, for LSF the more specific sampling algorithms make a difference indeed. (unless you use ss_x = ss_y = 1.0, since then the internal resizer is not used at all.)


Quote:
and what is "grain_texture" supposed to do ?
It's meant to make realtime usage impossible, and to force global warming.
__________________
- 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!)

Last edited by Didée; 2nd October 2008 at 13:29.
Didée is offline   Reply With Quote
Old 2nd October 2008, 14:48   #24  |  Link
Soulhunter
Bored...
 
Soulhunter's Avatar
 
Join Date: Apr 2003
Location: Unknown
Posts: 2,812
Good to see this function alive again! Remembers me my Gain generation procedure in Photoshop... Gaussian Noise -> Gaussian Blur -> UnsharpMask (With higher blur radius for low luma parts, lower blur radius for high luma parts, more sharpening for high luma parts, less sharpening for teh low luma parts etc...). Hmm, how about a Grain3 param for this function? Having separate params for low, mid and high luma would be advantageous imo! :]


Bye
__________________

Visit my IRC channel
Soulhunter is offline   Reply With Quote
Old 2nd October 2008, 15:17   #25  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
Quote:
Originally Posted by Didée View Post
Code:
bicubic( 1.0,0.00) -> grainX_sharpness =   0
bicubic( 0.0,0.50) -> grainX_sharpness =  50
bicubic(-0.5,0.75) -> grainX_sharpness =  75
bicubic(-1.0,1.00) -> grainX_sharpness = 100
ok, thanks for the explanation

I didn't realize the sharpness setting was playing around with the bicubic coeff

Quote:
Originally Posted by Didée View Post
For LSF it's another story. There, it's actual image content that gets resized, with lots of correlation between pixels. Therefore, for LSF the more specific sampling algorithms make a difference indeed. (unless you use ss_x = ss_y = 1.0, since then the internal resizer is not used at all.)
right!! well I used to run ss1.1, but it was a tad too soft to my taste.....I like very sharp details, even if that means jaggies once in a while....and with ss1.1 there was indeed a CPU% difference, that doesn't exist anymore with ss1.0

Quote:
Originally Posted by Didée View Post
It's meant to make realtime usage impossible, and to force global warming.
geez, I'm gonna stay far away from it then

Quote:
Originally Posted by Soulhunter View Post
how about a Grain3 param for this function? Having separate params for low, mid and high luma would be advantageous imo!
agreed, that would be the icing on the cake

Last edited by pitch.fr; 2nd October 2008 at 15:22.
pitch.fr is offline   Reply With Quote
Old 3rd October 2008, 06:24   #26  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,413
Quote:
Originally Posted by CruNcher View Post
Hmm Didée wouldn't it possible to record the original Grain Layer using mvdegrain and adding it back @ playback (instead of creating a artificial one) ?
so degrain with mvdegrain use the difference between the degrained and grained and regrain the compressed one with it or add it back @ playback, this way also the temporal information of the grainlayer could be preserved i think. Of course the recording of the whole layer wouldn't be necessary but i guess this way it could be easier to analyze different film stocks visual results and trying to match them as close as possible randomly generated. The final dream would be a selection box in ffdshow where you select the GrainLayer you want out of a Film Stock like Database
It's actually pretty easy to keep track of grain removed. Just record the MSE of every denoised frame to the original with Compare, feed that with some arithmetic manipulation into AddGrain. Had it working, but it's terribly slow since it has to reinitialize addgrain for every frame. Never implemented it in Avisynth because I really wanted to get it into ffdshow, but I lost steam a long time ago. Eventually lost the script when a driver crash wiped out my avsp session. >( That's the breaks sometimes.

As for addgrainC, I don't see how it could be leaking memory unless using it with MT somehow causes its pointers to be overwritten. I'd expect it to crash a lot in that case.
__________________
There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order.
foxyshadis is offline   Reply With Quote
Old 3rd October 2008, 09:39   #27  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
Quote:
Originally Posted by foxyshadis View Post
As for addgrainC, I don't see how it could be leaking memory unless using it with MT somehow causes its pointers to be overwritten. I'd expect it to crash a lot in that case.
hi foxy,

here's AddGrainC 1.1 with 4 thread in ffdshow(1st value is RAM usage, second one is virtual memory usage) :



here's AddGrainC 1.4 with 4 thread in ffdshow on the same exact movie, with the same exact config :



if I use SetMemoryMax(256), 1.0/1.1 will obey but newer versions won't

with 8 threads, it crashes in VDUB for me(it's bypassed), uses +1.6Gb of RAM in ffdshow/MPC..then crashes MPC(also tried with other players)

tests were conducted on XP SP3, with MT 0.7 and the latest ffdshow/MPC on a Q6600

Last edited by pitch.fr; 3rd October 2008 at 13:20.
pitch.fr is offline   Reply With Quote
Old 3rd October 2008, 14:38   #28  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
@ foxyshadis: That's too simplistic for what CruNcher has in mind. That way you'll "only" get noise with varying sigma per frame, but still it'll be the "same kind" of noise all over the frame. The idea, however, was to have noise varying acc. to local brighness, and/or acc. to local amount of R/G/B component. That's a bit more complex.
__________________
- 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 3rd October 2008, 14:55   #29  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
any chance you could add a third layer please Didee ?

so we get real simulation of dark/mid/bright areas grain

I'm about to get myself a new DFI mobo to o/c my Q6600 even further, so bring it on
pitch.fr is offline   Reply With Quote
Old 3rd October 2008, 21:47   #30  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
Here you go. Look into the default() section to inform yourself about the parameters - I decided to shorten parameters' names for less typing effort when using named values in the function call. The zone transitions get specified by th1/th2 and th3/th4.

The structure of script & parameters should be kind of obvious ... in case you come to the idea of needing "dark dark" + "bright dark" and/or "dark/medium/bright medium" etc. zones, you can do it on your own.

Code:
function GrainFactory3(clip clp,int "g1str",int "g2str",int "g3str",int "g1shrp",int "g2shrp",int "g3shrp",
 \                        float "g1size", float "g2size", float "g3size",
 \                        int "g1tex", int "g2tex", int "g3tex", int "temp_avg", int "ontop_grain",
 \                        int "th1", int "th2", int "th3", int "th4")
{

g1str       = default( g1str,        13 )  # [ 0 - ???] strength of grain / for dark areas
g2str       = default( g2str,        15 )  # [ 0 - ???] strength of grain / for midtone areas
g3str       = default( g3str,        25 )  # [ 0 - ???] strength of grain / for bright areas
g1shrp      = default( g1shrp,       60 )  # [ 0 - 100] sharpness of grain / for dark areas (NO EFFECT when g1size=1.0 !!)
g2shrp      = default( g2shrp,       66 )  # [ 0 - 100] sharpness of grain / for midtone areas (NO EFFECT when g2size=1.0 !!)
g3shrp      = default( g3shrp,       80 )  # [ 0 - 100] sharpness of grain / for bright areas (NO EFFECT when g3size=1.0 !!)
g1size      = default( g1size,     1.50 )  # [0.5 - 4.0] size of grain / for dark areas
g2size      = default( g2size,     1.20 )  # [0.5 - 4.0] size of grain / for mid-tone areas
g3size      = default( g3size,     0.90 )  # [0.5 - 4.0] size of grain / for bright areas
g1tex       = default( g1tex,         0 )  # [ 0 - 100] strength of "material texture" appearance
g2tex       = default( g2tex,         0 )  # [ 0 - 100] (in fact: 'bump' effect)
g3tex       = default( g3tex,         0 )  # [ 0 - 100] for dark / midtone / bright grain
temp_avg    = default( temp_avg,      0 )  # [ 0 - 100] percentage of noise's temporal averaging
th1         = default( th1,          24 )  # start of dark->midtone  mixing zone
th2         = default( th2,          56 )  # end  of  dark->midtone  mixing zone
th3         = default( th3,         128 )  # start of midtone->bright  mixing zone
th4         = default( th4,         160 )  # end  of  midtone->bright  mixing zone
ontop_grain = default( ontop_grain,   0 )  # [ 0 - ???] additional grain to put on top of prev. generated grain


#-----------------------------------------------------------------------------------

o    = clp
ox   = o.width
oy   = o.height
sx1  = m4(ox/float(g1size))
sy1  = m4(oy/float(g1size))
sx1a = m4((ox+sx1)/2.0)
sy1a = m4((oy+sy1)/2.0)
sx2  = m4(ox/float(g2size))
sy2  = m4(oy/float(g2size))
sx2a = m4((ox+sx2)/2.0)
sy2a = m4((oy+sy2)/2.0)
sx3  = m4(ox/float(g3size))
sy3  = m4(oy/float(g3size))
sx3a = m4((ox+sx3)/2.0)
sy3a = m4((oy+sy3)/2.0)

b1   = g1shrp/(-50.0) + 1.0
b2   = g2shrp/(-50.0) + 1.0
b3   = g3shrp/(-50.0) + 1.0
b1a  = b1/2.0
b2a  = b2/2.0
b3a  = b3/2.0
c1   = (1.0-b1)/2.0
c2   = (1.0-b2)/2.0
c3   = (1.0-b3)/2.0
c1a  = (1.0-b1a)/2.0
c2a  = (1.0-b2a)/2.0
c3a  = (1.0-b3a)/2.0
T1a  = string(int(g1tex*1.28))
T1b  = string(128-int(g1tex*1.28))
T2a  = string(int(g2tex*1.28))
T2b  = string(128-int(g2tex*1.28))
T3a  = string(int(g3tex*1.28))
T3b  = string(128-int(g3tex*1.28))
th1str = string(th1)
th2str = string(th2)
th3str = string(th3)
th4str = string(th4)
tmpavg = temp_avg/100.0

#-----------------------------------------------------------------------------------

BUMPKERNEL1 = T1a + " 0 0 0 " + T1b + " 0 0 0 0 128"
BUMPKERNEL2 = T2a + " 0 0 0 " + T2b + " 0 0 0 0 128"
BUMPKERNEL3 = T3a + " 0 0 0 " + T3b + " 0 0 0 0 128"

#-----------------------------------------------------------------------------------

grainlayer1 = blankclip(o, width=sx1, height=sy1, color_yuv=$808080) .AddGrainC(g1str, 0,0,0)

grainlayer1 = (g1tex==0)
\           ? grainlayer1
\           : mt_makediff(grainlayer1,grainlayer1.mt_edge(BUMPKERNEL1, 0,255,0,0, U=1,V=1 ), U=1,V=1)

grainlayer1 = (g1size == 1.0 || sx1==ox && sy1==oy) ? grainlayer1
\           : (g1size > 1.5) ? grainlayer1.bicubicresize(sx1a,sy1a, b1a,c1a).bicubicresize(ox,oy, b1a,c1a)
\                            : grainlayer1.bicubicresize(ox,oy, b1,c1)

#-----------------------------------------------------------------------------------

grainlayer2 = blankclip(o, width=sx2, height=sy2, color_yuv=$808080) .AddGrainC(g2str, 0,0,0)

grainlayer2 = (g2tex==0)
\           ? grainlayer2
\           : mt_makediff(grainlayer2,grainlayer2.mt_edge(BUMPKERNEL2, 0,255,0,0, U=1,V=1 ), U=1,V=1)

grainlayer2 = (g2size==1.0 || sx2==ox && sy2==oy) ? grainlayer2
\           : (g2size > 1.5) ? grainlayer2.bicubicresize(sx2a,sy2a, b2a,c2a).bicubicresize(ox,oy, b2a,c2a)
\                            : grainlayer2.bicubicresize(ox,oy, b2,c2)

#-----------------------------------------------------------------------------------

grainlayer3 = blankclip(o, width=sx3, height=sy3, color_yuv=$808080) .AddGrainC(g3str, 0,0,0)

grainlayer3 = (g3tex==0)
\           ? grainlayer3
\           : mt_makediff(grainlayer3,grainlayer3.mt_edge(BUMPKERNEL2, 0,255,0,0, U=1,V=1 ), U=1,V=1)

grainlayer3 = (g3size==1.0 || sx3==ox && sy3==oy) ? grainlayer3
\           : (g3size > 1.5) ? grainlayer3.bicubicresize(sx3a,sy3a, b3a,c3a).bicubicresize(ox,oy, b3a,c3a)
\                            : grainlayer3.bicubicresize(ox,oy, b3,c3)

#-----------------------------------------------------------------------------------

grainlayer = grainlayer1.mt_merge(grainlayer2, o.mt_lut("x "+th1str+" < 0 x "+th2str+" > 255 255 "+th2str+" "+th1str+" - / x "+th1str+" - * ? ?"), U=1,V=1)
 \                      .mt_merge(grainlayer3, o.mt_lut("x "+th3str+" < 0 x "+th4str+" > 255 255 "+th4str+" "+th3str+" - / x "+th3str+" - * ? ?"), U=1,V=1)

grainlayer = (temp_avg==0) ? grainlayer
\                          : grainlayer.mergeluma(grainlayer.temporalsoften(1,255,0,255,2), tmpavg)
grainlayer = (ontop_grain==0) ? grainlayer
\                             : grainlayer.AddGrainC(ontop_grain,0,0,0)

#-----------------------------------------------------------------------------------

result = o.mt_makediff(grainlayer, U=2,V=2) 

return( result ) 

#-----------------------------------------------------------------------------------
function m4(float x) {return( x<16?16:int(round(x/4.0)*4)) }
#===================================================================================}
__________________
- 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!)

Last edited by Didée; 3rd October 2008 at 22:29.
Didée is offline   Reply With Quote
Old 3rd October 2008, 21:50   #31  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
awesome Didee, you're the man

gonna try it right now with :

Code:
GrainFactory3(6,5,3,100,100,100,1.50,1,0.70,0,0,0,0,0,24,56,128,160)
EDIT : it looks damn good, thank you so much

it brings back the grain h264 stole from us

Code:
MT("GrainFactory_MT2(3,5,100,100,1.0,0.7,0,0,0,96,0)",4)
=152fps

Code:
MT("GrainFactory3(7,5,3,100,100,100,1.30,1,0.70,0,0,0,0,0,24,56,128,160)",4)
=112

Code:
MT("GrainFactory(3,5,100,100)",4) (1.15/0.8 default sizes and no temporal thingie)
=119

Last edited by pitch.fr; 3rd October 2008 at 23:17.
pitch.fr is offline   Reply With Quote
Old 3rd October 2008, 22:20   #32  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
apparently you need to add these lines at the end of the GrainF3 script to be standalone from the MT1/MT2 :

Code:
#-----------------------------------------------------------------------------------
function m4(float x) {return( x<16?16:int(round(x/4.0)*4)) }
#===================================================================================
pitch.fr is offline   Reply With Quote
Old 3rd October 2008, 22:27   #33  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
Ah yes, the modulo function accidentially was left out during copy/paste. Thanks for noting. It's now included in the script above.
__________________
- 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 3rd October 2008, 22:35   #34  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
I think I've edited after you read it, so here it is again :

GrainF3 gives less FPS than the original GrainF script, yet it's fully usable in realtime on my 3.4Ghz Q6600

apparently there's 2 different problems with using an AVS script in ffdshow :
1-fps, of course
2-but more importantly latency.....and the latency seems far better with MT2 than MT1

my CPU load is 55% with a 1.78 20mbit 720p h264 movie, and LSF/Ulevels/GrainF + gamut conversion through AVIshader + ConvertToRGB32
pitch.fr is offline   Reply With Quote
Old 4th October 2008, 01:23   #35  |  Link
mikeytown2
Resize Abuser
 
mikeytown2's Avatar
 
Join Date: Apr 2005
Location: Seattle, WA
Posts: 623
I added GrainFactory to the wiki http://avisynth.org/mediawiki/External_filters#Effects
Should I change the link to point to GrainFactory3? Does it need a new entry in the wiki? Some guidance would be nice.


GrainFactory3 got it's closing "}" commented out
mikeytown2 is offline   Reply With Quote
Old 4th October 2008, 10:15   #36  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
I think I like the same grain size for dark and mid areas(1), and then finer grain for bright ones(0.7)

big grain sizes for dark ones look rather distracting

at least it's good that we can set different strengths

Last edited by pitch.fr; 4th October 2008 at 10:25.
pitch.fr is offline   Reply With Quote
Old 4th October 2008, 11:15   #37  |  Link
Soulhunter
Bored...
 
Soulhunter's Avatar
 
Join Date: Apr 2003
Location: Unknown
Posts: 2,812
@pitch.fr

How about larger diameter but less sharpness, maybe also lower strength? To my experience grain often looks a bit blurry in dark areas... :]
__________________

Visit my IRC channel
Soulhunter is offline   Reply With Quote
Old 4th October 2008, 14:23   #38  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
good point, but then it makes the picture a bit blurry, doesn't it ?

I think I might settle down to

Code:
GrainFactory3(6,5,3,100,100,100,1,1,0.70,0,0,0,0,0,24,56,128,160)
I wonder if that'd be easily doable to have GrainF_MT2 using the same settings for dark/mid, and separate ones for bright ?
pitch.fr is offline   Reply With Quote
Old 4th October 2008, 15:32   #39  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
More and more it deteriorates to a foolish act ... you realize that with grainsizeX=1.0 you get exactly the output of AddGrain()? A few more such requests, and it'll be a huge placebo function that does the same as a simple AddGrain() would do ...

With th1=0 and th2=0, this mod uses layer2 for both dark & midtones.

Know why usually I don't react to any such "realtime function" requests? Most of the time it creates "more simplification" and "even more simplification", up to the point where the sophisticated idea you once had started with has turned into a thing so primitive and ugly that one should be ashamed about. And truly, we're on that way here.
__________________
- 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 4th October 2008, 16:41   #40  |  Link
pitch.fr
Didée 4 President
 
Join Date: Jun 2008
Posts: 239
cool, thanks again Didee!

well the whole idea is to have big grain in dark stuff, and very fine in bright ones.

maybe a 50/50 would be fine after all ? or at least better than having the same size in dark/bright, and different in mid.

but I've done my tests on a 19" CRT mainly, I'll look more into it this evening on the pj.

I'm not asking for 50/50 stuff because it sucks too much ressources, but simply coz huge grain in dark areas looks a bit distracting and very small one a bit weak.

I'll try to play around w/ the sharpness as SoulHunter said.

and this script is great, even for non realtime use I think

Last edited by pitch.fr; 4th October 2008 at 16:56.
pitch.fr is offline   Reply With Quote
Reply

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 08:37.


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