#border #image #entropy #algorithm

enimda

Entropy-based image border detection

11 unstable releases (3 breaking)

Uses old Rust 2015

0.4.1 Apr 24, 2017
0.4.0 Apr 23, 2017
0.3.4 Mar 1, 2017
0.3.3 Feb 25, 2017
0.1.5 Jan 29, 2017

#864 in Images

27 downloads per month

MIT license

1MB
203 lines

ENIMDA

Entropy-based image border detection algorithm: detect border or whitespace offset for every side of image, supports animated GIFs.

latest version at crates.io travis ci build status

Documentation

https://docs.rs/enimda/

Algorithm (simplified)

For each side of the image starting from top, rotating image counterclockwise to keep side of interest on top:

  • Get upper block 25% of image height
  • Get lower block with the same height as the upper one
  • Calculate entropy for both blocks and their difference
  • Make upper block 1px less
  • Repeat from p.2 until we hit image edge
  • Border is between blocks with entropy difference maximum
Sliding from center to edge - searching for maximum entropy difference

Example

Find image borders:

extern crate enimda;

use std::path::Path;
use enimda::enimda;

fn main() {
    let path = Path::new("source.jpeg");
    let borders = enimda(&path, Some(10), Some(512), Some(50), Some(0.25), Some(0.5), Some(false)).unwrap();
    println!("{:?}", borders);
}

Demo

For demo please refer to ENIMDA Demo

Also it lives at Picture Instruments as 'Remove borders' instrument

Tests

cargo test

Dependencies

~4.5MB
~45K SLoC