Skip to content

Commit 759dbd4

Browse files
committed
update algorithms for EEH and FCS modules
1 parent 11079ac commit 759dbd4

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

modules/eeh.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,32 @@ class EEH(BasicModule):
1515
def __init__(self, cfg):
1616
super().__init__(cfg)
1717

18-
kernel = gen_gaussian_kernel(kernel_size=7, sigma=5.0)
18+
kernel = gen_gaussian_kernel(kernel_size=5, sigma=1.2)
1919
self.kernel = (1024 * kernel / kernel.max()).astype(np.int32) # x1024
2020

21-
flat_slope = self.params.middle_threshold / (self.params.middle_threshold - self.params.flat_threshold + 1E-6)
22-
edge_slope = self.params.edge_gain / 256
23-
24-
self.flat_slope = np.array(256 * flat_slope, dtype=np.int32) # x256
25-
self.edge_slope = np.array(256 * edge_slope, dtype=np.int32) # x256
26-
self.flat_intercept = -np.array(256 * flat_slope * self.params.flat_threshold, dtype=np.int32) # x256
27-
self.edge_intercept = np.array(256 * (1 - edge_slope) * self.params.edge_threshold, dtype=np.int32) # x256
21+
t1, t2 = self.params.flat_threshold, self.params.edge_threshold
22+
threshold_delta = np.clip(t2 - t1, 1E-6, None)
23+
self.middle_slope = np.array(self.params.edge_gain * t2 / threshold_delta, dtype=np.int32) # x256
24+
self.middle_intercept = -np.array(self.params.edge_gain * t1 * t2 / threshold_delta, dtype=np.int32) # x256
25+
self.edge_gain = np.array(self.params.edge_gain, dtype=np.int32) # x256
2826

2927
def execute(self, data):
3028
y_image = data['y_image'].astype(np.int32)
3129

32-
gf_y_image = gaussian_filter(y_image, self.kernel)
33-
34-
delta = y_image - gf_y_image
30+
delta = y_image - gaussian_filter(y_image, self.kernel)
3531
sign_map = np.sign(delta)
3632
abs_delta = np.abs(delta)
3733

38-
flat_delta = np.right_shift(self.flat_slope * abs_delta + self.flat_intercept, 8)
39-
edge_delta = np.right_shift(self.edge_slope * abs_delta + self.edge_intercept, 8)
40-
enhanced_delta = sign_map * (
41-
(abs_delta > self.params.flat_threshold) * (abs_delta <= self.params.middle_threshold) * flat_delta +
42-
(abs_delta > self.params.middle_threshold) * (abs_delta <= self.params.edge_threshold) * abs_delta +
34+
middle_delta = np.right_shift(self.middle_slope * abs_delta + self.middle_intercept, 8)
35+
edge_delta = np.right_shift(self.edge_gain * abs_delta, 8)
36+
enhanced_delta = (
37+
(abs_delta > self.params.flat_threshold) * (abs_delta <= self.params.edge_threshold) * middle_delta +
4338
(abs_delta > self.params.edge_threshold) * edge_delta
4439
)
45-
enhanced_delta = np.clip(enhanced_delta, -self.params.delta_threshold, self.params.delta_threshold)
4640

47-
eeh_y_image = np.clip(gf_y_image + enhanced_delta, 0, self.cfg.saturation_values.sdr)
41+
enhanced_delta = sign_map * np.clip(enhanced_delta, 0, self.params.delta_threshold)
42+
43+
eeh_y_image = np.clip(y_image + enhanced_delta, 0, self.cfg.saturation_values.sdr)
4844

4945
data['y_image'] = eeh_y_image.astype(np.uint8)
5046
data['edge_map'] = delta

modules/fcs.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ class FCS(BasicModule):
1414
def __init__(self, cfg):
1515
super().__init__(cfg)
1616

17-
slope = (self.params.edge_gain - self.params.flat_gain) / (self.params.delta_max - self.params.delta_min)
18-
intercept = -slope * self.params.delta_max
19-
self.slope = np.array(slope, dtype=np.int32) # x256
20-
self.intercept = np.array(intercept, dtype=np.int32)
17+
threshold_delta = np.clip(self.params.delta_max - self.params.delta_min, 1E-6, None)
18+
self.slope = -np.array(65536 / threshold_delta, dtype=np.int32) # x65536
2119

2220
def execute(self, data):
2321
cbcr_image = data['cbcr_image'].astype(np.int32)
2422
edge_map = data['edge_map']
2523

26-
gain_map = self.slope * np.abs(edge_map) + self.intercept
27-
gain_map = np.clip(gain_map, self.params.edge_gain, self.params.flat_gain)
28-
fcs_cbcr_image = np.right_shift(gain_map[..., None] * (cbcr_image - 128), 8) + 128
24+
gain_map = self.slope * (np.abs(edge_map) - self.params.delta_max)
25+
gain_map = np.clip(gain_map, 0, 65536)
26+
fcs_cbcr_image = np.right_shift(gain_map[..., None] * (cbcr_image - 128), 16) + 128
2927
fcs_cbcr_image = np.clip(fcs_cbcr_image, 0, self.cfg.saturation_values.sdr)
3028

3129
data['cbcr_image'] = fcs_cbcr_image.astype(np.uint8)

0 commit comments

Comments
 (0)