Skip to main content

remove_overlap_blocks

Function remove_overlap_blocks 

Source
pub fn remove_overlap_blocks(
    elements: &[LayoutBox],
    threshold: f32,
) -> OverlapRemovalResult<LayoutBox>
Expand description

Removes overlapping layout blocks based on overlap ratio threshold.

This follows standard overlap removal implementation in layout_parsing/utils.py. When two blocks overlap significantly:

  • If one is an image and one is not, the image is removed (text takes priority)
  • Otherwise, the smaller block is removed

§Arguments

  • elements - Slice of layout elements to process
  • threshold - Overlap ratio threshold (default: 0.65) If intersection/smaller_area > threshold, blocks are considered overlapping

§Returns

OverlapRemovalResult containing kept elements and indices of removed elements

§Example

use oar_ocr_core::processors::layout_utils::{remove_overlap_blocks, LayoutBox};
use oar_ocr_core::processors::BoundingBox;

let elements = vec![
    LayoutBox::new(BoundingBox::from_coords(0.0, 0.0, 100.0, 100.0), "text".to_string()),
    LayoutBox::new(BoundingBox::from_coords(10.0, 10.0, 90.0, 90.0), "text".to_string()),
];

let result = remove_overlap_blocks(&elements, 0.65);
assert_eq!(result.kept.len(), 1); // Smaller overlapping box was removed