Introduction to Image Processing — Color Spaces
Python is a fun programming language for exploring around with color spaces in images. I hope this story will give you some ideas on the basic types of color spaces. In this story, we will use Yuyuko as our sample.
Let’s get started first with some important libraries in Python.
import numpy as np
import matplotlib.pyplot as plt
from skimage import img_as_uint
from skimage.color import rgb2hsv
from skimage.io import imshow, imread
from skimage.color import rgb2gray
from skimage.color import rgb2lab
- RGB Model
The RGB Model is a color model that can produce various colors by “additive” combinations of the primary colors, red, green, and blue. The more you add colors, the lighter the color you get. This color mixing is used in everyday devices such as TV, camera, and phones. We can represent the image above as a combination of the RGB space model.
yuyuko = imread(“yuyuko.png”)fig, ax = plt.subplots(1, 3, figsize=(12,4))
ax[0].imshow(yuyuko[:,:,0], cmap=’Reds’)
ax[0].set_title(‘Red’)
ax[1].imshow(yuyuko[:,:,1], cmap=’Greens’)
ax[1].set_title(‘Green’)
ax[2].imshow(yuyuko[:,:,2], cmap=’Blues’)
ax[2].set_title(‘Blue’);
What I noticed at a glance about this is her blue ribbon. It was visible on the blue image, but not on the red and green images. The white background color on the original image is an equal combination of the three primary colors.
2. HSV Color Model
The HSV (Hue, Saturation, Value) model is conceptualized based on human vision. The hue represents the base pigment, the saturation represents the intensity of the color, and the value represents the brightness.
yuyuko_hsv = rgb2hsv(yuyuko)
fig, ax = plt.subplots(1, 4, figsize=(16,4))
ax[0].imshow(yuyuko_hsv[:,:,0], cmap=’hsv’)
ax[0].set_title(‘Hue’)
ax[0].axis(“off”)
ax[1].imshow(yuyuko_hsv[:,:,1], cmap=’gray’)
ax[1].set_title(‘Saturation’)
ax[1].axis(“off”)
ax[2].imshow(yuyuko_hsv[:,:,2], cmap=’gray’)
ax[2].set_title(‘Value’);
ax[2].axis(“off”)
ax[3].imshow(yuyuko)
ax[3].set_title(‘Original’)
ax[3].axis(“off”)
From this image, the background has a red hue, low saturation(black), and bright value. This combination produced a pure white background. The ribbon has a blue hue, a high value of saturation(white), and a somewhat dark value. This combination produced a deep blue ribbon.
3. CIEL*a*b* Color Space
The CIELAB model represents color based on three values: the perceptual luminosity(L*), color range from green to red (a*), and color range from blue to yellow (b*)
yuyuko_lab = rgb2lab(yuyuko)
fig, ax = plt.subplots(1, 4, figsize=(16,4))
ax[0].imshow(yuyuko_lab[:,:,0], cmap=’gray’)
ax[0].set_title(‘L*’)
ax[0].axis(“off”)
ax[1].imshow(yuyuko_lab[:,:,1], cmap=’RdYlGn_r’)
ax[1].set_title(‘a*’)
ax[1].axis(“off”)
ax[2].imshow(yuyuko_lab[:,:,2], cmap=’YlGnBu_r’)
ax[2].set_title(‘b*’);
ax[2].axis(“off”)
ax[3].imshow(yuyuko)
ax[3].set_title(‘Original’)
ax[3].axis(“off”)
Other Colors Space
Some types of color space are the YUV and the CMYK. The CMYK model (Cyan, Magenta, Yellow, Key) uses color subtraction in creating colors and usually applied to printers. The YUV is a color encoding system that is usually used on analog televisions. [1]
References:
[1]Zimet, L. (2002). Digital Processing of Analog Television. Department of Electrical Engineering, Stanford University