重构-抽纯函数
This commit is contained in:
40
app/tests/eotf.py
Normal file
40
app/tests/eotf.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""EOTF(PQ / ST.2084)相关纯算法。"""
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def calculate_pq_curve(gray_levels):
|
||||
"""计算 PQ (ST.2084) EOTF 理想曲线。
|
||||
|
||||
Args:
|
||||
gray_levels: 灰阶百分比数组 (0-100)
|
||||
|
||||
Returns:
|
||||
numpy.ndarray: 归一化亮度数组 (0-1)
|
||||
"""
|
||||
# PQ 曲线参数(ITU-R BT.2100 标准)
|
||||
m1 = 0.1593017578125 # = 2610 / 16384
|
||||
m2 = 78.84375 # = 78.84375
|
||||
c1 = 0.8359375 # = 3424 / 4096
|
||||
c2 = 18.8515625 # = 2413 / 128
|
||||
c3 = 18.6875 # = 2392 / 128
|
||||
|
||||
L_bar = []
|
||||
for gray in gray_levels:
|
||||
V = gray / 100.0
|
||||
|
||||
if V <= 0:
|
||||
L_bar.append(0)
|
||||
else:
|
||||
V_pow = np.power(V, 1 / m2)
|
||||
numerator = max(V_pow - c1, 0)
|
||||
denominator = c2 - c3 * V_pow
|
||||
|
||||
if denominator > 0:
|
||||
L = np.power(numerator / denominator, 1 / m1)
|
||||
else:
|
||||
L = 0
|
||||
|
||||
L_bar.append(L)
|
||||
|
||||
return np.array(L_bar)
|
||||
Reference in New Issue
Block a user