Skip to main content

Entropy-based image border detection algorithm

Project description

ENtropy-based IMage border Detection Algorithm: finds out if your image has borders or whitespaces around and helps you to trim border providing whitespace offsets for every side of a picture.

Supports GIF border detection and its cropping.

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

Requirements

Python 3.5+

Setup

pip install enimda

Usage

Find if image has any borders:

from enimda import ENIMDA


# Load target image
em = ENIMDA(fp='test.jpg')

# Scan for borders with high precision
em.scan(fast=False)

# Save image with outlined borders for demonstration
em.outline()
em.save(fp='outlined.jpg')

# Print found image borders (tuple)
print(em.borders)

Demo

For demo please refer to ENIMDA Demo

Also it lives at Picture Instruments as ‘Remove borders’ instrument

Tests

Run tests: py.test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for enimda, version 1.1.6
Filename, size File type Python version Upload date Hashes
Filename, size enimda-1.1.6.tar.gz (16.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page