utils: introduce box2rect and box2slice

This commit is contained in:
Robert Sachunsky 2025-08-26 21:00:33 +02:00
parent d3566e55ef
commit 892ff41e38

View file

@ -1,3 +1,4 @@
from typing import Tuple
import time import time
import math import math
@ -298,9 +299,17 @@ def return_x_start_end_mothers_childs_and_type_of_reading_order(
x_end_with_child_without_mother, x_end_with_child_without_mother,
new_main_sep_y) new_main_sep_y)
def box2rect(box: Tuple[int, int, int, int]) -> Tuple[int, int, int, int]:
return (box[1], box[1] + box[3],
box[0], box[0] + box[2])
def box2slice(box: Tuple[int, int, int, int]) -> Tuple[slice, slice]:
return (slice(box[1], box[1] + box[3]),
slice(box[0], box[0] + box[2]))
def crop_image_inside_box(box, img_org_copy): def crop_image_inside_box(box, img_org_copy):
image_box = img_org_copy[box[1] : box[1] + box[3], box[0] : box[0] + box[2]] image_box = img_org_copy[box2slice(box)]
return image_box, [box[1], box[1] + box[3], box[0], box[0] + box[2]] return image_box, box2rect(box)
def otsu_copy_binary(img): def otsu_copy_binary(img):
img_r = np.zeros((img.shape[0], img.shape[1], 3)) img_r = np.zeros((img.shape[0], img.shape[1], 3))