Log in

View Full Version : Histogram Luma mode possible with expression (For HBD)?


mastrboy
28th May 2020, 18:31
I'm trying to find a alternative to Histogram("luma") that works with higher bit depts, but actually solving it might be out reach with my knowledge.

By the description, the function doesn't seem very complex:
"This mode will amplify luminance, and display very small luminance variations. This is good for detecting blocking and noise, and can be helpful at adjusting filter parameters. In this mode a 1 pixel luminance difference will show as a 16 pixel luminance pixel, thus seriously enhancing small flaws. "

I tried understanding the source code from Avisynth plus and Vapoursynth at
https://github.com/dubhater/vapoursynth-histogram/blob/master/src/luma.c
https://github.com/AviSynth/AviSynthPlus/blob/master/avs_core/filters/histogram.cpp#L519
and then translating that into a expression than can be used in mt_lut.

Trying to do that has made me realize that I have no clue what I'm doing and I don't even know if mt_lut can do it at all.

So rather than wasting more time, anyone got a solution for this?
Or do I have have to wait for histogram to support HBD in Avisynth Plus?

Closest I got to something somewhat similear was:
mt_lut("x range_half / 16 ^ range_max *",use_expr=2).Grayscale()
Though it seems to remove most of the details instead of doing whatever histogram is doing.

Andouille
28th May 2020, 18:52
mt_lut (expr="x 16 &u 17 x 15 &u - 1 x 15 &u + ? 14 *", u=-128, v=-128)
Something like that should be "basic" histogram with masktools and should be faster than internal Avisynth's one.
High bit depth ? I dont know...

mastrboy
28th May 2020, 19:23
Something like that should be "basic" histogram with masktools and should be faster than internal Avisynth's one.
High bit depth ? I dont know...

Thanks, it's about 99% similar to histogram("luma") in 8 bit but way too dark in 10bit and completely black in 16bits. It's still way better than my attempt.

So next step to solve this is to make that expression work at any bit-depth if that is possible...

Edit:
Could it be possible with scaleb/scalef functions in Masktools2? (ref: http://avisynth.nl/index.php/MaskTools2#Expression_syntax_supporting_bit_depth_independent_expressions )

SlowDelivery
29th May 2020, 00:40
Putting scale_inputs="allf" makes masktools2 work for HBD so
mt_lut (expr="x 16 &u 17 x 15 &u - 1 x 15 &u + ? 14 *", u=-128, v=-128, scale_inputs="allf")
should do the trick.

mastrboy
29th May 2020, 10:29
Putting scale_inputs="allf" makes masktools2 work for HBD so

should do the trick.

That works indeed.

Thanks for the assistance Andouille and SlowDelivery.