{"id":8026,"library":"color-operations","title":"Color Operations","description":"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.","status":"active","version":"0.2.0","language":"en","source_language":"en","source_url":"https://github.com/vincentsarago/color-operations","tags":["color","image processing","computer vision","numpy","operations","raster"],"install":[{"cmd":"pip install color-operations","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Required for array manipulation, as functions accept and return numpy ndarrays. Although not a strict PyPI dependency, it's essential for practical use.","package":"numpy","optional":false}],"imports":[{"note":"Contains core image manipulation functions like `sigmoidal`, `gamma`, and `saturation`.","symbol":"operations","correct":"from color_operations import operations"}],"quickstart":{"code":"import numpy as np\nfrom color_operations import operations\n\n# Simulate a 3-band RGB image (e.g., 100x100 pixels)\n# Input arrays are expected to be (bands, rows, columns) and scaled 0-1.\nimage_array = np.random.rand(3, 100, 100).astype(np.float32)\n\n# Apply a sigmoidal contrast adjustment\n# contrast: adjusts the slope of the sigmoid function (higher values mean higher contrast)\n# bias: shifts the sigmoid function (affects brightness)\nsigmoidal_adjusted = operations.sigmoidal(image_array, contrast=5, bias=0.5)\n\n# Apply gamma correction to brighten midtones (e.g., gamma > 1.0 darkens, < 1.0 brightens)\ngamma_corrected = operations.gamma(image_array, g=0.8)\n\n# Adjust saturation (proportion > 1.0 increases saturation, < 1.0 decreases)\nsaturated_image = operations.saturation(image_array, proportion=1.5)\n\nprint(f\"Original image array shape: {image_array.shape}\")\nprint(f\"Sigmoidal adjusted image shape: {sigmoidal_adjusted.shape}\")\nprint(f\"Gamma corrected image shape: {gamma_corrected.shape}\")\nprint(f\"Saturated image shape: {saturated_image.shape}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to version 3.9 or higher.","message":"Python 3.8 is no longer supported; the library now requires Python >= 3.9 for installation and use.","severity":"breaking","affected_versions":"0.2.0 and later"},{"fix":"Ensure all image data is provided as raw `numpy.ndarray` objects. If `rasterio` integration is critical, consider using `rio-color` instead.","message":"This library is an explicit fork of `rio-color` that *removes* the `rasterio` dependency. Code expecting `rasterio` objects or direct `rasterio` integration will not work.","severity":"breaking","affected_versions":"All versions of `color-operations`"},{"fix":"Before passing data to `color-operations`, ensure your arrays are reshaped (e.g., `image.transpose(2, 0, 1)` for (H,W,C) to (C,H,W)) and rescaled (e.g., `image_255 / 255.0` for 0-255 to 0-1). Convert back if needed for display or other libraries.","message":"Input and output NumPy arrays for all operations are expected to be in `(bands, columns, rows)` order (similar to `rasterio`'s internal representation) and have pixel values scaled from 0.0 to 1.0. Many other image processing libraries use `(rows, columns, bands)` or 0-255 scaling.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Reshape your NumPy array. If your array is `(rows, columns, bands)`, use `your_array.transpose(2, 0, 1)` before passing it to `color-operations` functions.","cause":"The input NumPy array has an incorrect dimension order. `color-operations` expects `(bands, rows, columns)`, but you might be providing `(rows, columns, bands)`.","error":"ValueError: operands could not be broadcast together with shapes (H,W,C) (C,H,W)"},{"fix":"Verify that your input NumPy array's pixel values are floating-point numbers between 0.0 and 1.0. If starting from an 8-bit image (0-255), convert it with `image_255.astype(np.float32) / 255.0`. Remember to convert output back to 0-255 for display/saving if necessary (e.g., `(output_array * 255).astype(np.uint8)`).","cause":"Input pixel values are not scaled between 0.0 and 1.0 (e.g., still 0-255), or the output 0-1.0 values are being misinterpreted by a display tool expecting 0-255.","error":"Output image appears completely washed out, over-saturated, or incorrect."},{"fix":"This library does not support `rasterio` directly. Extract the raw `numpy.ndarray` from your `rasterio` dataset to use with `color-operations`. If deep `rasterio` integration is required, use the original `rio-color` library.","cause":"You are attempting to use `color-operations` in a manner that expects `rasterio` integration. This library is a fork specifically designed to *remove* `rasterio` as a dependency.","error":"ModuleNotFoundError: No module named 'rasterio'"}]}