View Single Post
Old 12th March 2017, 17:12   #1  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
HDR10 to SDR with Hable tone-mapping

Hi!
This is a basic script for hdr to sdr conversion, I'm not sure i've used the hable tonemapping in the right way.
it's a tone mapping operator used for videogames but it seems good even for videos.
Code:
import vapoursynth as vs


core = vs.get_core()
c = core.ffms2.Source(source = 'path/to/file')

source_peak=1200 #set manually


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.Bilinear(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/100

#hable/uncharted tone mapping
tm = core.std.Expr(c, expr="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 / -  ".format(exposure_bias=exposure_bias),format=vs.RGBS)#12=1200 nits / 100 nits

w = core.std.Expr(c, expr="{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),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()
HDR10 is generally mastered with with a peak brightness of 1000,1200,1500 nits and it corrisponds with the parameter in the script "source_peak".

I only have some hdr video sample downloaded so I can't test exhaustively this script, but it produces reasonably good output.

There's at least one issue:
I use the resizer in the core for conversion from bt.2020 to bt.709 and from the github
"Note that "z" is not a color management system and should not be used to perform drastic contrast or gamut reduction, such as BT.2020 to BT.709."


Screenshot before/after:
http://screenshotcomparison.com/comparison/203274

http://screenshotcomparison.com/comparison/203275

http://screenshotcomparison.com/comparison/203276
age is offline   Reply With Quote