Welcome to pycimg’s documentation!

Build Status Coverage Status Documentation Status PyPI version

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

  • Access pixel data as a numpy array.
  • Builtin support for reading/writing png, jpeg, and tiff image formats.

Installation

Install pycimg by running:

pip install pycimg

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:

__eq__(img)[source]

Return self==value.

__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.
__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

asarray(copy=False)[source]

Returns image data as a numpy array.

Parameters:copy (bool) – False.
depth

Return depth of image.

height

Return height of image.

isempty()[source]

Return true if image is empty.

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.

Indices and tables