Log in

View Full Version : New "producing" filters: noise generators


SansGrip
31st October 2002, 00:42
Here is a package containing two new "producing" filters, UniformNoise and GaussianNoise. As you can probably guess, these respectively generate uniformly distributed noise and normally distributed (aka Gaussian) noise.

Their usage is vaguely similar to the built-in BlankClip filter. Please check out the included readme for more information.

(See this thread (http://forum.doom9.org/showthread.php?s=&threadid=31301) for the reason I wrote them, and this one (http://arstechnica.infopop.net/OpenTopic/page?a=tpc&s=50009562&f=67909965&m=3890938134&r=5470927074) for some discussion of the benefits of adding noise to a clip.)

This is first-release alpha code, and the usual disclaimers apply. Feedback of any nature would be very much appreciated.

Edit: Removed link to old version.

SansGrip
31st October 2002, 22:06
Here's version 0.2 (http://www.jungleweb.net/~sansgrip/avisynth/Noise_Generators-0.2.zip) (and source code (http://www.jungleweb.net/~sansgrip/avisynth/Noise_Generators-0.2_src.zip)), which fixes a pure virtual call runtime error when temporal=false.

I also put up a web page (http://www.jungleweb.net/~sansgrip/avisynth/) with the filters I've written to date. It's quick and nasty but it works ;).

SansGrip
1st November 2002, 02:53
Hey, is that a tumbleweed? *grin*

Incidentally, I just finished a test encode of American Pie with this script:


AudioDub(Mpeg2Source("ap.d2v"), WavSource("ap.wav"))
Crop(11, 8, 700, 462)
LanczosResize(352, 174)

opening = Trim(0, 533)
opening = opening.TemporalSoften(3, 8, 30)

movie = Trim(534, 131644)
movie = movie.Layer(GaussianNoise(movie, fast=true), "add", 12, use_chroma=false)

credits = Trim(131645, 0)
credits = credits.Greyscale().TemporalSoften(3, 8, 30)

last = opening + movie + credits

AddBorders(0, 33, 0, 33)

LegalClip()
ConvertToRGB()
Levels(0, 1, 255, 16, 235)


Settings:

TMPGEnc MPEG-1 352x240 23.976fps CQ-100 (min 500 + padding, max 2564)

File sizes:

Without noise 1,199,309,496 bytes
With noise 1,259,192,004 bytes

It looks fantastic. Not a DCT block to be found -- anywhere :) :) :). If you look real close at static areas you can see very slight temporal noise, but I think dropping the Layer level down to 11 would get rid of this (but might reintroduce those DCT blocks).

All in all I think this is the best-looking encode I've ever done. I'll keep testing it on different material and see what happens (I'm especially interested to find out how it handles action movies).

Summary:

Try it!! ;)

Xenoproctologist
1st November 2002, 06:01
GaussianNoise is sloooow. Painfully slow. 32 bit precision is ludicrously overkill when you're just outputting 8 bit noise. Back away from the floating point ops.

MINMAX(n,16,235) == bad juju. Don't assume people are using the CCIR601 color scale.

Kb_cruncher
1st November 2002, 13:27
Your filters look to give many benefits,especially for those outputting to TV.
I use cce to encode svcd for tvout and never knew what the 16-235 setting did until reading your LegalClip readme..thankyou.I will use it for my divx rips that i output to TV from know on,looks much nicer.

SansGrip
1st November 2002, 16:04
GaussianNoise is sloooow. Painfully slow.

Of course -- it's unoptimized alpha code ;). Apart from that, transforming uniform noise to Gaussian noise is never going to be particularly fast by it's nature. I use about the fastest algorithm out there, but as you observe it's not speedy.

That said version 0.3 has a new parameter, loop. This specifies the number of frames to generate which the filter will cache and loop over. For example, if you say loop=6 it'll generated and cache six frames of noise the first time it's called, and will simply loop over those for the remainder of the clip with no more noise generation to be done.

In certain applications (e.g. adding noise to a clip) this seems to work just as well as "proper" noise but has the advantage of running at real time.

Back away from the floating point ops.

Unfortunately I'm not sufficiently mathematically inclined to convert those floating point ops into integer-only versions. If anyone can point me to a good resource to read, I'd be grateful.

In fact I made the decision to use floats instead of doubles for performance reasons, but I'm now considering switching back to double precision. It's amazing what damage an "innocuous" change can do to a PRNG, and I'm nowhere near close to understanding the ramifications of switching from double->float. Now, with the loop parameter, speed is much less of an issue for what I perceive as the most common application for this filter.

MINMAX(n,16,235) == bad juju. Don't assume people are using the CCIR601 color scale.

I actually started a new thread (http://forum.doom9.org/showthread.php?s=&threadid=37082) trying to address just this question. At the moment there seems to be a great deal of confusion (at least in my head ;)) over whether or not, as far as Avisynth is concerned, YUY2 should always be within CCIR-601 bounds. Most existing filters do clamp.

SansGrip
1st November 2002, 16:10
Your filters look to give many benefits,especially for those outputting to TV.

I have to say the resulting encode of American Pie far exceeded my expectations in terms of quality, especially since the avs looked so noisy in Media Player. But it seems that MPEG-1 takes that noise and smooths it significantly, and in this instance it was nearly invisible in the final encode.

So I'd recommend encoding a short clip with various "strengths" of noise and see what the encoder produces from it, rather than simply trying to get the "right" amount of noise by looking at the avs in Media Player or whatever.

I use cce to encode svcd for tvout and never knew what the 16-235 setting did until reading your LegalClip readme..thankyou.I will use it for my divx rips that i output to TV from know on,looks much nicer.

Yep, it can make a big difference, since by scaling to 16-235 you're preserving all that detail that is otherwise clipped by your DVD player or TV out card...

LigH
5th November 2002, 14:10
Thank you so much - I've been waiting so long to get one from Donald Graft; I'm sure he had much more interesting things to do, though...

SansGrip
5th November 2002, 14:47
Thank you so much - I've been waiting so long to get one from Donald Graft

Wow, someone else who finds it useful! :D

Out of interest, what did you need a noise generator for?

LigH
5th November 2002, 23:03
What I would need a noise generator for? Well, for testing purposes, of course (codec quality, for example); for special effects, maybe; and even for enhancing the quality (you know, forcing a few high frequencies may reduce blocking artifacts).

SansGrip
5th November 2002, 23:12
What I would need a noise generator for? Well, for testing purposes, of course (codec quality, for example); for special effects, maybe

That's pretty much what I was thinking when I wrote it.

and even for enhancing the quality (you know, forcing a few high frequencies may reduce blocking artifacts).

In that case I hope you're following this thread (http://forum.doom9.org/showthread.php?s=&threadid=37135) :D.

LigH
5th November 2002, 23:35
Yeah, I saw that one. Well, I won't force it too much until I checked it well. More than 3..5% will definitely not be necessary, I'd guess from my experience of still pictures.