INTRODUCTION TO IMAGE PROCESSING
LECTURE 5
Color Image Processing
Color characteristics
Colors are distinguished from one another based on brightness, hue, and saturation.
Brightness: the amount of intensity
Hue: an attribute associated with the dominant wavelength in a mixture of light
waves. It represents the dominant color as perceived by an observer. (red, orange,
yellow, etc.)
Saturation: specifies relative purity or the amount of white lights mixed with a hue.
(pink less saturated than red : red and white) (lavender less saturated than violet :
white and violet)
Hue and saturation together are called chromaticity.
Color characteristics
Color characteristics
Color vision
• CONES are active at higher light levels (photopic vision).
• They are capable of color vision.
• They provide high spatial resolution (perception of fine details).
• There are three types of color-sensitive cones, corresponding roughly to red,
green, and blue sensitive detectors.
L-cones, 65% of the cones. Response peaking at about
560 nm.
M-cones, 33% of thecones. Response peaking at about
530 nm.
S-cones, 2% of the cones. Response peaking at about
420 nm.
The signals received from the three cone types are
combined and interpreted by the brain for perception of
Normalized response spectra of human cones, a continuous range of colors
to monochromatic spectral stimuli
Primary Colors
• The colors are seen as variable combinations of the responses of the cone types
(concentrated around red, green and blue bands)
• CIE (Commission Internationale de l’Eclariage) designated the following primary
colors:
– Red: 700 nm
– Green: 546.1 nm
– Blue: 435.8 nm
Color matching experiment
Target color
versus
Three primary lights with knobs
(adjustable intensity)
The observer matches the target
color by adjusting the intensities of
Red, Green and Blue lights.
.
CIE 1931 XYZ color system -Tristimulus values
The amounts of red, green and blue needed to form any particular color are called
the tristimulus values and are denoted by X, Y, and Z, respectively.
(Measured through color experiments)
A color is defined by its trichromatic coefficients:
X
x=
X +Y + Z
Y
y=
X +Y + Z
Z
z=
X +Y + Z
The CIE XYZ color space covers all colors that are perceivable to humans.
CIE XYZ (Tristimulus values) is a device-invariant representation of color.
The CIE Chromacity Diagram
Show color composition as a function of 𝑥 and 𝑦.
Adjust 𝑧 such that 𝑧 = 1 − 𝑥 − 𝑦
Maximally saturated bright colors
Color gamut
The color gamut of a device defines the range of colors that can be represented,
produced or displayed.
A monitor, which combines RGB lights, has a greater color gamut than a printer,
which uses CMYK (cyan, magental, yellow, black) inks.
The gray region shape is the entire range of
possible chromaticities represented in the
CIE 1931 chromaticity diagram.
The colored triangle is the gamut of the
sRGB color space typically used in computer
monitors.
The monitors cannot produce all visible
colors to the human eye.
Color gamut
The color gamut of a device defines the range of colors that can be represented,
produced or displayed.
A monitor, which combines RGB lights, has a greater color gamut than a printer,
which uses CMYK (cyan, magental, yellow, black) inks.
Printing devices has lower color gamut
than computer monitors.
The printed images will look different from
the images seen in the monitor.
Color Models
Color models provide a systematic way to specify colors.
We define a 3D coordinate system that contains all constructable colors.
A distinct color in this model will correspond to a single point in the 3D
coordinate system.
• RGB (red, green, blue) color model: monitor, video
• CMY (cyan, magenta, yellow) color model: printing
• CMYK (cyan, magenta, yellow, black) color model: printing
• HSI (hue, saturation, intensity) color model: Corresponds closely with
the way humans describe and interpret color.
• HSV (hue, saturation, value) color model
• HSL (hue, saturation, lightness) color model
RGB Model
RGB Model
We can view RGB images as a 2D array of pixels where each pixel gets a 3D vector
representing the Red, Green and Blue channels corresponding to the color of that pixel.
RGB Model
We can also view RGB images as three component images, one for each primary color.
• HSI (hue, saturation, intensity) color model
• HSV (hue, saturation, value) color model
• HSL (hue, saturation, lightness) color model
The HS* color spaces are simple geometric
transformations of the RGB cube into cylindrical form.
In each cylinder:
• the angle around the central vertical axis
corresponds to “hue”,
• the distance from the axis corresponds to
“saturation”,
• the distance along the axis corresponds to
“lightness (value)” or “brightness ”
HSI Model
First scale the RGB components to the range [0,1] (Divide by L-1.)
HSL and HSV Models
First scale the RGB components to the range [0,1] (Divide by L-1.)
Hue component for the two models:
The hue h ∈[ 0,1] corresponds to an angle h⋅2π in radians.
In the special cases of full saturation
h = 0 for red, h= 2/6 for green, and h = 4/6 for blue
HSL and HSV Models
First scale the RGB components to the range [0,1] (Divide by L-1.)
The lightness l and saturation s for HSL:
HSL and HSV Models
First scale the RGB components to the range [0,1] (Divide by L-1.)
The value v and saturation s for HSV:
HSV Model
Image with constant saturation and value, S = 1, V = 1
Hue: 0 1
Image with constant hue and value, H = 0.6, V = 1
Saturation: 0 1
HSV Model
Image with constant hue and saturation, H = 0.6 , S = 1
Value: 0 1
Color Image Processing
Full color image processing.
Two approaches:
1) Process each component image individually
2) Work with color pixels directly
Let c represent an arbitrary vector in RGB color space:
cR R
c = cG = G
cB B
At coordinates (x, y ),
cR ( x , y ) R ( x , y )
c( x, y ) = cG ( x, y ) = G ( x, y )
cB ( x, y ) B( x, y )
Color Transformation
Two approaches:
1) Apply a transformation to a component independent from the other (Red,
Blue or Green channels)
2) Apply a transformation that takes a vector as an input and returns another
vector.
si = Ti (r1 , r2 ,..., rn ), i = 1, 2,..., n.
- The two approaches become the same if 𝑇𝑖 only depends on 𝑟𝑖 .
Color Transformation
Example: Gamma transformation
Apply gamma transformation independently to Red, Blue and Green component images.
Red component image Green component image Blue component image
Combine the transformed components to get the output color image.
Spatial Filtering of Color Images
Two approaches:
1) Apply a 2D filter to a component independent from the other (Red, Blue or
Green channels) or (Intensity channel in the HSV or HSI space)
2) Apply a 3D filter that takes into account all the component values in the
neighborhood. For example, apply a 5x5x3 filter to the 3D color vectors in
the 5x5 neighborhood of a pixel.
Spatial Filtering of Color Images
Example: Average Filtering
Apply average filtering independently to Red, Blue and Green component images.
Combine the filtered component images to get the output color image.
Histogram equalization of Color Images
Histogram equalization: Determine the transformation to produce an image with a
uniform histogram of intensity values
For color images, it is unwise to apply histogram equalizaion independently to red, green
and blue component images. The result of doing so is erronous color.
Original image Result of applying histogram equalization separately to red,
green and blue component images. Colors are not correct.
Histogram equalization of Color Images
Instead, apply histogram equalization to the «intensity» component only, leaving the
chromatic components unchanged.
Obtain Hue, Saturation and Intensity components. Apply histogram equalization only to
the Intensity component.
Original image Result of applying histogram equalization only to the value
component in the HSV color model.
MATLAB SESSION
A = imread(‘colors.jpg');
% RGB components
A_r = A(:,:,1);
A_g = A(:,:,2);
A_b = A(:,:,3);
figure(1);
subplot(2,2,1);
imshow(A);
title('RGB image');
subplot(2,2,2);
imshow(A_r);
title('Red channel');
subplot(2,2,3);
imshow(A_g);
title('Green channel');
subplot(2,2,4);
imshow(A_b);
title('Blue channel');
A = imread('balloons.tif’);
% Convert to HSV color space
A_hsv = rgb2hsv(A);
A_h = A_hsv(:,:,1);
A_s = A_hsv(:,:,2);
A_v = A_hsv(:,:,3);
figure(1);
subplot(2,2,1);
imshow(A);
title('Original image');
subplot(2,2,2);
imshow(A_h);
title('Hue');
subplot(2,2,3);
imshow(A_s);
title('Saturation');
subplot(2,2,4);
imshow(A_v);
title('Value');
A = imread('tiger.jpeg');
figure(1)
imshow(A);
A_hsv = rgb2hsv(A);
A_s = A_hsv(:,:,2);
A_sn = A_s+0.3;
% Clip the values greater than 1
A_sn(A_sn>1) = 1;
A_hsv_new = A_hsv;
A_hsv_new(:,:,2) = A_sn;
A_new = hsv2rgb(A_hsv_new);
figure(2)
imshow(A_new);
% Gamma transformation
A = imread('tiger.jpeg');
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
figure(1);
imshow(A);
% gamma = 2
R_out = imadjust(R,[],[],2);
G_out = imadjust(G,[],[],2);
B_out = imadjust(B,[],[],2);
A_out = cat(3,R_out,G_out,B_out);
figure(2);
imshow(A_out);
% Gamma transformation to the
% value component only
% in the HSV space
A = imread('tiger.jpeg');
figure(1);
imshow(A);
A_hsv = rgb2hsv(A);
A_hsv_new = A_hsv;
A_h = A_hsv(:,:,3);
% gamma = 2
A_h_new = imadjust(A_h,[],[],2);
A_hsv_new(:,:,3) = A_h_new;
A_new = hsv2rgb(A_hsv_new);
figure(2);
imshow(A_new);
% Average filtering
A = imread('brain_398.tif');
figure(1); imshow(A);
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
mask_a = (1/(25*25))*ones(25);
R_a = imfilter(R,mask_a);
G_a = imfilter(G,mask_a);
B_a = imfilter(B,mask_a);
A_out = cat(3,R_a,G_a,B_a);
figure(2); imshow(A_out);
%%%% Histogram equalization
A = imread('balloons.tif');
figure(1);
imshow(A);
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
A_HSV = rgb2hsv(A);
V = A_HSV(:,:,3);
V_h = histeq(V);
A_HSV_n = A_HSV;
A_HSV(:,:,3) = V_h;
A_out = hsv2rgb(A_HSV);
figure(2)
imshow(A_out);