Log in

View Full Version : 'Luma Peak' Hold, Store, and Aggregate? Help needed...


Karyudo
22nd June 2005, 05:49
As usual, I've got a filter concept that I don't even know how to search for, or even encapsulate into a tidy, one-line description. Here's what I'm after; maybe you have some hints??

I'm working with starfields in NTSC, and I'm finding that because some stars sort of fall between scanlines, there's a bunch of twinkle that goes on, and some stars pretty much permanently disappear. Not cool.

I'm hoping someone has come up with a routine that does something like the following:

- Looks at any pixels above a certain luminance value on a frame , and, if they are above the value, stores them.

- Looks at the next frame and does the same over a specified range of frames.

- Finally, overlays all the over-the-threshold pixels onto a single new frame.

This would captures all of the stars that twinkle in and out of existence because of movement/scanlines and whatever other problems. Of course it might make anything else in the shot go crazy, but that's what rotoscoping is for.

With a good, tunable, tool, you could then do a multiple luma pass to pick up bright stars, faint stars and so on until you got down to the noise floor.

To avoid really odd results or lots of roto work, I guess you could restrict a chroma range or ignore a pixel if there were a high percentage of pixels in an X by X radius that also had a high luma (i.e. it is not a star in a sea of blackness but probably a pixel in the middle of a planet or something else in frame). Could MaskTools() do something like this? In any case, I'd be happy enough with some baby steps in the right direction.

I've been told by a friend who uses Shake that this isn't that big a trick using that app. Well, I don't have Shake -- I have AviSynth! Considering the amazing filters I've seen around here, I'm hoping at least somebody has some ideas...?

E-Male
22nd June 2005, 08:59
what about overlaying all frames using "lighter"?

Karyudo
23rd June 2005, 06:18
Thanks, E-Male. Even that little hint helps. I'm not good at writing elegant AviSynth scripts, but I'll post my lame attempt here anyway, in the hopes that somebody will be so offended with its crapulence that he will be all but forced to post a highly-improved version...

clip=BlankClip(length=1, width=720, height=352, fps=24, color=$000000)

o1=avisource("Ep 4 - F1A.avi").trim(1377,1378)
o2=avisource("Ep 4 - F1A.avi").trim(1378,1379)
o3=avisource("Ep 4 - F1A.avi").trim(1379,1380)
o4=avisource("Ep 4 - F1A.avi").trim(1380,1381)
o5=avisource("Ep 4 - F1A.avi").trim(1381,1382)
o6=avisource("Ep 4 - F1A.avi").trim(1382,1383)
o7=avisource("Ep 4 - F1A.avi").trim(1383,1384)
o8=avisource("Ep 4 - F1A.avi").trim(1384,1385)

output_1=overlay(clip,o1,mode="lighten")
output=output_1.overlay(o2,mode="lighten")
output=output.overlay(o3,mode="lighten")
output=output.overlay(o4,mode="lighten")
output=output.overlay(o5,mode="lighten")
output=output.overlay(o6,mode="lighten")
output=output.overlay(o7,mode="lighten")
output=output.overlay(o8,mode="lighten")

stack=stackvertical(output_1,output)
return stack

That horrific piece of code gets me in the ballpark. A faster way to do more frames, and some sort of thresholding (in order to keep the noise in the black parts to a minimum) would be my next wish/target.

E-Male
23rd June 2005, 18:12
i think in avisynth script there is no easier way than yours

except you don't need the blankclip
and can just do it like this:
clip=avisource("Ep 4 - F1A.avi").

o1=clip.trim(1377,1378)
o2=cliptrim(1378,1379)
o3=clip.trim(1379,1380)
o4=clip.trim(1380,1381)
o5=clip.trim(1381,1382)
o6=clip.trim(1382,1383)
o7=clip.trim(1383,1384)
o8=clip.trim(1384,1385)

output_1=o1
output=output_1.overlay(o2,mode="lighten")
output=output.overlay(o3,mode="lighten")
output=output.overlay(o4,mode="lighten")
output=output.overlay(o5,mode="lighten")
output=output.overlay(o6,mode="lighten")
output=output.overlay(o7,mode="lighten")
output=output.overlay(o8,mode="lighten")

stack=stackvertical(output_1,output)
return stack

now for the noise in the black parts:
is it luma ort chroma noise, or both (or is your material rgb)?


what you also could try is something like this:
avisource("Ep 4 - F1A.avi")
#trim if the avi contains more then just the star-field
loop(10)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255)
TemporalSoften(1,255,255) (just from memory, might have errors)


good luck

Karyudo
24th June 2005, 03:49
OK, I've taken the ideas I've been given (thanks, E-Male!) and tried to make things a little cleaner and more elegant. Now there's only one place I need to change "lighten" to "luma" or "darken," if that's what I want to do. I've also made the overlay frames more generic, by doing the trim to the input clip, and then referencing that.

How am I doing?

function ol(clip base, clip overlay_frame)
{
aggregate=base.overlay(overlay_frame,mode="lighten")

return aggregate
}

clip=avisource("Ep 4 - F1A.avi").trim(1377,1424)

o1=clip.trim(0,1)
o2=clip.trim(1,2)
o3=clip.trim(2,3)
o4=clip.trim(3,4)
o5=clip.trim(4,5)
o6=clip.trim(5,6)
o7=clip.trim(6,7)
o8=clip.trim(7,8)
o9=clip.trim(8,9)
o10=clip.trim(9,10)
o11=clip.trim(10,11)
o12=clip.trim(11,12)
o13=clip.trim(12,13)

out=o1
out=ol(out,o2)
out=ol(out,o3)
out=ol(out,o4)
out=ol(out,o5)
out=ol(out,o6)
out=ol(out,o7)
out=ol(out,o8)
out=ol(out,o9)
out=ol(out,o10)
out=ol(out,o11)
out=ol(out,o12)
out=ol(out,o13)

b=out
b=b.loop(10)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)
b=b.TemporalSoften(1,255,255)

stack=stackvertical(o1,out)
return stack

E-Male
29th June 2005, 14:49
i meant using either overlay or temporalsoften

in your script (if i'm right, just read quickly through it) the temporalsoften will do nothing
because all frames in the clip you feed it are the same
so temporal smoothing won't change anything

also in the end b is never output

but all-in-all your doing good, your progress on scripting just fine

one thing to add, before i confuse beginners:
such iterations, like 20x overlay or temporalsoften are normaly a very bad idea, this is a rare special case

Karyudo
1st July 2005, 03:16
Yeah, I guess I never looked too carefully at those TemporalSoftens! I also realized after I posted that I'd put up a copy of the script where I wasn't looking at 'b', but whatever. I was more interested in cleaning up some of the other code, so the fact 'b' actually ended up being useless was sort of a mistake...

As it turns out, the result without TemporalSoften looks pretty nice, anyway! Thanks for your help (once again)!