Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th January 2019, 09:58   #61  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by asarian View Post
So, maybe you know a solution to my problem too. See: DGHDRtoSDR lacking in contrast

Which also makes me wonder, would there be a way for DGHDRtoSDR to extract values like 'Max luminance: 1000' from the metadata itself?
I don't have UBD content, so I don't know what they look like.

For HDR TV, HDR was suppose to look different from SDR, as it preserves detail on both highlight and shadow instead of "white" being blown out in SDR in comparison. But as a result, it will look washier and less contrast than SDR. You HDR result looks ok to me except for the saturation.
lansing is offline   Reply With Quote
Old 26th March 2019, 11:22   #62  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Quote:
Originally Posted by lansing View Post
Ok after reading the hable reference article from ifb's tonemap page, I just realized that hable is not for 4k hdr tv to sdr conversion. It was created for images and SDR games to make them looks HDR. So this whole approach to use it for "4K HDR TV content -> SDR" is just wrong. The right tool for this in vapoursynth is DGHDRtoSDR.
I don't think that matters at all, it's a curve as valid as any other and as you can see mpv is using it for this purpose.
Alexkral is offline   Reply With Quote
Old 26th March 2019, 17:15   #63  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
Quote:
Originally Posted by Alexkral View Post
I don't think that matters at all, it's a curve as valid as any other and as you can see mpv is using it for this purpose.
And maybe that's why it gives the obvious wrong color on HDR content?
lansing is offline   Reply With Quote
Old 26th March 2019, 18:04   #64  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by lansing View Post
I don't have UBD content, so I don't know what they look like.

For HDR TV, HDR was suppose to look different from SDR, as it preserves detail on both highlight and shadow instead of "white" being blown out in SDR in comparison. But as a result, it will look washier and less contrast than SDR. You HDR result looks ok to me except for the saturation.
I do not have (1080p) Blu-Rays for all UHD discs I own, so I will only seldom be able to do a comparison. Hence, my initial question, "would there be a way for DGHDRtoSDR to extract values like 'Max luminance: 1000' from the metadata itself?" And then for contrast too, of course.
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 26th March 2019, 18:45   #65  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
Quote:
Originally Posted by lansing View Post
And maybe that's why it gives the obvious wrong color on HDR content?
I don't see those wrong colors in mpv, so the problem is in the script, not in the curve. It may be because the script is tone mapping the RGB channels instead of the luminance. I don't know what DGHDRtoSDR does in that sense, but it seems to be using the Reinhard TMO which is much simpler.
Alexkral is offline   Reply With Quote
Old 26th March 2019, 18:54   #66  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
@asarian

DGHDRtoSDR doesn't even have a parameter for that.
Alexkral is offline   Reply With Quote
Old 26th March 2019, 22:25   #67  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by Alexkral View Post
@asarian

DGHDRtoSDR doesn't even have a parameter for that.
Why would it need a parameter for that?! Preferably, it would find and extract the info on its own from the UHD Blu-Ray structure (DV layer and what not; or, if it needs a parameter per se, a location of the meta-data file).
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 26th March 2019, 23:26   #68  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
It would still need a parameter internally for the math.
Alexkral is offline   Reply With Quote
Old 13th April 2019, 19:45   #69  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
I was testing the tonemapping using the hue-constant curves from adobe
https://github.com/Beep6581/RawThera.../curves.h#L919
https://github.com/Beep6581/RawThera.../curves.h#L974

Here's a new script
tonemapping.py
Code:
import vapoursynth as vs



