remove_hypotenuse_in_place

Function remove_hypotenuse_in_place 

Source
pub fn remove_hypotenuse_in_place<T>(
    contours: &mut Vec<Contour<T>>,
    max_aspect_ratio: f32,
    border_type: Option<BorderType>,
)
where T: Num + NumCast + Copy + PartialEq + Eq + Ord + AsPrimitive<f32>,
Expand description

Filters a vector of contours in-place based on shape properties.

This function removes contours that do not meet the specified criteria. The filtering is done based on two optional conditions:

  1. Border Type: If border_type is Some, only contours with a matching border_type are kept.
  2. Aspect Ratio: Contours whose minimum area bounding rectangle has an aspect ratio (long side / short side) greater than or equal to max_aspect_ratio are removed.

§Arguments

  • contours: A mutable reference to a Vec<Contour> to be filtered.
  • max_aspect_ratio: The maximum allowed aspect ratio. Must be a positive value.
  • border_type: An Option<BorderType> to filter contours by their border type.

§Examples

use imageproc::contours::{Contour, BorderType};
use imageproc::point::Point;
use image_debug_utils::contours::remove_hypotenuse_in_place;

let mut contours = vec![
    // Square, aspect ratio 1.0 (keep)
    Contour {
        parent: None,
        border_type: BorderType::Outer,
        points: vec![Point::new(0,0), Point::new(10,0), Point::new(10,10), Point::new(0,10)]
    },
    // Thin strip, high aspect ratio > 5.0 (remove)
    Contour {
        parent: None,
        border_type: BorderType::Outer,
        points: vec![Point::new(0,0), Point::new(100,0), Point::new(100,2), Point::new(0,2)]
    }
];

remove_hypotenuse_in_place(&mut contours, 5.0, None);
assert_eq!(contours.len(), 1);

§Panics

§Type Parameters

  • T: The numeric type of the point coordinates. Must implement Num, Copy, AsPrimitive<f32>, and be compatible with min_area_rect.

§Panics

Panics if max_aspect_ratio is not a positive finite number.