From 0c8ab9b510ddf5f84485da324f8b6f30c18cd803 Mon Sep 17 00:00:00 2001 From: Jeremy Hummel Date: Sun, 23 May 2021 22:15:22 -0700 Subject: [PATCH] fix jpeg range --- samplelib/SampleProcessor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samplelib/SampleProcessor.py b/samplelib/SampleProcessor.py index 620b973..f8d1106 100644 --- a/samplelib/SampleProcessor.py +++ b/samplelib/SampleProcessor.py @@ -261,10 +261,11 @@ class SampleProcessor(object): # Apply random jpeg compression if random_jpeg: + img = np.clip(img*255, 0, 255).astype(np.uint8) jpeg_compression_level = np.random.randint(50, 85) encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), jpeg_compression_level] - _, encimg = cv2.imencode('.jpg', img, encode_param) - img = cv2.imdecode(encimg, 1) + _, enc_img = cv2.imencode('.jpg', img, encode_param) + img = cv2.imdecode(enc_img, cv2.IMREAD_UNCHANGED).astype(np.float32) / 255.0 img = imagelib.warp_by_params (params_per_resolution[resolution], img, warp, transform, can_flip=True, border_replicate=border_replicate) img = np.clip(img.astype(np.float32), 0, 1)