UBC-MDS / imgtoolpy

A Python package that is intended to allow users to compress, sharpen and shrink an input image
MIT License
0 stars 4 forks source link

imgtoolpy

build codecov Release

Documentation Status

Team Members

Name Github
Ruidan Ni rita-ni
Frank Lu Frank Lu
Kexin Zhao Margaret8521

Package Overview

imgtoolpy is a Python package that is intended to allow users to compress, sharpen and crop an input image. Our package only allows the input image to be a 3D numpy array and output the manipulated image as a 3D numpy array. It contains three functions: compress(), sharpen(), and crop().

Feature Description

Installation:

pip install -i https://test.pypi.org/simple/ imgtoolpy

Related Packages

There are a few existing Python packages that perform content-aware image resizing, such as pyCAIR (available on PyPI), and seam-carver. Currently, there is no package available on CRAN to resize images based on the same mechanism, however, there is a package available on Github to seam carve image. Also, there are similar packages for image manipulation such as scikit-image, which could be used for filtering and transforming images.

Dependencies

[tool.poetry.dependencies]

[tool.poetry.dev-dependencies]

Usage

Task from imgtoolpy import compress, crop, sharpen
Compress an image to 4 bits per channel (2^4=16 colors) compress.compress(image, 4)
crop an image to desired width and height crop.crop(image, 20, 20)
Sharpen an image by detecting and enhancing the edges sharpen.sharpen(image)

Usage Scenarios

First, we should load the imgtoolpy library:

from imgtoolpy import compress, crop, sharpen

We are going to use butterfly.jpg image which is in the img folder of this repository for illustration.

We can apply the compress function: compress.compress(image, 4)

import os

from matplotlib.pyplot import imread, imshow, imsave

image = imread(os.path.join("img", "butterfly.jpg"))

imsave(os.path.join("img", "compress.jpg"), compress.compress(image, 4))

We can also apply the crop function: crop.crop(image, 400, 400)

import os

from matplotlib.pyplot import imread, imshow, imsave

image = imread(os.path.join("img", "butterfly.jpg"))

imsave(os.path.join("img", "crop.jpg"), crop.crop(image, 400, 400))

We can also apply the sharpen function: sharpen.sharpen(image)

import os
from matplotlib.pyplot import imread, imsave, cm

image = imread(os.path.join("img", "free-wallpaper.jpg"))
res = sharpen.sharpen(image)
# save the monotoned original image
imsave(os.path.join("img", "sharpen_before.png"), res[0], cmap = cm.gray)
# save the sharpened image
imsave(os.path.join("img", "sharpen_after.png"), res[1], cmap = cm.gray)

Documentation

The official documentation is hosted on Read the Docs: https://imgtoolpy.readthedocs.io/en/latest/

Credits

This package was created with Cookiecutter and the UBC-MDS/cookiecutter-ubc-mds project template, modified from the pyOpenSci/cookiecutter-pyopensci project template and the audreyr/cookiecutter-pypackage.