@@ -368,7 +368,7 @@ def get_neighbour_pixels(
368
368
369
369
def detect_horizontal_and_vertical_lines (
370
370
image : np .ndarray ,
371
- average_depiction_size : Tuple [int , int ]
371
+ max_depiction_size : Tuple [int , int ]
372
372
) -> np .ndarray :
373
373
"""
374
374
This function takes an image and returns a binary mask that labels the pixels that
@@ -378,15 +378,16 @@ def detect_horizontal_and_vertical_lines(
378
378
Args:
379
379
image (np.ndarray): binarised image (np.array; type bool) as it is returned by
380
380
binary_erosion() in complete_structure_mask()
381
+ max_depiction_size (Tuple[int, int]): height, width; used as thresholds
381
382
382
383
Returns:
383
384
np.ndarray: Exclusion mask that contains indices of pixels that are part of
384
385
horizontal or vertical lines
385
386
"""
386
387
binarised_im = ~ image * 255
387
388
binarised_im = binarised_im .astype ("uint8" )
388
-
389
- structure_height , structure_width = average_depiction_size
389
+
390
+ structure_height , structure_width = max_depiction_size
390
391
391
392
horizontal_kernel = cv2 .getStructuringElement (
392
393
cv2 .MORPH_RECT , (structure_width , 1 )
@@ -477,23 +478,23 @@ def expansion_coordination(
477
478
def complete_structure_mask (
478
479
image_array : np .array ,
479
480
mask_array : np .array ,
480
- average_depiction_size : Tuple [int , int ],
481
+ max_depiction_size : Tuple [int , int ],
481
482
debug = False
482
483
) -> np .array :
483
484
"""
484
485
This funtion takes an image (np.array) and an array containing the masks (shape:
485
486
x,y,n where n is the amount of masks and x and y are the pixel coordinates).
486
- Additionally, it takes the average depiction size of the structures in the image
487
+ Additionally, it takes the maximal depiction size of the structures in the image
487
488
which is used to define the kernel size for the vertical and horizontal line
488
489
detection for the exclusion masks. The exclusion mask is used to exclude pixels
489
- from the mask expansion to avoid including whole tables.
490
+ from the mask expansion to avoid including whole tables.
490
491
It detects objects on the contours of the mask and expands it until it frames the
491
492
complete object in the image. It returns the expanded mask array
492
493
493
494
Args:
494
495
image_array (np.array): input image
495
496
mask_array (np.array): shape: y, x, n where n is the amount of masks
496
- average_depiction_size (Tuple[int, int]): height, width
497
+ max_depiction_size (Tuple[int, int]): height, width
497
498
debug (bool, optional): More verbose if True. Defaults to False.
498
499
499
500
Returns:
@@ -519,7 +520,7 @@ def complete_structure_mask(
519
520
[mask_array [:, :, index ] for index in range (mask_array .shape [2 ])]
520
521
)
521
522
exclusion_mask = detect_horizontal_and_vertical_lines (blurred_image_array ,
522
- average_depiction_size )
523
+ max_depiction_size )
523
524
# Run expansion the expansion
524
525
image_repeat = itertools .repeat (blurred_image_array , mask_array .shape [2 ])
525
526
exclusion_mask_repeat = itertools .repeat (exclusion_mask , mask_array .shape [2 ])
0 commit comments