WUT_Computer_Science/code/sightpy/utils/colour_functions.py

23 lines
710 B
Python
Raw Normal View History

2025-01-12 12:07:04 +01:00
import numpy as np
def sRGB_linear_to_sRGB(rgb_linear):
'''sRGB standard for gamma inverse correction.'''
rgb = np.where( rgb_linear <= 0.00304, 12.92 * rgb_linear, 1.055 * np.power(rgb_linear, 1.0/2.4) - 0.055)
# clip intensity if needed (rgb values > 1.0) by scaling
rgb_max = np.amax(rgb, axis=0) + 0.00001 # avoid division by zero
intensity_cutoff = 1.0
rgb = np.where(rgb_max > intensity_cutoff, rgb * intensity_cutoff / (rgb_max), rgb)
return rgb
def sRGB_to_sRGB_linear(rgb):
'''sRGB standard for gamma inverse correction.'''
rgb_linear = np.where( rgb <= 0.03928, rgb / 12.92, np.power((rgb + 0.055) / 1.055, 2.4))
return rgb_linear