Skip to content

Instantly share code, notes, and snippets.

@sobotka
Last active December 15, 2021 22:55
Show Gist options
  • Save sobotka/277e844eca9f16d8de7b88d6fdfa0deb to your computer and use it in GitHub Desktop.
Save sobotka/277e844eca9f16d8de7b88d6fdfa0deb to your computer and use it in GitHub Desktop.
def open_domain_to_normalized_log2(
in_od,
in_middle_grey=0.18,
minimum_ev=-6.0,
maximum_ev=+7.0
):
total_exposure = maximum_ev - minimum_ev
in_od = numpy.asarray(in_od)
in_od[in_od <= 0.0] = numpy.finfo(numpy.float).eps
output_log = numpy.clip(
numpy.log2(in_od / in_middle_grey),
minimum_ev,
maximum_ev
)
return as_numeric((output_log - minimum_ev) / total_exposure)
# Convert normalised log value to scene referred linear value.
def calculate_log_to_sr(
in_log_norm,
sr_middle_grey=base_middle_grey,
minimum_ev=base_dr_minimum_ev,
maximum_ev=base_dr_maximum_ev
):
in_log_norm = numpy.asarray(in_log_norm)
in_log_norm = numpy.clip(in_log_norm, 0., 1.) * (
maximum_ev - minimum_ev) + minimum_ev
return as_numeric(numpy.power(2., in_log_norm) * sr_middle_grey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment