gyakujinton

OpenCV wrapper to handle shapes and images.


License
MIT
Install
pip install gyakujinton==0.4.0

Documentation

Gyaku Jinton

made-with-python PyPI pyversions Maintenance Awesome Badges

OpenCV wrapper to handle shapes and images.

Installation

Just execute the command below and do the jutsus below!

pip install gyakujinton

Pre-requisites

  • Python 3.6.1 or higher
  • OpenCV

I suggest to check OpenCV's tutorials on installation to help you.

Programmatic

Drawing a polygon on image

Given an image path, by identifying points in the image, you can draw line based on given point.

If color is added as argument, it will also draw those lines by that color. The color is in RGB format.

If output_path is not defined, the application will create an application window with the modified image.

from gyakujinton import draw_on_image
draw_on_image(
    image_path="/path/to/file.filetype",
    output_path="/path/to/output-file.filetype",  #optional
    points=[[INT, INT], ..., [INT, INT]],  # points on a 2D plane
    color=(0, 0, 0)  # in RGB; optional
)

Distorting an image

Given an image path, this image will be the basis for distortion. The distortion will be from mimimum distortion of 10% to a maximum distortion of 40%. This number is identified in randomly.

A patch parameter can be defined to focus on an area in an image. This will "crop" the image based on the input patch. This patch should be a rectangle for a proper distortion to take place.

If output_path is not defined, the application will create an application window with the modified image.

from gyakujinton import skew_image
skew_image(
    image_path="/path/to/file.filetype",
    output_path="/path/to/output-file.filetype",  #optional
    patch=[[INT, INT], ..., [INT, INT]],  # points on a 2D plane
)

Note: The window that will be created will not consider alpha values. As such, to see transparency it is recommended to save the file in PNG format.

Command-line Interface

The application also allows executions through the CLI.

Drawing a polygon on image (CLI)

The example below gets the image based on the path given and will draw a polygon based on the input points.

gyakujinton draw_on_image /path/to/file.filetype --points 100,100 200,100 200,200 100,200

We can also define an output path by adding the argument -o or --output_path followed by the file path.

gyakujinton draw_on_image /path/to/file.filetype --points 100,100 200,100 200,200 100,200 --output_path /path/to/output-file.filetype

Distorting an image (CLI)

A proof-of-concept is created within the application to distort the skew the input image.

gyakujinton distort /path/to/file.filetype --patch 10,10 10,400 400,400 400,10

Similar to previous functions, an output path can be set to write the image into a file.

Note: The window that will be created will not consider alpha values. As such, to see transparency it is recommended to save the file in PNG format.

Sample

To test out the application, we'll be using an image by Samantha Gades taken from Unsplash. We have this beautiful and simple original image.

Original Image

We can draw a polygon near the clock by doing the following in the command-line:

gyakujinton draw_on_image sample/samantha-gades-unsplash.jpg --points 150,150 150,250 250,250 250,150

Modified Image

Again, we are not restricted with the polygon that we want to create. It all depends on where we put the points and how they are ordered when lines are to be drawn.

gyakujinton draw_on_image sample/samantha-gades-unsplash.jpg --points 100,100 100,150 180,200 250,150 250,100 180,50 -o output-2.jpg

Modified Image 2

We can also test out the created function for image distortion.

gyakujinton distort sample/samantha-gades-unsplash.jpg --patch 10,10 10,400 400,400 400,10 -o output.distort.jpg

Modified Image 3

Name Inspiration

Ohnoki's Dust Release

Source: naruto.fandom.com/wiki

When thinking of a name for the app, the first thing that came into mind is Ohnoki's Particle Style (or Dust Release) Atomic Dismantling Jutsu from Naruto which is a technique that has a sphere in the center contained by a geometric object. In the series, dust release is called Jinton which was chosen due to how amazed I am on the shapes happening.

Now, with the points above, the technique is used to dismantle atoms to dust. Gyaku (or reverse as taught to me by Google Translate) was added to signify making of shapes and images rather than dismantling them.

Hence, the app name Gyaku Jinton.

Author

Almer Mendoza