Simple python demos of Color Histogram.
This package includes:
- 1D color histogram: Hist1D class in
color_histogram/core/hist_1d.py
. - 2D color histogram: Hist2D class in
color_histogram/core/hist_2d.py
. - 3D color histogram: Hist3D class in
color_histogram/core/hist_3d.py
.
Histogram 1D plotting in 1 channel from RGB, Lab, HSV color spaces.
from color_histogram.io_util.image import loadRGB
from color_histogram.core.hist_1d import Hist1D
import matplotlib.pyplot as plt
# Load image.
image = loadRGB(image_file)
# 16 bins, Lab color space, target channel L ('Lab'[0])
hist1D = Hist1D(image, num_bins=16, color_space='Lab', channel=0)
fig = plt.figure()
ax = fig.add_subplot(111)
hist1D.plot(ax)
plt.show()
In the following demo, I show the L (Lab), h (HSV), v (HSV) plots by changing color_space
and channel
.
Histogram 2D plotting in 2 channels from RGB, Lab, HSV color spaces.
from color_histogram.io_util.image import loadRGB
from color_histogram.core.hist_2d import Hist2D
import matplotlib.pyplot as plt
# Load image.
image = loadRGB(image_file)
# 32 bins, hsv color space, target channels (h, s) ('hsv'[0], 'hsv'[1])
hist2D = Hist2D(image, num_bins=32, color_space='hsv', channels=[0, 1])
fig = plt.figure()
ax = fig.add_subplot(111)
hist2D.plot(ax)
plt.show()
In the following demo, I show the (h, s), (h, v), (s, v) plots by changing channels
.
Histogram 3D plotting in RGB, Lab, HSV color spaces.
from color_histogram.io_util.image import loadRGB
from color_histogram.core.hist_3d import Hist3D
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Load image.
image = loadRGB(image_file)
# 16 bins, rgb color space
hist3D = Hist3D(image, num_bins=16, color_space='rgb')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
hist3D.plot(ax)
plt.show()
In the following demo, I show the RGB, Lab, HSV plots by changing color_space
.
Note: This program was only tested on Windows with Python2.7. Linux and Mac OS are not officially supported, but the following instructions might be helpful for installing on those environments.
Please install the following required python modules.
- NumPy
- SciPy
- matplotlib
- OpenCV
As these modules are heavily dependent on NumPy modules, please install appropriate packages for your development environment (Python versions, 32-bit or 64-bit). For 64-bit Windows, you can download the binaries from Unofficial Windows Binaries for Python Extension Packages.
You can use pip command for installing main modules. Please run the following command from the shell.
> pip install git+https://github.com/tody411/ColorHistogram.git
You can test the color histogram demo with the following command from color_histogram
directory.
> python main.py
This command will start downloading test images via Google Image API then run the demo module to generate result images in color_histogram/results
directory.
color_histogram/examples
: You can find minimal example codes.color_histogram/results
: You can also find examples codes to generate result images.
The MIT License 2015 (c) tody