Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit f71a9e6

Browse files
committed
update SampleProcessor.py
1 parent a1ba64b commit f71a9e6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

samplelib/SampleProcessor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def get_eyes_mouth_mask():
9292
nearest_resize_to = opts.get('nearest_resize_to', None)
9393
warp = opts.get('warp', False)
9494
transform = opts.get('transform', False)
95+
random_hsv_shift_amount = opts.get('random_hsv_shift_amount', 0)
9596
normalize_tanh = opts.get('normalize_tanh', False)
9697
ct_mode = opts.get('ct_mode', None)
9798
data_format = opts.get('data_format', 'NHWC')
@@ -190,6 +191,15 @@ def get_eyes_mouth_mask():
190191
if ct_sample_bgr is None:
191192
ct_sample_bgr = ct_sample.load_bgr()
192193
img = imagelib.color_transfer (ct_mode, img, cv2.resize( ct_sample_bgr, (resolution,resolution), interpolation=cv2.INTER_LINEAR ) )
194+
195+
if random_hsv_shift_amount != 0:
196+
a = random_hsv_shift_amount
197+
h_amount = max(1, int(360*a*0.5))
198+
img_h, img_s, img_v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
199+
img_h = (img_h + rnd_state.randint(-h_amount, h_amount+1) ) % 360
200+
img_s = np.clip (img_s + (rnd_state.random()-0.5)*a, 0, 1 )
201+
img_v = np.clip (img_v + (rnd_state.random()-0.5)*a, 0, 1 )
202+
img = np.clip( cv2.cvtColor(cv2.merge([img_h, img_s, img_v]), cv2.COLOR_HSV2BGR) , 0, 1 )
193203

194204
img = imagelib.warp_by_params (warp_params, img, warp, transform, can_flip=True, border_replicate=border_replicate)
195205

0 commit comments

Comments
 (0)