-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the implementation of the HLG EOTF function #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,19 +482,24 @@ def eotf_hlg( | |
Returns: | ||
frame_data: pixel values in the physical luminance up to 10,000 cd/m^2 | ||
""" | ||
frame_data = np.maximum(frame_data, 0.0) | ||
frame_data = np.minimum(frame_data, 1.0) | ||
|
||
a = 0.17883277 | ||
b = 0.02372241 | ||
c = 1.00429347 | ||
gamma = 1.2 | ||
if l_max <= 1000.0: | ||
gamma = 1.2 | ||
else: | ||
gamma = 1.2 + 0.42 * np.log10(l_max/1000.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See NOTE 5e in the Recommendation BT.2100 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM, it appears to be NOTE 5f though in the latest verson (https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf). |
||
|
||
frame_data = (frame_data <= 0.5) * (np.power(frame_data, 2.0) / 3.0) + ( | ||
frame_data > 0.5 | ||
) * (np.exp((frame_data - c) / a) - b) | ||
|
||
frame_data = (l_max - l_min) * np.power(frame_data, gamma - 1.0) + l_min | ||
# NOTE: The following is only valid when the function is applied to the Y channel. | ||
# If frame_data was a color channel (R, G, or B), the correct implementation would be: | ||
# (l_max - l_min) * np.power(Y, gamma - 1.0) * frame_data + l_min, | ||
# where Y would be obtained from linearized R, G, B channels. | ||
frame_data = (l_max - l_min) * np.power(frame_data, gamma) + l_min | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part I don't see in BT.2100, but to be honest I have only looked very briefly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @slhck You are right, it is not in the recommendation as it only defines the functions for the individual components. The "most correct" way would therefore be to convert the YUV input to RGB, apply the EOTF on individual components, and convert back to YUV. But I believe that is not really needed for our use case and this solution seems like a reasonable approximation. Would you agree? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, yes, that makes sense. I was more confused about the subtraction |
||
|
||
return frame_data | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the ITU-R Recommendation BT.2100, the values below 0 and above 1 are also possible and acceptable (see NOTE 5g).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fine, note 5h per latest version.