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.

Algorithm

For each side of the image starting from the top, clockwise:

  • Get upper block with 25% height (indent) of the dimension opposite to current side

  • Get lower block with the same height as the upper one (50% of image total)

  • Calculate entropy for both blocks

  • Find their entropies difference

  • Make upper block 1px less

  • Repeat from p.2 until we hit image edge

  • Get maximum (minimum) of the entropies difference

  • Here we have a border center if it lies closer to the edge rather than to the center of image and entropies difference is lower than pre-set threshold

Requirements

Python 3.5+

Setup

pip install enimda

Usage

Find if image has any borders:

from enimda import ENIMDA


# Open target image, convert it to grayscale and resize too 300 px
image = ENIMDA(path='test.jpg', mode='L', resize=300)
# Scan for borders existence
image.scan(threshold=0.5, indent=0.25)
# Save image with outlined borders for demonstration
image.save(path='test-outlined.jpg', outline=True)
# Print found image borders (tuple)
print(image.borders)

Detect borders with high precision (iterative):

from enimda import ENIMDA


# Open target image, convert it to grayscale and resize too 300 px
image = ENIMDA(path='test.jpg', mode='L', resize=300)
# Detect borders
image.detect(threshold=0.5, indent=0.25)
# Save image with outlined borders for demonstration
image.save(path='test-outlined.jpg', outline=True)
# Print found image borders (tuple)
print(image.borders)

Demo

For demonstration please refer to ENIMDA Demo

Project details


Download files

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

Source Distribution

enimda-1.0.0b2.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

enimda-1.0.0b2-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page