From aa76a223df492d901ac5bd4778f0a9a386b2d85e Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Tue, 24 Nov 2020 16:08:14 +0100 Subject: [PATCH] more extraction of util functions --- sbb_newspapers_org_image/eynollah.py | 15 ++------------- sbb_newspapers_org_image/utils.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sbb_newspapers_org_image/eynollah.py b/sbb_newspapers_org_image/eynollah.py index 48ce610..5038c25 100644 --- a/sbb_newspapers_org_image/eynollah.py +++ b/sbb_newspapers_org_image/eynollah.py @@ -76,6 +76,7 @@ from .utils import ( seperate_lines_new_inside_teils2, seperate_lines_vertical_cont, delete_seperator_around, + return_regions_without_seperators, ) @@ -3827,18 +3828,6 @@ class eynollah: # cv2.imwrite(os.path.join(dir_of_image, self.f_name) + ".tif",self.image_org) - def return_regions_without_seperators(self, regions_pre): - kernel = np.ones((5, 5), np.uint8) - regions_without_seperators = ((regions_pre[:, :] != 6) & (regions_pre[:, :] != 0)) * 1 - # regions_without_seperators=( (image_regions_eraly_p[:,:,:]!=6) & (image_regions_eraly_p[:,:,:]!=0) & (image_regions_eraly_p[:,:,:]!=5) & (image_regions_eraly_p[:,:,:]!=8) & (image_regions_eraly_p[:,:,:]!=7))*1 - - regions_without_seperators = regions_without_seperators.astype(np.uint8) - - regions_without_seperators = cv2.erode(regions_without_seperators, kernel, iterations=6) - - return regions_without_seperators - - def image_change_background_pixels_to_zero(self, image_page): image_back_zero = np.zeros((image_page.shape[0], image_page.shape[1])) image_back_zero[:, :] = image_page[:, :, 0] @@ -6048,7 +6037,7 @@ class eynollah: args_big_parts = np.array(range(len(spliter_y_new_diff)))[spliter_y_new_diff > 22] - regions_without_seperators = self.return_regions_without_seperators(region_pre_p) + regions_without_seperators = return_regions_without_seperators(region_pre_p) ##print(args_big_parts,'args_big_parts') # image_page_otsu=otsu_copy(image_page_deskewd) diff --git a/sbb_newspapers_org_image/utils.py b/sbb_newspapers_org_image/utils.py index 314ff26..d8de791 100644 --- a/sbb_newspapers_org_image/utils.py +++ b/sbb_newspapers_org_image/utils.py @@ -2329,3 +2329,15 @@ def delete_seperator_around(spliter_y, peaks_neg, image_by_region): image_by_region[int(spliter_y[i]) : int(spliter_y[i + 1]), peaks_neg[i][j] - int(1.0 / 20.0 * peaks_neg[i][j]) : peaks_neg[i][j] + int(1.0 / 20.0 * peaks_neg[i][j])][image_by_region[int(spliter_y[i]) : int(spliter_y[i + 1]), peaks_neg[i][j] - int(1.0 / 20.0 * peaks_neg[i][j]) : peaks_neg[i][j] + int(1.0 / 20.0 * peaks_neg[i][j])] == 7] = 0 return image_by_region +def return_regions_without_seperators(regions_pre): + kernel = np.ones((5, 5), np.uint8) + regions_without_seperators = ((regions_pre[:, :] != 6) & (regions_pre[:, :] != 0)) * 1 + # regions_without_seperators=( (image_regions_eraly_p[:,:,:]!=6) & (image_regions_eraly_p[:,:,:]!=0) & (image_regions_eraly_p[:,:,:]!=5) & (image_regions_eraly_p[:,:,:]!=8) & (image_regions_eraly_p[:,:,:]!=7))*1 + + regions_without_seperators = regions_without_seperators.astype(np.uint8) + + regions_without_seperators = cv2.erode(regions_without_seperators, kernel, iterations=6) + + return regions_without_seperators + +