Color Channels
Color Channels is a simple, command-line program that can
- separate a color image into multiple grayscale images, each representing a single color channel, and
- combine multiple grayscale images, each representing a single color channel, into a unified color image.
Features
Color Channels supports the following color spaces:
An alpha (opacity) channel is supported for all of the above.
The user can specify an explicit white point for HCL, L*a*b*, and L*u*v* conversions.
The program accepts images provided in PNG, JPEG, GIF, or any of the Netpbm formats.
Unrepresentable colors are clamped gracefully to representable colors.
Installation
Color Channels is written in the Go programming language so you will need to install Go to compile it.
Once Go is installed, Color Channels can be downloaded, built, and installed into $GOPATH/bin/
simply by running
go install github.com/spakin/color-channels@latest
An alternative install location can be specified by first setting the GOBIN
environment variable (e.g., export GOBIN=/usr/local/bin
).
Usage
Basic operation
Run color-channels --help
for a usage summary. In short, one of --split
or --merge
must be specified. For example,
color-channels --split --space=HCL -o channel-%s.png input-image.jpg
reads input-image.jpg
and generates channel-H.png
, representing the hue channel, channel-C.png
, representing the chroma channel, and channel-L.png
, representing the luminance channel. Output images always are written in PNG regardless of the input-image's format.
The channel images from the preceding command can be recombined (typically after transforming them in some manner) using --merge
:
color-channels --merge --space=HCL -o output-image.png channel-H.png channel-C.png channel-L.png
A more concrete example
Here's a sample image, courtesy of https://file-examples.com/:
We can split the above into luma (gamma-corrected luminance), blue-difference, and red-difference channels with
color-channels --split --space="Y'CbCr" -o channel-%s.png example.jpg
Let's swap the blue-difference and red-difference channels when recombining the above to see what happens:
color-channels --merge --space="Y'CbCr" -o output-image.png channel-Y.png channel-Cr.png channel-Cb.png
Color spaces
The --space
option allows color-space names to include arbitrary punctuation and capitalization. That is, --space="L*a*b*"
and --space=lab
are treated identically.
Appending an A
to any color-space name includes an alpha channel (named alpha
on output).
Advanced usage
As a more advanced example, a white point can be specified via its x and y chromaticity coordinates. color-channels
currently honors the white point for only a few color spaces, though. The default white point is D65. As an example, the F2 standard illuminant (cool white fluorescent) with a 2° standard observer can be requested with --white="0.37208 0.37529"
.
Author
Scott Pakin, scott+clrch@pakin.org