Welcome to pycimg’s documentation!¶
README¶
pycimg is a python extension for the CImg library.
The package contains a single class CImg that provides access to the image processing methods of the CImg library.
Pixel data of CImg objects can be accessed as a numpy array.
Vice versa new CImg objects can be created from pixel data in a numpy array or an image file. Supported file formats are png, jpeg, tiff, bmp, and cimg.
from pycimg import CImg
import numpy as np
# Load image from file
img = CImg('test/test.png')
img.display()
# Access pixel data as numpy array
arr = img.asarray()
# Set pixels in upper left 100 x 100 px rectangle
arr[:,:,0:99,0:99] = 0
# Pixel data is shared with the image instance
img.display()
# Create image from numpy array
img = CImg(np.random.randn(100,100))
Features¶
Documentation¶
See readthedocs.
License¶
The project is licensed under the GPL3 license.
API¶
-
class
pycimg.pycimg.
CImg
(*args, **kwargs)[source]¶ CImg is a wrapper class for the CImg library:
-
__init__
(*args, **kwargs)[source]¶ Create CImg with given data type.
Supported datatypes are int8, int16, int32, uint8, uint16, uint32, float32, and float64.
Examples
1. Create empty image with default type float32 im = CImg()
2. Create image from file. im = CImg(“filename.png”)
3. Create image from numpy array arr = np.zeros((100,2)) im = CImg(arr)
4. Create image of size 100x200 with data type uint8 im = CImg((100, 200), dtype=uint8)
Parameters: image filename, numpy array, or image size. (Either) – Keyword Arguments: dtype – Data type of CImg. Raises: RuntimeError
– For unsupported data types.
-
__weakref__
¶ list of weak references to the object (if defined)
-
depth
¶ Return depth of image.
-
height
¶ Return height of image.
-
shape
¶ Return shape of image data.
-
size
¶ Return the total number of pixel values in the image.
-
spectrum
¶ Return spectrum (number of channels) of image.
-
width
¶ Return width of image.
-