Skip to content

Commit 10a4b6a

Browse files
committed
fix typos
1 parent 4ce0999 commit 10a4b6a

3 files changed

Lines changed: 27 additions & 43 deletions

File tree

modules/eeh.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88

99
from .basic_module import BasicModule, register_dependent_modules
10-
from .helpers import gaussian_filter, gen_gaussian_kernel
10+
from .helpers import generic_filter, gen_gaussian_kernel
1111

1212

1313
@register_dependent_modules('csc')
@@ -16,7 +16,7 @@ def __init__(self, cfg):
1616
super().__init__(cfg)
1717

1818
kernel = gen_gaussian_kernel(kernel_size=5, sigma=1.2)
19-
self.kernel = (1024 * kernel / kernel.max()).astype(np.int32) # x1024
19+
self.gaussian = (1024 * kernel / kernel.max()).astype(np.int32) # x1024
2020

2121
t1, t2 = self.params.flat_threshold, self.params.edge_threshold
2222
threshold_delta = np.clip(t2 - t1, 1E-6, None)
@@ -27,7 +27,7 @@ def __init__(self, cfg):
2727
def execute(self, data):
2828
y_image = data['y_image'].astype(np.int32)
2929

30-
delta = y_image - gaussian_filter(y_image, self.kernel)
30+
delta = y_image - generic_filter(y_image, self.gaussian)
3131
sign_map = np.sign(delta)
3232
abs_delta = np.abs(delta)
3333

@@ -39,7 +39,6 @@ def execute(self, data):
3939
)
4040

4141
enhanced_delta = sign_map * np.clip(enhanced_delta, 0, self.params.delta_threshold)
42-
4342
eeh_y_image = np.clip(y_image + enhanced_delta, 0, self.cfg.saturation_values.sdr)
4443

4544
data['y_image'] = eeh_y_image.astype(np.uint8)

modules/helpers.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def get_bayer_indices(pattern):
1212
Get (x_start_idx, y_start_idx) for R, Gr, Gb, and B channels
1313
in Bayer array, respectively
1414
"""
15-
1615
return {'gbrg': ((0, 1), (1, 1), (0, 0), (1, 0)),
1716
'rggb': ((0, 0), (1, 0), (0, 1), (1, 1)),
1817
'bggr': ((1, 1), (0, 1), (1, 0), (0, 0)),
@@ -26,7 +25,6 @@ def split_bayer(bayer_array, bayer_pattern):
2625
:param bayer_pattern: 'gbrg' | 'rggb' | 'bggr' | 'grbg'
2726
:return: 4-element list of R, Gr, Gb, and B channel sub-arrays, each is an np.ndarray(H/2, W/2)
2827
"""
29-
3028
rggb_indices = get_bayer_indices(bayer_pattern)
3129

3230
sub_arrays = []
@@ -47,7 +45,6 @@ def reconstruct_bayer(sub_arrays, bayer_pattern):
4745
:param bayer_pattern: 'gbrg' | 'rggb' | 'bggr' | 'grbg'
4846
:return: np.ndarray(H, W)
4947
"""
50-
5148
rggb_indices = get_bayer_indices(bayer_pattern)
5249

5350
height, width = sub_arrays[0].shape
@@ -71,7 +68,6 @@ def pad(array, pads, mode='reflect'):
7168
:param mode: padding mode, see np.pad
7269
:return: padded array: np.ndarray(H', W', ...)
7370
"""
74-
7571
if isinstance(pads, (list, tuple, np.ndarray)):
7672
if len(pads) == 2:
7773
pads = ((pads[0], pads[0]), (pads[1], pads[1])) + ((0, 0),) * (array.ndim - 2)
@@ -93,7 +89,6 @@ def crop(array, crops):
9389
if 4-element sequence: (top crop, bottom crop, left crop, right crop)
9490
:return: cropped array: np.ndarray(H', W', ...)
9591
"""
96-
9792
if isinstance(crops, (list, tuple, np.ndarray)):
9893
if len(crops) == 2:
9994
top_crop = bottom_crop = crops[0]
@@ -117,7 +112,6 @@ def shift_array(padded_array, window_size):
117112
:return: a generator of length (2r+1)*(2r+1), each is an np.ndarray(H, W), and the original
118113
array before padding locates in the middle of the generator
119114
"""
120-
121115
wy, wx = window_size if isinstance(window_size, (list, tuple)) else (window_size, window_size)
122116
assert wy % 2 == 1 and wx % 2 == 1, 'only odd window size is valid'
123117

