color-operations 0.2.0


pip install color-operations

  Latest version

Released: Mar 27, 2025

Project Links

Meta
Author: Charlie Loyd
Maintainer: Vincent Sarago
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers
  • Science/Research

License
  • OSI Approved :: MIT License

Programming Language
  • Cython
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13

Topic
  • Multimedia :: Graphics :: Graphics Conversion
  • Scientific/Engineering :: GIS

color-operations (fork of rio-color )

Apply basic color-oriented image operations.

Test Coverage Package version license

Modified version of Mapbox's rio-color, removing rasterio dependency and with python>=3.10 compatibility.

Install

You can install color-operations using pip

python -m pip install -U pip
python -m pip install color-operations

Build from source

git checkout https://github.com/vincentsarago/color-operations.git
cd color-operations
python -m pip install -U pip
python -m pip install -e .

Operations

Gamma adjustment adjusts RGB values according to a power law, effectively brightening or darkening the midtones. It can be very effective in satellite imagery for reducing atmospheric haze in the blue and green bands.

Sigmoidal contrast adjustment can alter the contrast and brightness of an image in a way that matches human's non-linear visual perception. It works well to increase contrast without blowing out the very dark shadows or already-bright parts of the image.

Saturation can be thought of as the "colorfulness" of a pixel. Highly saturated colors are intense and almost cartoon-like, low saturation is more muted, closer to black and white. You can adjust saturation independently of brightness and hue but the data must be transformed into a different color space.

Ref https://github.com/mapbox/rio-color/blob/master/README.md

Examples

Sigmoidal

Contrast

sigmoidal_contrast

Bias

sigmoidal_bias

Gamma

Red

gamma_red

Green

gamma_green

Blue

gamma_blue

Saturation

saturation

Combinations of operations

combos

Ref https://github.com/mapbox/rio-color/blob/master/README.md

Python API

color_operations.operations

The following functions accept and return numpy ndarrays. The arrays are assumed to be scaled 0 to 1. In some cases, the input array is assumed to be in the RGB colorspace.

All arrays use rasterio ordering with the shape as (bands, columns, rows). Be aware that other image processing software may use the (columns, rows, bands) axis order.

  • sigmoidal(arr, contrast, bias)
  • gamma(arr, g)
  • saturation(rgb, proportion)
  • simple_atmo(rgb, haze, contrast, bias)

The color_operations.operations.parse_operations function takes an operations string and returns a list of python functions which can be applied to an array.

from color_operations import parse_operations

ops = "gamma b 1.85, gamma rg 1.95, sigmoidal rgb 35 0.13, saturation 1.15"

assert arr.shape[0] == 3
assert arr.min() >= 0
assert arr.max() <= 1

for func in parse_operations(ops):
    arr = func(arr)

This provides a tiny domain specific language (DSL) to allow you to compose ordered chains of image manipulations using the above operations. For more information on operation strings, see the rio color command line help.

color_operations.colorspace

The colorspace module provides functions for converting scalars and numpy arrays between different colorspaces.

from color_operations.colorspace import ColorSpace as cs  # enum defining available color spaces
from color_operations.colorspace import convert, convert_arr

convert_arr(array, src=cs.rgb, dst=cs.lch) # for arrays
...

convert(r, g, b, src=cs.rgb, dst=cs.lch)  # for scalars
...

dict(cs.__members__)  # can convert to/from any of these color spaces
{
    'rgb': <ColorSpace.rgb: 0>,
    'xyz': <ColorSpace.xyz: 1>,
    'lab': <ColorSpace.lab: 2>,
    'lch': <ColorSpace.lch: 3>,
    'luv': <ColorSpace.luv: 4>
}

Wheel compatibility matrix

Platform CPython 3.9 CPython 3.10 CPython 3.11 CPython 3.12 CPython 3.13
macosx_10_13_universal2
macosx_10_13_x86_64
macosx_10_9_universal2
macosx_10_9_x86_64
macosx_11_0_arm64
manylinux1_x86_64
manylinux2014_aarch64
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_x86_64
manylinux_2_5_x86_64
win_amd64

Files in release

color_operations-0.2.0-cp310-cp310-macosx_10_9_universal2.whl (84.5KiB)
color_operations-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl (49.8KiB)
color_operations-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (48.1KiB)
color_operations-0.2.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (175.8KiB)
color_operations-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (182.1KiB)
color_operations-0.2.0-cp310-cp310-win_amd64.whl (130.4KiB)
color_operations-0.2.0-cp311-cp311-macosx_10_9_universal2.whl (84.4KiB)
color_operations-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl (49.7KiB)
color_operations-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (48.1KiB)
color_operations-0.2.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (184.7KiB)
color_operations-0.2.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (190.6KiB)
color_operations-0.2.0-cp311-cp311-win_amd64.whl (130.6KiB)
color_operations-0.2.0-cp312-cp312-macosx_10_13_universal2.whl (84.1KiB)
color_operations-0.2.0-cp312-cp312-macosx_10_13_x86_64.whl (49.5KiB)
color_operations-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (47.9KiB)
color_operations-0.2.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (194.0KiB)
color_operations-0.2.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199.5KiB)
color_operations-0.2.0-cp312-cp312-win_amd64.whl (130.3KiB)
color_operations-0.2.0-cp313-cp313-macosx_10_13_universal2.whl (82.6KiB)
color_operations-0.2.0-cp313-cp313-macosx_10_13_x86_64.whl (48.9KiB)
color_operations-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (47.1KiB)
color_operations-0.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (188.5KiB)
color_operations-0.2.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (194.0KiB)
color_operations-0.2.0-cp313-cp313-win_amd64.whl (129.4KiB)
color_operations-0.2.0-cp39-cp39-macosx_10_9_universal2.whl (84.5KiB)
color_operations-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl (49.8KiB)
color_operations-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (48.1KiB)
color_operations-0.2.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (175.6KiB)
color_operations-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (181.9KiB)
color_operations-0.2.0-cp39-cp39-win_amd64.whl (130.3KiB)
color_operations-0.2.0.tar.gz (17.6KiB)
Extras:
Dependencies:
numpy