From 3b10128c8f2f46015bc3094377ceb81508f635d9 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 4 Feb 2021 18:28:27 +0100 Subject: [PATCH] simplify if-else logic for enhancement --- sbb_newspapers_org_image/eynollah.py | 32 +++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/sbb_newspapers_org_image/eynollah.py b/sbb_newspapers_org_image/eynollah.py index 365012f..37f2d57 100644 --- a/sbb_newspapers_org_image/eynollah.py +++ b/sbb_newspapers_org_image/eynollah.py @@ -2136,23 +2136,21 @@ class eynollah: K.clear_session() scale = 1 - if self.allow_enhancement and is_image_enhanced: - cv2.imwrite(os.path.join(self.dir_out, self.image_filename_stem) + ".tif", img_res) - img_res = img_res.astype(np.uint8) - self.get_image_and_scales(img_org, img_res, scale) - - if not self.allow_enhancement and is_image_enhanced: - self.get_image_and_scales_after_enhancing(img_org, img_res) - - if self.allow_enhancement and not is_image_enhanced: - self.get_image_and_scales(img_org, img_res, scale) - - if not self.allow_enhancement and not is_image_enhanced: - self.get_image_and_scales(img_org, img_res, scale) - - if self.allow_scaling and not is_image_enhanced: - img_org, img_res, is_image_enhanced = self.resize_image_with_column_classifier(is_image_enhanced) - self.get_image_and_scales_after_enhancing(img_org, img_res) + if is_image_enhanced: + if self.allow_enhancement: + cv2.imwrite(os.path.join(self.dir_out, self.image_filename_stem) + ".tif", img_res) + img_res = img_res.astype(np.uint8) + self.get_image_and_scales(img_org, img_res, scale) + else: + self.get_image_and_scales_after_enhancing(img_org, img_res) + else: + if self.allow_enhancement: + self.get_image_and_scales(img_org, img_res, scale) + else: + self.get_image_and_scales(img_org, img_res, scale) + if self.allow_scaling: + img_org, img_res, is_image_enhanced = self.resize_image_with_column_classifier(is_image_enhanced) + self.get_image_and_scales_after_enhancing(img_org, img_res) self.logger.info("Enhancing took %ss ", str(time.time() - t1)) text_regions_p_1 = self.get_regions_from_xy_2models(img_res, is_image_enhanced)