Skip to content

tody411/PaletteSelection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automatic Color Palette Selection (Python)

Simple python demos of Automatic Color Palette Selection [Chang et al. 2015].

They proposed palette-based photo recoloring method for image editing.

I will implement automatic color palette selection part for single and multi-images.

This package includes:

Examples

Palette Selection for Single Image:

Minimal example:

from palette.io_util.image import loadRGB
from palette.core.hist_3d import Hist3D
from palette.core.palette_selection import PaletteSelection
import matplotlib.pyplot as plt

# Load image.
image = loadRGB(image_file)

# 16 bins, Lab color space
hist3D = Hist3D(image, num_bins=16, color_space='Lab')

color_coordinates = hist3D.colorCoordinates()
color_densities = hist3D.colorDensities()
rgb_colors = hist3D.rgbColors()

# 5 colors from Lab color samples.
palette_selection = PaletteSelection(color_coordinates,
                                             color_densities, rgb_colors,
                                             num_colors=5, sigma=70.0)

fig = plt.figure()

# Plot image.
fig.add_subplot(131)
plt.imshow(image)
plt.axis('off')

# Plot palette colors.
fig.add_subplot(132)
palette_selection.plot(plt)
plt.axis('off')

# Plot 3D color histogram.
ax = fig.add_subplot(133, projection='3d')
hist3D.plot(ax)

plt.show()

In the following demo, I compare the palette selection results by changing color_space.

Demo for single image

Palette Selection for Multi-Images:

In the following demo, I test the palette selection for multi-images.

Demo for multi-images

Installation

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.

Dependencies

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.

Install main modules

You can use pip command for installing main modules. Please run the following command from the shell.

  > pip install git+https://github.com/tody411/PaletteSelection.git

Usage

Run Palette Selection Demo

You can test the Palette Selection with the following command from palette directory.

  > python main.py

This command will start downloading test images via Google Image API then run the demo module to generate result images.

Examples Codes

License

The MIT License 2015 (c) tody

About

Automatic Color Palette Selection (Python)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages