Log in

View Full Version : Restricted luminance range smoothing?


FredThompson
28th June 2003, 01:23
Yet again, I'm filtering single-CCD camcorder DV with a lot of swim in the shadows. That got me to thinking it would be nice to have a smoother which allows restriction based on luminance.

Basically, it would be fed a value and anything under that would be subject to the smoothing. Actually, two settings would be best; one that states the value at which smoothing begins, another which states the value at which smoothing is done at 100% of the smoothing parameters. Everything in between would have a linear percentage of the parameters.

This would help prevent very obvious border zones between the newly-smooth areas and those which aren't processed.

Does anyone know of such a filter or a way to approximate this type of behavior?

FredThompson
28th June 2003, 09:49
This also needs a 2d test to ensure neighboring pixels are also in the candidate range for smoothing. If not, the result could be unintentional coring.

Wilbert
28th June 2003, 12:38
I guess you can use ConditionalFilter for this (also have a look at MergeChroma/MergeLuma).

FredThompson
28th June 2003, 17:02
Those are a little different, they're combining or choosing between 2 files. I'm visualizing something more like a detail-aware smoothing.

With camcorder source, Limiter() helps but there's still noise in the near-black luma of, say, 17-23. The challenge is there are also legitimate pixels with those luma values but high chroma.

Wilbert
28th June 2003, 18:22
Yet again, I'm filtering single-CCD camcorder DV with a lot of swim in the shadows. That got me to thinking it would be nice to have a smoother which allows restriction based on luminance.
Did you actually look at: http://www.avisynth.org/index.php?page=ConditionalFilter

This will choose frames from vid_blur when the average luma value of a frame is less than 20. Otherwise frames from vid will be returned. Adding "true" at the end will display the actual values on the screen:

vid = AviSource("file")
vid_blur = vid.Blur(1.5) # this can be replaced by any smoother
ConditionalFilter(vid, vid_blur, vid, "AverageLuma()", "lessthan", "20")

I don't see how to change this "using a linear way". Maybe Sh0dan has an idea?

FredThompson
28th June 2003, 18:35
That approach replaces an entire frame. Doing that will work for the swimming almost-blacks but detail in the highlighted areas will be lost. It's a nifty approach, though.

Wilbert
29th June 2003, 12:03
Sorry, I didn't read your first post carefully. You want to smooth areas in a frame where the luma is below some threshold. You could the following:

1) Suppose "clip1" is your original clip.
2) Smooth it, resulting in clip2.
3) Use Levels to make a mask (convert pixels with luma<20 to white, and the rest to black).
4) Apply the mask to clip2, resulting in clip3.
5) Layer the clips clip2 and clip3 with a threshold of 256.

This way the smoothed pixels with luma<20, and the normal pixels with luma>=20 will be visible. To make/apply a mask you will have to convert everything to RGB32.

FredThompson
29th June 2003, 15:07
whoa. That's a nifty idea. I'll have to give it a shot. Might be just the thing for some kinds of noisy camcorder shots.

Didée
29th June 2003, 16:14
Time ago, I stumbled over the VirtualDub-filter "ShadowSmoother". I admit to never have tried it actually. But it should do exactly what you need.
Find it here (http://timsara.zetafleet.com/vdub.html).

- Didée

Kurosu
29th June 2003, 16:21
Originally posted by Wilbert

3) Use Levels to make a mask (convert pixels with luma<20 to white, and the rest to black).


That sounds a bit dangerous: if there is no transition, a pixel ith luma of 21 won't be filtered, while one with luma of 20 will. It can may still produce a good output, but it might be better to convert mask with levels on the range (0-20) to 255, and then (20-32) (for instance) to (255-0) (the rest bein left at 0).

The clip resulting from layer could also be converted to a YUV colorspace, and then you would use mergeluma to only keep the smoothing on luma (if it's needed).

Leuf
30th June 2003, 21:33
I modified smart smoother to only work on dark areas some time ago, but never released it. It's RGB32 only and pretty slow. Recompiled it for 2.5 just now.

download here (http://members.verizon.net/~vze3kkvm/dark/darksmoother.zip)

Try something like:

Darksmoother(5,25,20,30)

I've used this on dark analog caps with higher values, like (7,25,50,75). I'd love a YUY2 or YV12 version of this, but the smart smoother hq source was a tad over my head.

FredThompson
1st July 2003, 03:08
That's pretty cool. Maybe DG will run with this idea when he's done with the new decomb.

FredThompson
1st July 2003, 03:43
For your example, luma_lo = 20 and luma_hi = 30.

What do these really mean? Do you, essentially, run DG's code then decide how much of the smoothing to apply to candidate pixels?

IOW, a luma of 30 and above is not modified, anything below 21 is completely modified by the smoothing and 21-29 are modified by a percentage of the calculated smoothing determined by a linear multiplier scale?

Geez, easier to think that than explain it.

Leuf
1st July 2003, 06:05
Yep, it does an alpha blend between the blurred and source if it's between the two, I put that in the readme. I used to do it with a hard cutoff and to be honest I never noticed any artifacts if I kept the threshold low. I just did the gradual blending so I could extend the blurring into higher luma values.

Also note that since it's working from RGB it does a quick and dirty luma calculation so you may have to tweak your thresholds a bit due to rounding errors.

FredThompson
15th July 2003, 05:52
Well, I've just finished some extensive testing.

My preference is for Darksmoother's performance.

However, Shadow Smoother is a LOT faster. I used 2 instances of Shadow Smoother with these settings:

threshold 6 strength 1 difference 3
threshold 5 strength 2 difference 3

by way of comparison, my general field-based filter (adapted from KVCD) yields about 9-10 fps on my Athlon 2100-based mobo.

Adding DarkSmoother to the AviSynth script takes it to 3 fps
2 added Shadow Smoother filters run at 8-9 fps

This is not a complete test, it was in VirtualDub but you should get an idea of how well it performs.

Of the two, DarkSmoother does a better job but at a serious degradation of processing time.

Combined with Xesdeeni's 411 Helper, almost all YUV saturation turns into a glow instead of a grid pattern.

This is really, really cool.