An integer RGB to HSV converter using the Chernov algorithm
Project description
RGB-to-HSV
An integer RGB ↔ HSV converter implementing the algorithm from:
Chernov, Vladimir, Jarmo Alander, and Vladimir Bochko.
"Integer-Based Accurate Conversion between RGB and HSV Color Spaces."
Computers & Electrical Engineering 46 (August 2015): 328–37.
https://doi.org/10.1016/j.compeleceng.2015.08.005
All arithmetic is performed in the integer domain to avoid floating-point rounding errors.
Features
- Accurate integer conversion — no floating-point rounding errors.
- Batch / image support — works on single pixels, 1-D arrays of pixels, and
full 2-D images (
H × W × 3arrays). - Flexible I/O — read/write JPEG, PNG, TIFF, BMP, WebP (via Pillow), CSV / TXT (via NumPy), and HDF5 (via h5py).
- Command-line interface —
rgb2hsv convert input.png output.h5 - Tkinter GUI —
rgb2hsv-gui python -m rgb_to_hsvshorthand.
Installation
# From PyPI (once published)
pip install rgb-to-hsv
# From source
git clone https://github.com/alencina-faa/RGB-to-HSV.git
cd RGB-to-HSV
pip install -e ".[dev]"
Dependencies
| Package | Purpose | Required? |
|---|---|---|
numpy |
Array math | Yes |
Pillow |
Image I/O | Optional (needed for image files) |
h5py |
HDF5 I/O | Optional (needed for .h5 files) |
Python API
import numpy as np
from rgb_to_hsv import rgb_to_hsv, hsv_to_rgb
# Single pixel
rgb = np.array([[255, 0, 0]], dtype=np.uint8) # pure red
hsv = rgb_to_hsv(rgb)
# hsv[0] => (H, S, V) as uint32 integers
# Round-trip
rgb_back = hsv_to_rgb(hsv)
# Full image (H × W × 3, uint8)
from rgb_to_hsv.io_handlers import read_image, write_image
img = read_image("photo.jpg") # uint8 RGB
hsv_img = rgb_to_hsv(img) # uint32 HSV
rgb_img = hsv_to_rgb(hsv_img) # uint8 RGB
write_image("out.png", rgb_img)
Chernov integer constants
| Constant | Value | Description |
|---|---|---|
Chernov.E |
65537 | Unit hue step (1/6 of full circle) |
Chernov.S_MAX |
65535 | Maximum saturation |
Chernov.H_MAX |
393222 | Maximum hue (= 6 × E) |
Command-line interface
rgb2hsv [-h] [--version] {convert} ...
Subcommands:
convert Convert a file from RGB→HSV or HSV→RGB
Options for convert:
input Input file (image / CSV / HDF5)
output Output file
--reverse, -r HSV → RGB instead of RGB → HSV
--dataset NAME HDF5 dataset name (default: "data")
Examples
# PNG → HDF5
rgb2hsv convert photo.png photo_hsv.h5
# HDF5 → PNG (round-trip)
rgb2hsv convert --reverse photo_hsv.h5 photo_restored.png
# CSV of RGB rows → CSV of HSV rows
rgb2hsv convert pixels_rgb.csv pixels_hsv.csv
# via python -m
python -m rgb_to_hsv convert photo.png photo_hsv.h5
GUI
rgb2hsv-gui
A simple Tkinter window lets you browse for input/output files, select conversion direction, and run the conversion.
Running tests
pip install -e ".[dev]"
pytest
License
This project is licensed under the GNU General Public License v3 or later (GPLv3+). See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rgb_to_hsv-0.1.0.tar.gz.
File metadata
- Download URL: rgb_to_hsv-0.1.0.tar.gz
- Upload date:
- Size: 50.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58908ee4661421b6e25fe395c49e6826b4e43bac30c2ff592f8b0aac93d27bf5
|
|
| MD5 |
e44dcf43313dc9b42569f4314397b8aa
|
|
| BLAKE2b-256 |
6110f639775a7470674554b74af0d8da4ee6c6ec54784bf3a40d762df5fb1798
|
Provenance
The following attestation bundles were made for rgb_to_hsv-0.1.0.tar.gz:
Publisher:
publish.yml on alencina-faa/RGB-to-HSV
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgb_to_hsv-0.1.0.tar.gz -
Subject digest:
58908ee4661421b6e25fe395c49e6826b4e43bac30c2ff592f8b0aac93d27bf5 - Sigstore transparency entry: 2164425162
- Sigstore integration time:
-
Permalink:
alencina-faa/RGB-to-HSV@85ae1c093b27bb61fd5da1bc555faed79fb5d09a -
Branch / Tag:
refs/tags/v0.1.0a - Owner: https://github.com/alencina-faa
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@85ae1c093b27bb61fd5da1bc555faed79fb5d09a -
Trigger Event:
release
-
Statement type:
File details
Details for the file rgb_to_hsv-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rgb_to_hsv-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78d5155cdec35425d9013a011415960ac62c6a188471541c3c2907778f709dcd
|
|
| MD5 |
1cfd31155f7a9e1b5ff82641c2fe64a0
|
|
| BLAKE2b-256 |
172cbc906016eeb6ed6b75de2049f071627fef176d62a9a51d8874299b6008bd
|
Provenance
The following attestation bundles were made for rgb_to_hsv-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on alencina-faa/RGB-to-HSV
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rgb_to_hsv-0.1.0-py3-none-any.whl -
Subject digest:
78d5155cdec35425d9013a011415960ac62c6a188471541c3c2907778f709dcd - Sigstore transparency entry: 2164425167
- Sigstore integration time:
-
Permalink:
alencina-faa/RGB-to-HSV@85ae1c093b27bb61fd5da1bc555faed79fb5d09a -
Branch / Tag:
refs/tags/v0.1.0a - Owner: https://github.com/alencina-faa
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@85ae1c093b27bb61fd5da1bc555faed79fb5d09a -
Trigger Event:
release
-
Statement type: