PDA

View Full Version : Colour noise applied in bright areas only


anton_foy
5th December 2007, 13:02
Hi again!
I am here with a new odd question as usual :p
As the title is already mentioning I like to apply colour(only) noise in the brighter areas of the image and also antialias/blur the noise just a bit. Haven't got the hang of masktools very well but I guess it would be the way to go?

AddgrainC using only the chroma gets big blobs and not small noise particles, any suggestion which other filter I should use?
I have tried Colour noise for vdub and it looks quite good but i think it mixes some luma noise into the colour aswell.

The footage is in 1920x1080 res, if this matters I don't know.


Thank you, any suggestions are helpful!

Spuds
5th December 2007, 18:40
I'm sure I'll get this wrong but what the heck :D

The quick way is to just make a hard mask like this, change the threshold to suit your needs

original = last
processed = original.AddgrainC
lightmask = mt_Binarize(last, threshold = 180, upper = false)
mt_merge(original ,processed ,lightmask)

Instead of the hard mask above you could try to do a transition between thresholds, so above its in, below its out and between its a mix. Note I have not tested this and my RPN is not so good!


original = last
processed = original.AddgrainC
th_hi = string(235)
th_lo = string(180)
lightmask = original.mt_lut("x " + th_hi + " > 255 x " + th_lo + " < 0 255 x " + th_lo + " - 255 " + th_hi + " " + th_lo + " - / * - ? ? ")
mt_merge(original ,processed ,lightmask)

anton_foy
6th December 2007, 08:36
Thank you very much Spuds, it leaves the grain in the lighter parts only yes but no chroma grain im afraid.

I tried this I just copied some lines and adjusted:

QTInput("C:\Jonas\ae.mov").Converttoyv12()
clip2 = QTInput("C:\Jonas\ae.mov").Converttoyv12()

clip2=ConvertToRGB32().NoiseC(10,2,3).blur(.5).converttoyv12()
Mas =Overlay(clip2, last, mode="Multiply", opacity=0.5).TweakColor(bright=5, cont=1)
LO = string( 15 )
HI = string( 100 )
darkmask = mas.yv12lut("x "+LO+" < 255 x "+HI+" > 0 255 x "+LO+" - 255 "+HI+" "+LO+" - / * - ? ?" )
darkmask = darkmask.FitY2UV()
dark_filter = mas
MaskedMerge(mas, dark_filter, darkmask, U=3,V=3)


It Kinda works but the thresholding I can't figure out, it won't mask out the dark parts enough.

Didée
6th December 2007, 09:03
It's needed to use the luma mask for the chroma planes. For that you have to use MaskTools v2, as MaskTools v1.5 won't do that. Spuds' script is almost correct, just change the last line to

mt_merge(original ,processed ,lightmask, luma=true, Y=2,U=3,V=3)

Also, pure chroma grain is a tricky thing in yv12, since all chroma samples are 2x2 pixels. That's why it will appear coarse no matter what, and applying blurring to the chroma noise won't make it better, only more blotchy.


edit: oops, there's a bug somewhere in the mt_lut line of Spuds' script. Can't track it right now, I'm leaving. Replace the mt_lut with levels(th_lo,1,th_hi,255,0,false). That's a tiny bit slower, but it's definetly correct.

MOmonster
6th December 2007, 10:30
original = last
processed = original.addgrainc()
th_hi = string(235)
th_lo = string(180)
lightmask = original.mt_lut("x "+th_lo+" - "+th_hi+" "+th_lo+" - / 255 *")
mt_merge(original ,processed ,lightmask, luma=true, Y=2,U=3,V=3)

This should work.

anton_foy
6th December 2007, 10:30
Thank you both!

When I added:
mt_merge(original ,processed ,lightmask, luma=true, Y=2,U=3,V=3)
it works but as you said Didée its blotchy as hell even without the blur (the grain looks combed also).

If I replace the mt_lut -line with levels(th_lo,1,th_hi,255,0, false) I get an error: Invalid arguments to the function "levels"

Any thoughts?

MOmonster thank you I tried it but there is no colour noise. I use Vdubs Noise (color).vdf instead of AddgrainC because its has the structure I want. Does the converttorgb32() screw it up?

original = last
processed = original.ConvertToRGB32().VdubNoiseC(10,2,3).converttoyv12()
th_hi = string(235)
th_lo = string(180)
lightmask = original.mt_lut("x "+th_hi+" > 255 x "+th_lo+" < 0 x "+th_lo+" - "+th_hi+" "+th_lo+" - / 255 * ? ? ")
mt_merge(original ,processed ,lightmask, luma=true, Y=2,U=3,V=3)

MOmonster
6th December 2007, 10:49
If you use levels, don´t convert the values to strings:
instead
th_hi = string(235)
th_lo = string(180)
just this:
th_hi = 235
th_lo = 180


Is there a bug in mt_merge? This use:
mt_merge(original ,processed ,lightmask, luma=true, Y=2,U=3,V=3) doesn´t process chroma at least on my pc. I use mt_masktools v2.0a32.

anton_foy
6th December 2007, 11:08
Now I am satisfied!

Thank you all so much you are heroes!


this work great

original = last
processed = original.ConvertToRGB32().VdubNoiseC(10,2,3).blur(.5).converttoyv12()
th_hi = string(235)
th_lo = string(180)
lightmask = original.mt_lut("x "+th_lo+" - "+th_hi+" "+th_lo+" - / 255 *")
mt_merge(original ,processed ,lightmask, luma=true,U=3,V=3)

Spuds
6th December 2007, 16:25
oops, there's a bug somewhere in the mt_lut line of Spuds' script

I just can't wrap my head around the syntax of RPN especially with the if/then /else :( So using MOmonster and Didees fixes it should be:

original = last
processed = original.AddgrainC (or whatever you want here)
th_hi = string(235)
th_lo = string(180)
lightmask = original.mt_lut("x " + th_hi + " > 255 x " + th_lo + " < 0 x " + th_lo + " - " + th_hi + " " + th_lo + " - / 255 * ? ? ")
mt_merge(original ,processed ,lightmask, luma=true, Y=2,U=3,V=3)

This should take all values below th_lo and make them zero, all above th_hi and make them 255 and have a linear transition between the two from 0 to 255.

In one of the posts there is a FitY2UV() function. Is this part of masktools v1? If so what is there a counterpart for v2 or do you need to do something like:

b=YtoUV(last,last)
mergeluma(b.bicubicresize(b.width/2,b.height/2),last)

Thanks!

anton_foy
7th December 2007, 14:54
Thats great Spuds! Thanks for your help. I have already used the script i posted above for the clip but I bet this will come in handy soon too.

Thank you all

sarmano
27th June 2008, 08:23
What about red colour areas only?

Gavino
27th June 2008, 11:01
What about red colour areas only?
One way to do it would be to use ShowRed (http://avisynth.org/mediawiki/ShowRed) to extract the red component, apply the filtering described earlier, then use MergeRGB (http://avisynth.org/mediawiki/MergeRGB) to put it back together again.

Manao
27th June 2008, 15:02
In one of the posts there is a FitY2UV() function. Is this part of masktools v1?Yes
If so what is there a counterpart for v2No

sarmano
27th June 2008, 18:06
Gavino
Thanks for answer!

http://img225.imageshack.us/img225/4052/02xc3.jpg
Any script example would be helping, if it possible.
Again thanks.

Gavino
27th June 2008, 19:05
Any script example would be helping, if it possible.
What I had in mind was something like:

source = ... # your source
source = source.ConvertToRGB32() # if necessary
source.ShowRed("YV12")

# <- ... apply original filtering here ...

MergeRGB(last, source.ShowGreen("YV12"), source.ShowBlue("YV12"))

but it's possible there are better ways to achieve what you want more directly.

sarmano
29th June 2008, 23:00
Gavino
Many many thanks!