@@ -150,50 +144,48 @@ def gen_gaussian_kernel(kernel_size, sigma):
150144
return kernel / kernel.sum()
151145

152146

153-
def mean_filter(array, filter_size=3):
154-
"""
155-
A faster reimplementation of the mean-filter
156-
:param array: array to be filter: np.ndarray(H, W, ...)
157-
:param filter_size: int, diameter of the mean-filter
158-
:return: filtered array: np.ndarray(H, W, ...)
147+
def generic_filter(array, kernel):
159148
"""
160-
161-
assert filter_size % 2 == 1, 'only odd filter size is valid'
162-
163-
padded_array = pad(array, pads=filter_size // 2)
164-
shifted_arrays = shift_array(padded_array, window_size=filter_size)
165-
return (sum(shifted_arrays) / filter_size ** 2).astype(array.dtype)
166-
167-
168-
def gaussian_filter(array, kernel):
169-
"""
170-
A faster reimplementation of the bilateral-filter
149+
Filter input image array with given kernel
171150
:param array: array to be filter: np.ndarray(H, W, ...), must be np.int dtype
172151
:param kernel: np.ndarray(h, w)
173152
:return: filtered array: np.ndarray(H, W, ...)
174153
"""
175-
176154
kh, kw = kernel.shape[:2]
177155
kernel = kernel.flatten()
178156

179157
padded_array = pad(array, pads=(kh // 2, kw // 2))
180158
shifted_arrays = shift_array(padded_array, window_size=(kh, kw))
181159

182-
gf_array = np.zeros_like(array)
160+
filtered_array = np.zeros_like(array)
183161
weights = np.zeros_like(array)
184162

185163
for i, shifted_array in enumerate(shifted_arrays):
186-
gf_array += kernel[i] * shifted_array
164+
filtered_array += kernel[i] * shifted_array
187165
weights += kernel[i]
188166

189-
gf_array = (gf_array / weights).astype(array.dtype)
167+
filtered_array = (filtered_array / weights).astype(array.dtype)
168+
return filtered_array
190169

191-
return gf_array
170+
171+
def mean_filter(array, filter_size=3):
172+
"""
173+
A faster reimplementation of the mean filter
174+
:param array: array to be filter: np.ndarray(H, W, ...)
175+
:param filter_size: int, diameter of the mean-filter
176+
:return: filtered array: np.ndarray(H, W, ...)
177+
"""
178+
179+
assert filter_size % 2 == 1, 'only odd filter size is valid'
180+
181+
padded_array = pad(array, pads=filter_size // 2)
182+
shifted_arrays = shift_array(padded_array, window_size=filter_size)
183+
return (sum(shifted_arrays) / filter_size ** 2).astype(array.dtype)
192184

193185

194186
def bilateral_filter(array, spatial_weights, intensity_weights_lut, right_shift=0):
195187
"""
196-
A faster reimplementation of the bilateral-filter
188+
A faster reimplementation of the bilateral filter
197189
:param array: array to be filter: np.ndarray(H, W, ...), must be np.int dtype
198190
:param spatial_weights: np.ndarray(h, w): predefined spatial gaussian kernel, where h and w are
199191
kernel height and width respectively
@@ -202,7 +194,6 @@ def bilateral_filter(array, spatial_weights, intensity_weights_lut, right_shift=
202194
right to avoid integer overflow when multiply this result to the input array
203195
:return: filtered array: np.ndarray(H, W, ...)
204196
"""
205-
206197
filter_height, filter_width = spatial_weights.shape[:2]
207198
spatial_weights = spatial_weights.flatten()
208199

@@ -222,4 +213,4 @@ def bilateral_filter(array, spatial_weights, intensity_weights_lut, right_shift=
222213

223214
bf_array = (bf_array / weights).astype(array.dtype)
224215

225-
return bf_array
216+
return bf_array

pipeline.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
class Pipeline:
2323
""" Core fast-openISP pipeline """
24-
2524
def __init__(self, cfg):
2625
"""
2726
:param cfg: yacs.Config object, configurations about camera specs and module parameters
@@ -42,7 +41,6 @@ def get_saturation_values(self):
4241
module, i.e., Gamma in openISP (not included)
4342
SDR stage: dataflow after the Gamma module (included)
4443
"""
45-
4644
raw_max_value = 2 ** self.cfg.hardware.raw_bit_depth - 1
4745
sdr_max_value = 255
4846

@@ -63,7 +61,6 @@ def get_saturation_values(self):
6361

6462
def get_modules(self):
6563
""" Get activated ISP modules according to the configuration """
66-
6764
if op.dirname(__file__) not in sys.path:
6865
sys.path.insert(0, op.dirname(__file__))
6966

@@ -97,6 +94,7 @@ def execute(self, bayer, save_intermediates=False, verbose=True):
9794
intermediates: a dict containing intermediate results if save_intermediates=True,
9895
otherwise a empty dict
9996
"""
97+
10098
def print_(*args, **kwargs):
10199
return print(*args, **kwargs) if verbose else None
102100

@@ -126,7 +124,6 @@ def get_output(self, data):
126124
:param data: argument returned by self.execute()
127125
:return: displayable result: np.ndarray(H, W, 3) in np.uint8 dtype
128126
"""
129-
130127
if 'y_image' in data and 'cbcr_image' in data:
131128
ycbcr_image = np.dstack([data['y_image'][..., None], data['cbcr_image']])
132129
output = ycbcr_to_rgb(ycbcr_image)
@@ -152,7 +149,6 @@ def run(self, raw_path, save_dir, load_raw_fn, suffix=''):
152149
:param load_raw_fn: function to load the Bayer array from the raw_path
153150
:param suffix: suffix to added to the output filename
154151
"""
155-
156152
import cv2
157153

158154
bayer = load_raw_fn(raw_path)
@@ -165,15 +161,14 @@ def run(self, raw_path, save_dir, load_raw_fn, suffix=''):
165161

166162
def batch_run(self, raw_paths, save_dirs, load_raw_fn, suffixes='', num_processes=1):
167163
"""
168-
Batch running with multiprocessing
164+
Batch version of self.run via multiprocessing
169165
:param raw_paths: list of paths to the raw files to be executed
170166
:param save_dirs: list of directories to save the outputs. If given a string, it will be
171167
copied to a N-element list, where N is the number of paths in raw_paths
172168
:param load_raw_fn: function to load the Bayer array from the raw_path
173169
:param suffixes: a list of suffixes to added to the output filenames
174170
:param num_processes: number of processes in multiprocessing
175171
"""
176-
177172
num_files = len(raw_paths)
178173
num_batches = math.ceil(num_files / num_processes)
179174

@@ -210,7 +205,6 @@ def batch_run(self, raw_paths, save_dirs, load_raw_fn, suffixes='', num_processe
210205

211206
def ycbcr_to_rgb(ycbcr_array):
212207
""" Convert YCbCr 3-channel array into sRGB array """
213-
214208
assert ycbcr_array.dtype == np.uint8
215209

216210
matrix = np.array([[298, 0, 409],

0 commit comments

Comments
 (0)