Simple image processing library for python
# pip3 install numpy
# pip3 install matplotlib
git clone https://github.com/cb285/python_image/
from python_image import *
or import python_image
python_image's Img type inherits from numpy's ndarray, which allows for compatability with a large number of complex functions provided by numpy. more information can be found here.
if you need to convert between an Img type and ndarray, use the view function:
Img to ndarray: img.view(np.ndarray)
ndarray to Img: img.view(Img)
imread(filename)
Reads a file into an image.
Parameters:
filename
: string, name of image file to read
Returns:
- Img, image created by reading file
Example: img = imread("strawberries.png")
Supported file types:
- png
- NetPBM Formats (pbm, pgm, ppm)
Img.imwrite(filename)
Writes an image to file.
Parameters:
filename
: string, name of file to create
Filename extension specifies filetype. Supports same file types as reading.
Example: img.imwrite("my_image.png")
Img.imshow(figure, block)
Displays an image in a window.
Parameters:
figure
: integer, figure number - change for displaying multiple images at one time (default: 1)block
: bool, if True then function blocks until the window is closed (default: True)
Example: img.imshow(1, False)
Note: if blocking is disabled then all windows will close when the program finishes.
Img(shape, dtype)
Creates a new image with specified shape and data type initially filled with zeros.
Parameters:
shape
: tuple, shape (dimensions) of created array (default: (1, 1))dtype
: data-type (python or numpy), datatype of created image (default: uint8)
Returns:
- Img, new image filled with zeros
Img[y, x]
y
: vertical distance from top of imagex
: horizontal distance from left of image
Img[z, y, x]
z
: plane- 0 : Red/Hue
- 1 : Green/Saturation
- 2 : Blue/Intensity
y
: vertical distance from top of imagex
: horizontal distance from left of image
Example: value = img[4, 30]
Example: img[43, 12] = value
Pad types:
PADTYPE_NONE
: padding disabled, out-of-bounds addressing will cause an exception (default)PADTYPE_ZERO
: out-of-bounds addressing will return zeroPADTYPE_SAME
: out-of-bounds addressing will return the nearest pixel's value
Img.padtype(padtype)
Parameters:
padtype
: padtype, string constant specifying desired pad type
Img.padtype()
Returns the current pad type of the image as a string constant.
Returns:
- string constant, current padtype
Img.rgb2hsi()
Converts the image from RGB to HSI representation.
Returns:
- Img, hsi representation of RGB image
Example: hsi = rgb_img.rgb2hsi()
Img.hsi2rgb()
Converts the image from HSI to RGB representation.
Returns:
- Img, rgb representation of HSI image
Img.conv2(mask, padtype)
Performs in-place 2D convolution. Values will be in the range [0, 1]
Parameters:
mask
: Img, odd-dimensioned image to use as maskpadtype
: string constant, specifies padding to be used during convolution (defaults to image's current pad type)