<commit_before>ENIMDA
======

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

.. image:: https://raw.githubusercontent.com/embali/enimda/master/algorithm.gif
    :alt: Sliding from center to edge - searching for maximum entropy difference
    :width: 300
    :height: 300

Requirements
------------

Python 3.5+

Setup
-----

.. code-block:: bash
    
    pip install enimda

Usage
-----

Find if image has any borders:

.. code-block:: python

    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 images please refer to `ENIMDA Demo <https://github.com/embali/enimda-demo/>`_

Also see live demo at `Picture Instruments <http://picinst.com/>`_ as 'Remove borders' instrument

Tests
-----

Run tests: py.test<commit_msg>prepare for packaging, live demo<commit_after>ENIMDA
======

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

.. image:: https://raw.githubusercontent.com/embali/enimda/master/algorithm.gif
    :alt: Sliding from center to edge - searching for maximum entropy difference
    :width: 300
    :height: 300

Requirements
------------

Python 3.5+

Setup
-----

.. code-block:: bash
    
    pip install enimda

Usage
-----

Find if image has any borders:

.. code-block:: python

    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 <https://github.com/embali/enimda-demo/>`_

Also see live at `Picture Instruments <http://picinst.com/>`_ as 'Remove borders' instrument

Tests
-----

Run tests: py.test
{'fraction_non_alphanumeric': 0.10148439866707058, 'fraction_numerical': 0.007270524083611027, 'mean_word_length': 3.132665832290363, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6142649', 'n_tokens_mistral': 978, 'n_tokens_neox': 913, 'n_words': 397}