From e7aeb17404fa1a353a7ac9b79a18b49916eb7f50 Mon Sep 17 00:00:00 2001 From: James Betker Date: Tue, 22 Dec 2020 15:42:21 -0700 Subject: [PATCH] ImageFolder dataset: allow intermediary downscale before corrupt For massive upscales (ex: 8x), corruption does almost nothing when applied at the HQ level. This patch adds support to perform corruption at a specified intermediary scale. The dataset downscales to this level, performs the corruption, then downscales the rest of the way to get the LQ image. --- codes/data/image_folder_dataset.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/codes/data/image_folder_dataset.py b/codes/data/image_folder_dataset.py index 9817cb62..00c61832 100644 --- a/codes/data/image_folder_dataset.py +++ b/codes/data/image_folder_dataset.py @@ -82,11 +82,19 @@ class ImageFolderDataset: def synthesize_lq(self, hs): h, w, _ = hs[0].shape ls = [] + local_scale = self.scale if self.corrupt_before_downsize: - hs = [h.copy() for h in hs] + # You can downsize to a specified scale, then corrupt, then continue the downsize further using this option. + if 'corrupt_before_downsize_factor' in self.opt.keys(): + special_factor = self.opt['corrupt_before_downsize_factor'] + hs = [cv2.resize(h_, (h // special_factor, w // special_factor), interpolation=cv2.INTER_AREA) for h_ in hs] + local_scale = local_scale // special_factor + else: + hs = [h.copy() for h in hs] hs = self.corruptor.corrupt_images(hs) for hq in hs: - ls.append(cv2.resize(hq, (h // self.scale, w // self.scale), interpolation=cv2.INTER_AREA)) + h, w, _ = hq.shape + ls.append(cv2.resize(hq, (h // local_scale, w // local_scale), interpolation=cv2.INTER_AREA)) # Corrupt the LQ image (only in eval mode) if not self.corrupt_before_downsize: ls = self.corruptor.corrupt_images(ls)