def tm_hable(clip="",source_peak=1000 ) :
    core = vs.get_core()
    c=clip

    source_peak=source_peak 
    LDR_nits=100     
    exposure_bias=source_peak/LDR_nits
    o=c
    c=core.std.Limiter(c, 0)     
    r=core.std.ShufflePlanes(c, planes=[0], colorfamily=vs.GRAY)
    g=core.std.ShufflePlanes(c, planes=[1], colorfamily=vs.GRAY)
    b=core.std.ShufflePlanes(c, planes=[2], colorfamily=vs.GRAY)
    lum = core.std.Expr(clips=[r,g,b], expr="0.216 x * 0.715 y * + 0.0722 z * +")
    lum=core.std.Limiter(lum, 0)
    lum=core.std.ShufflePlanes(lum, planes=[0], colorfamily=vs.RGB)



    
    rr="x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.05 + * 0.004 + x  {exposure_bias} * 0.15 x  {exposure_bias} * * 0.50 + * 0.06 + / 0.02 0.30 / - 1 {exposure_bias} 0.15 {exposure_bias} * 0.05 + * 0.004 + {exposure_bias} 0.15 {exposure_bias} * 0.50 + * 0.06 + / 0.02 0.30 / - / * ".format(exposure_bias=exposure_bias)
    gg="y  {exposure_bias} * 0.15 y  {exposure_bias} * * 0.05 + * 0.004 + y  {exposure_bias} * 0.15 y  {exposure_bias} * * 0.50 + * 0.06 + / 0.02 0.30 / - 1 {exposure_bias} 0.15 {exposure_bias} * 0.05 + * 0.004 + {exposure_bias} 0.15 {exposure_bias} * 0.50 + * 0.06 + / 0.02 0.30 / - / * ".format(exposure_bias=exposure_bias)
    bb="z {exposure_bias} * 0.15 z  {exposure_bias} * * 0.05 + * 0.004 + z  {exposure_bias} * 0.15 z  {exposure_bias} * * 0.50 + * 0.06 + / 0.02 0.30 / - 1 {exposure_bias} 0.15 {exposure_bias} * 0.05 + * 0.004 + {exposure_bias} 0.15 {exposure_bias} * 0.50 + * 0.06 + / 0.02 0.30 / - / * ".format(exposure_bias=exposure_bias)


    r1 = core.std.Expr(clips=[r,g,b], expr="x y >=   y z > {rr}   z x > x y - z y - / {bb} {gg} - * {gg} +     z y > {rr} {rr}   ?  ?     ?    x z >=   x z - y z - / {gg} {bb} - * {bb} + z y >  {rr}   {rr}            ? ? ?     ".format(exposure_bias=exposure_bias,rr=rr,gg=gg,bb=bb))
    g1 = core.std.Expr(clips=[r,g,b], expr="x y >=   y z > y z - x z - / {rr} {bb} - * {bb} +  z x > {gg}      z y > {gg}  {gg}   ?  ?     ?    x z >=   {gg}  z y >  y x - z x - / {bb} {rr} - * {rr} +   {gg}            ? ? ?        ".format(exposure_bias=exposure_bias,rr=rr,gg=gg,bb=bb))
    b1 = core.std.Expr(clips=[r,g,b], expr="x y >=   y z > {bb}   z x > {bb}      z y > z y -  x y - / {rr} {gg} - * {gg} +  {bb}   ?  ?     ?    x z >=   {bb}  z y >  {bb}   z x - y x - / {gg} {rr} - * {rr} +            ? ? ?    ".format(exposure_bias=exposure_bias,rr=rr,gg=gg,bb=bb))

    crgb=core.std.ShufflePlanes(clips=[r1,g1,b1], planes=[0,0,0], colorfamily=vs.RGB)


    lumtm = core.std.Expr(clips=[r1,g1,b1], expr="0.216 x * 0.715 y * + 0.0722 z * +")
    lumtm=core.std.Limiter(lumtm, 0)
    lumtm=core.std.ShufflePlanes(lumtm, planes=[0], colorfamily=vs.RGB)
    clum = core.std.Expr(clips=[o,lum,lumtm], expr=" x {exposure_bias} *  y {exposure_bias} *  / z *  ".format(exposure_bias=exposure_bias))
    clum=core.std.Limiter(clum, 0)    

    mask=core.std.Expr(clips=[lum,lumtm], expr=" x {exposure_bias} * y - abs {exposure_bias}  1 - /  ".format(exposure_bias=exposure_bias))
    mask=core.std.Limiter(mask, 0,1)

                       
    ctemp=core.std.MaskedMerge(crgb, lumtm, mask)
    c=core.std.Merge(clum, ctemp, 0.5)

    return c
It looks similar to the new algo used by madvr at 200 nits target, not as good as madvr because the script needs a gamut compression when converting to rec.709 color primaries

http://screenshotcomparison.com/comparison/133859
http://screenshotcomparison.com/comparison/133858
http://screenshotcomparison.com/comparison/133861

It has only a parameter source_peak

this is the usage of the script
Code:
import tonemapping
import vapoursynth as vs

core = vs.get_core()
c = core.ffms2.Source(source = 'C:/Users/.../videos/HDR.mp4')

source_peak=1200 
matrix_in_s="2020ncl"
transfer_in_s="st2084"


c=core.resize.Bicubic(clip=c, format=vs.RGBS, filter_param_a=0, filter_param_b=0.75, matrix_in_s=matrix_in_s,chromaloc_in_s="center",chromaloc_s="center", range_in_s="limited",dither_type="none")

c=core.resize.Bilinear(clip=c, format=vs.RGBS, transfer_in_s=transfer_in_s, transfer_s="linear",dither_type="none", nominal_luminance=source_peak)



c=tonemapping.tm_hable(c,source_peak=source_peak )

c=core.resize.Bilinear(clip=c, format=vs.RGBS, primaries_in_s="2020", primaries_s="709",dither_type="none")
c=core.resize.Bilinear(clip=c, format=vs.RGBS, transfer_in_s="linear", transfer_s="709",dither_type="none")

c=core.resize.Bicubic(clip=c, format=vs.YUV420P8,matrix_s="709", filter_param_a=0, filter_param_b=0.75, range_in_s="full",range_s="limited", chromaloc_in_s="center", chromaloc_s="center",dither_type="none")

c.set_output()

Last edited by age; 2nd May 2019 at 13:00.
age is offline   Reply With Quote
Old 16th May 2019, 20:26   #70  |  Link
chipseps
Guest
 
Posts: n/a
Quote:
Originally Posted by age View Post
Thank you all for your suggestion and the hdr samples.
Well I've discovered some interesting things....
First, a better version of the hable tonemapping that gives better contrast,brightness and saturation.
http://screenshotcomparison.com/comparison/203550


I've tried different algorithms, the aces tonemapping too but I don't like it very much.
Here a good link for a lot of open source tm operators :

https://github.com/tizian/tonemapper.../src/operators

And a different version of aces:

https://github.com/keijiro/PostProce...emapping.cginc


new script with correct parameters
Code:
import vapoursynth as vs


core = vs.get_core()
c = core.ffms2.Source(source  = 'C:/bla')

source_peak=1000 #set manually
LDR_nits=100     #set 150 or 200 for lowering the brightness

c=core.resize.Bilinear(clip=c, format=vs.YUV444PS, range_in_s="limited", range_s="full",chromaloc_in_s="center",dither_type="none")

c=core.resize.Bicubic(clip=c, format=vs.RGBS, matrix_in_s="2020ncl", range_in_s="full",dither_type="none")

c=core.resize.Bilinear(clip=c, format=vs.RGBS, transfer_in_s="st2084", transfer_s="linear",dither_type="none", nominal_luminance=source_peak)

exposure_bias=(source_peak/LDR_nits)

#hable tone mapping  correct parameters
#["A"] = 0.22
#["B"] = 0.3
#["C"] = 0.1
#["D"] = 0.2
#["E"] = 0.01
#["F"] = 0.3
#["W"] = 11.2
#((x * (A*x + C*B) + D*E) / (x * (A*x+B) + D*F)) - E/F"   
tm = core.std.Expr(c, expr="x    {exposure_bias} * 0.22 x    {exposure_bias} * * 0.03 + * 0.002 +    x   {exposure_bias} * 0.22 x   {exposure_bias} * * 0.3 + * 0.06 + / 0.01 0.30 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)#12=1200 nits / 100 nits



w = core.std.Expr(c, expr="{exposure_bias} 0.22 {exposure_bias} * 0.03 + * 0.002 + {exposure_bias} 0.22 {exposure_bias} * 0.3 + * 0.06 + / 0.01 0.30 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)

c = core.std.Expr(clips=[tm,w], expr=" x  1 y  / *  ",format=vs.RGBS)

#c=core.fmtc.primaries(clip=c, prims="2020", primd="709")
c=core.resize.Bilinear(clip=c, format=vs.RGBS, primaries_in_s="2020", primaries_s="709",dither_type="none")
c=core.resize.Bilinear(clip=c, format=vs.RGBS, transfer_in_s="linear", transfer_s="709",dither_type="none")

c=core.resize.Bilinear(clip=c, format=vs.YUV420P8, matrix_s="709", range_in_s="full",range_s="limited",chromaloc_in_s="center")


c.set_output()
Hi you! With color filtering like this, what command must we use to crop and resize to 1080p? Because I'm newbie encodec so I don't know! Hope to help you! thank you very much!
  Reply With Quote
Old 16th May 2019, 21:16   #71  |  Link
gonca
Registered User
 
Join Date: Jul 2012
Posts: 1,213
Quote:
Originally Posted by asarian View Post
I do not have (1080p) Blu-Rays for all UHD discs I own, so I will only seldom be able to do a comparison. Hence, my initial question, "would there be a way for DGHDRtoSDR to extract values like 'Max luminance: 1000' from the metadata itself?" And then for contrast too, of course.
The master display data, CLL, and FALL is "extracted by DGIndexNV
gonca is offline   Reply With Quote
Old 16th May 2019, 21:42   #72  |  Link
videoh
Useful n00b
 
Join Date: Jul 2014
Posts: 1,667
Quote:
Originally Posted by gonca View Post
The master display data, CLL, and FALL is "extracted by DGIndexNV
... and recorded in the DGI file.
videoh is offline   Reply With Quote
Reply

Tags
hdr, sdr

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:24.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.