File size: 1,288 Bytes
e91104d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import cv2
import numpy as np
def perform_flash(source, a=5, target=-1, perform_gamma_correction=True):
rows, cols, _ = source.shape
v = np.max(source, axis=2)
vd = np.copy(v)
vd[vd == 0] = 1e-9
result = source / (a * np.exp(np.mean(np.log(vd))) + np.tile(np.expand_dims(vd, axis=2), (1, 1, 3)))
if perform_gamma_correction:
result **= 1.0 / 2.2
if target >= 0:
result *= target / np.mean((0.299 * result[:, :, 2] + 0.587 * result[:, :, 1] + 0.114 * result[:, :, 0]))
else:
result *= 255.0 / np.max(result)
return result
def perform_storm(source, a=5, target=-1, kernels=(1, 4, 16, 64, 256), perform_gamma_correction=True):
rows, cols, _ = source.shape
v = np.max(source, axis=2)
vd = np.copy(v)
vd[vd == 0] = 1e-9
lv = np.log(vd)
result = sum([source / np.tile(
np.expand_dims(a * np.exp(cv2.boxFilter(lv, -1, (int(min(rows // kernel, cols // kernel)),) * 2)) + vd, axis=2),
(1, 1, 3)) for kernel in kernels])
if perform_gamma_correction:
result **= 1.0 / 2.2
if target >= 0:
result *= target / np.mean((0.299 * result[:, :, 2] + 0.587 * result[:, :, 1] + 0.114 * result[:, :, 0]))
else:
result *= 255.0 / np.max(result)
return result
|