Skip to main content

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 × 3 arrays).
  • Flexible I/O — read/write JPEG, PNG, TIFF, BMP, WebP (via Pillow), CSV / TXT (via NumPy), and HDF5 (via h5py).
  • Command-line interfacergb2hsv convert input.png output.h5
  • Tkinter GUIrgb2hsv-gui
  • python -m rgb_to_hsv shorthand.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rgb_to_hsv-0.1.0.tar.gz (50.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rgb_to_hsv-0.1.0-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

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

Hashes for rgb_to_hsv-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58908ee4661421b6e25fe395c49e6826b4e43bac30c2ff592f8b0aac93d27bf5
MD5 e44dcf43313dc9b42569f4314397b8aa
BLAKE2b-256 6110f639775a7470674554b74af0d8da4ee6c6ec54784bf3a40d762df5fb1798

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for rgb_to_hsv-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78d5155cdec35425d9013a011415960ac62c6a188471541c3c2907778f709dcd
MD5 1cfd31155f7a9e1b5ff82641c2fe64a0
BLAKE2b-256 172cbc906016eeb6ed6b75de2049f071627fef176d62a9a51d8874299b6008bd

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page