Color Operations

0.2.0 · active · verified Thu Apr 16

The `color-operations` library applies basic color-oriented image operations, serving as a modified fork of Mapbox's `rio-color` library. It specifically removes the `rasterio` dependency and ensures compatibility with Python 3.10 and newer. Version 0.2.0 was released recently, focusing on distribution and Python version updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic color operations (sigmoidal contrast, gamma correction, saturation adjustment) on a simulated NumPy image array. The library expects input arrays to be in `(bands, rows, columns)` order with pixel values scaled between 0.0 and 1.0.

import numpy as np
from color_operations import operations

# Simulate a 3-band RGB image (e.g., 100x100 pixels)
# Input arrays are expected to be (bands, rows, columns) and scaled 0-1.
image_array = np.random.rand(3, 100, 100).astype(np.float32)

# Apply a sigmoidal contrast adjustment
# contrast: adjusts the slope of the sigmoid function (higher values mean higher contrast)
# bias: shifts the sigmoid function (affects brightness)
sigmoidal_adjusted = operations.sigmoidal(image_array, contrast=5, bias=0.5)

# Apply gamma correction to brighten midtones (e.g., gamma > 1.0 darkens, < 1.0 brightens)
gamma_corrected = operations.gamma(image_array, g=0.8)

# Adjust saturation (proportion > 1.0 increases saturation, < 1.0 decreases)
saturated_image = operations.saturation(image_array, proportion=1.5)

print(f"Original image array shape: {image_array.shape}")
print(f"Sigmoidal adjusted image shape: {sigmoidal_adjusted.shape}")
print(f"Gamma corrected image shape: {gamma_corrected.shape}")
print(f"Saturated image shape: {saturated_image.shape}")

view raw JSON →