Sie sind auf Seite 1von 68

Lecture 2

Color Representation
and Quantization
Yao Wang g
Polytechnic Institute of NYU, Brooklyn, NY 11201

With contributions from Zhu Liu, AT&T Labs


Most figures from Gonzalez/Woods: Digital Image Processing
Lecture Outline
• Color perception and representation
– Human p perception
p of color
– Trichromatic color mixing theory
– Different color representations
• Color
C l iimage di
display
l
– True color image
– Indexed color images
• Pseudo color images
• Quantization Fundamentals
– Uniform, non-uniform, dithering
• Color quantization

Yao Wang, NYU-Poly EL5123: color and quantization 2


Light is part of the EM wave

Yao Wang, NYU-Poly EL5123: color and quantization 3


Illuminating and Reflecting Light
• Illuminating sources (primary light):
– emit light (e.g. the sun, light bulb, TV monitors)
– perceived color depends on the emitted freq.
– follow additive rule
• R+G+B=White
• Reflecting sources (secondary light):
– reflect an incoming light (e.g. the color dye, matte
surface, cloth)
– perceived color depends on reflected freq (=emitted
freq-absorbed freq.)
– follow subtractive rule
• R+G+B=Black

Yao Wang, NYU-Poly EL5123: color and quantization 4


Eye vs. Camera

Camera components Eye components


Lens Lens, cornea
Shutter Iris, pupil
Fil
Film R ti
Retina
Cable to transfer images Optic nerve send the info to
the brain
Yao Wang, NYU-Poly EL5123: color and quantization 5
Human Perception of Color
• Retina contains receptors
– Cones
• Day vision, can perceive color tone
• Red, green, and blue cones
– Rods
• Night vision, perceive brightness only
• Color sensation
– Luminance (brightness)
– Chrominance From
http://www.macula.org/anatomy/
• Hue (color tone) retinaframe.html
• Saturation (color purity)

Yao Wang, NYU-Poly EL5123: color and quantization 6


Frequency Responses of Cones and the
Luminous Efficiency Function

Ci   C ( )ai ( )d , i  r , g , b, y

Yao Wang, NYU-Poly EL5123: color and quantization 7


Tri-chromatic Color Mixing
• Tri-chromatic color mixing theory
– Any color can be obtained by mixing three primary colors with a
right proportion
• Primary colors for illuminating sources:
– Red, Green, Blue (RGB)
– Color monitor works by exciting red, green, blue phosphors
using separate electronic guns
– follow additive rule: R+G+B=White
• Primary colors for reflecting sources (also known as
secondary colors):
– Cyan, Magenta, Yellow (CMY)
– Color printer works by using cyan, magenta, yellow and black
(CMYK) dyes
– follow subtractive rule: R+G+B=Black

Yao Wang, NYU-Poly EL5123: color and quantization 8


RGB vs CMY

Magenta = Red + Blue Magenta = White - Green


Cyan = Blue + Green Cyan = White - Red
Yellow = Green + Red Yellow = White - Blue

Yao Wang, NYU-Poly EL5123: color and quantization 9


Demo with Photoshop
• Show the mixing using RGB, CMY colors
– Using the “window>color”
window>color tool (in “show
show
color”, click on right arrow button to choose
different color sliders) (can also click F6)
– Sample image: RGBadd, CMYsub
• Use the dropper tool, click on different part of the
image, see the color information in “show color”
• Select different color coordinates

Yao Wang, NYU-Poly EL5123: color and quantization 10


A Color Image

Red

Green Blue

Yao Wang, NYU-Poly EL5123: color and quantization 11


Tristimuls Values
• Tristimulus value
– The amounts of red,
red green,
green and blue needed
to form any particular color are called the
tristimulus values, denoted by X, Y, and Z.
– Trichromatic coefficients
X Y Z
x , y , z .
X Y  Z X Y  Z X Y  Z
– Only two chromaticity coefficients are
necessary to specify the chrominance of a
light.
x  y  z 1

Yao Wang, NYU-Poly EL5123: color and quantization 12


CIE Chromaticity Diagram
CIE (Commission
Internationale de
L’Eclairage,
International
Commission on
Illumination ) system
of color specification
x axis: red
y axis: green
e.g.
g GREEN:
x: 25%, y: 62%, z: 13%.

Colors on the boundary:


spectrum colors,
colors highest
saturation

Yao Wang, NYU-Poly EL5123: color and quantization 13


Color Gamut

A line segment indicates all colors that can be produced by mixing two colors corresponding to the end
points of the line.
E h color
Each l modeld lhhas diff
differentt color
l range ((or gamut).
t) RGB model
d lhhas a llarger gamutt th
than CMY
CMY.
Therefore, some color that appears on a screen may not be printable and is replaced by the closest
color in the CMY gamut.

Yao Wang, NYU-Poly EL5123: color and quantization 14


Demo with Photoshop
• Using photoshop to show how to replace a out of
gamut color by its closest in-gamut
in gamut color.
• Choose “window->show color”, choose the
“CMYK slider”
• While having “RGBadd” in display, use
Eyedropper tool to click on “red”, “green” or
“blue”, you will see a warning about out of gamut
color, and the suggested replacement color
• Also open “gamut” image, click on out of gamut
region

Yao Wang, NYU-Poly EL5123: color and quantization 15


Three Attributes of Color
• Luminance (brightness)
• Chrominance
– Hue (color tone) and Saturation (color purity)
• Represented by a “color cone” or “color solid”

Yao Wang, NYU-Poly EL5123: color and quantization 16


Color Models
• Specify three primary or secondary colors
– Red, Green, Blue.
– Cyan, Magenta, Yellow.
• Specify the luminance and chrominance
– HSB or HSI (Hue, saturation, and brightness or
intensity)
– YIQQ (used
( in NTSC color TV))
– YCbCr (used in digital color TV)
• Amplitude specification:
– 8 bits per color component, or 24 bits per pixel
– Total of 16 million colors
– A 1kx1k true RGB color requires 3 MB memory

Yao Wang, NYU-Poly EL5123: color and quantization 17


RGB Color Model

RGB 24-bit color cube

Yao Wang, NYU-Poly EL5123: color and quantization 18


CMY and CMYK Color Models
• Conversion between RGB and CMY (assuming
maximum value is 1)

 C  1  R   R  1  C 
 M   1  G , G   1   M .
         
 Y  1  B   B  1  Y 

• Equal amounts of Cyan, Magenta, and Yellow produce


black. In p
practice, this p
produce muddy-looking
y g black. To
produce true black, a fourth color, black is added, which
is CMYK color model.

Yao Wang, NYU-Poly EL5123: color and quantization 19


HSI Color Model
• Hue represents dominant color as
perceived by an observer
observer. It is an attribute
associated with the dominant wavelength.
• Saturation refers to the relative purity or
the amount of white light mixed with a hue.
The pure spectrum colors are fully
saturated. Pink and lavender are less
saturated.
saturated
• Intensity reflects the brightness.

Yao Wang, NYU-Poly EL5123: color and quantization 20


Conversion Between RGB and HSI
• Converting color from RGB to HSI
 
 
1
( R  G )  ( R  B)
if B  G 1 
 2 
H  with   cos  
360   if B  G
 
1
 ( R  G ) 2  ( R  B)(G  B ) 
 2

3
S  1 [min( R, G, B)]
( R  G  B)
1
I  [ R  G  B]
3

• Converting color from HSI to RGB


RG sector ((0≤H<120)) GB sector (120≤H<240) BR sector (240≤H<360)
B  I (1  S ) R  I (1  S ) G  I (1  S )
 S cos H   S cos( H  120)   S cos( H  240) 
R  I 1  G  I 1   B  I 1  
  cos(60  ( H  120)) 
 cos((60  H )   cos(60  ( H  240)) 
G  1  ( R  B) B  1  (R  G) R  1  (G  B)

Yao Wang, NYU-Poly EL5123: color and quantization 21


YIQ Color Coordinate System
• YIQ is defined by the National Television
System Committee (NTSC)
– Y describes the luminance, I and Q describes
the chrominance
chrominance.
– A more compact representation of the color.
– YUV plays similar role in PAL and SECAM
SECAM.
• Conversion between RGB and YIQ
Y  0.299 0.587 0.114   R   R  1.0 0.956 0.621  Y 
 I   0.596  0.274  0.322 G , G   1.0  0.272  0.649  I 
         
Q   0.211  0.5523
3 0.3311   B   B  1.0  1.106
06 1.703  Q 

Yao Wang, NYU-Poly EL5123: color and quantization 22


YUV/YCbCr Coordinate
• YUV is the color coordinate used in color TV in PAL
system, somewhat different from YIQ.
• YCbCr is the digital equivalent of YUV, used for digital
TV, with 8 bit for each component, in range of 0-255

Yao Wang, NYU-Poly EL5123: color and quantization 23


Demo with Photoshop
• Show the RGB, CMY, HSI models
– Using the “window>show
window>show color”
color tool (in “show
show
color”, click on right arrow button to choose
different color sliders)
– Sample image: RGBadd, CMYsub, fruit
• Use the dropper tool, click on different part of the
image, see the color information in “show color”
• Select different color coordinates

Yao Wang, NYU-Poly EL5123: color and quantization 24


Criteria for Choosing the Color
Coordinates
• The type of representation depends on the
applications at hand
hand.
– For display or printing, choose primary colors
so that more colors can be produced
produced. E E.g.
g
RGB for displaying and CMY for printing.
– For analytical analysis of color differences
differences,
HSI is more suitable.
– For transmission or storage, choose a less
redundant representation, eg. YIQ or YUV or
YCbCr

Yao Wang, NYU-Poly EL5123: color and quantization 25


Comparison of Different Color
Spaces

Yao Wang, NYU-Poly EL5123: color and quantization 26


Pseudo Color Display
• Intensity slicing: Display different gray levels
as different colors
– Can be useful to visualize medical / scientific /
vegetation imagery
• E.g. if one is interested in features with a certain intensity
range or several intensity ranges
• Frequency slicing: Decomposing an image into
different frequency components and represent
them using different colors.

Yao Wang, NYU-Poly EL5123: color and quantization 27


Intensity Slicing

Color

C4

C3

C2

C1

f0 =0 f1 f2 f3 f4 Gray level

Pixels with gray-scale


gray scale (intensity) value in the range of (f i-1 , fi) are rendered with color Ci

Yao Wang, NYU-Poly EL5123: color and quantization 28


Example

Yao Wang, NYU-Poly EL5123: color and quantization 29


Another Example

Yao Wang, NYU-Poly EL5123: color and quantization 30


Pseudo Color Display of Multiple Images
• Display multi-sensor images as a single color
image
– Multi-sensor images: e.g. multi-spectral images by
satellite

Yao Wang, NYU-Poly EL5123: color and quantization 31


An Example

Yao Wang, NYU-Poly EL5123: color and quantization 32


Example

Yao Wang, NYU-Poly EL5123: color and quantization 33


Three Processes in A/D Conversion

Sampling Quanti- Binary


zation Encoding
xc(t) x[n] = xc(nT) x[n] c[n]

Sampling Quantization Binary


P i d
Period I t
Interval
l codebook
T Q

• Sampling: take samples at time nT


– T: sampling period;
– fs = 1/T: sampling frequency
• Quantization: map amplitude values into a set of discrete values
kQ
– Q: quantization interval or stepsize
• Binary
y Encoding
g
– Convert each quantized value into a binary codeword

Yao Wang, NYU-Poly EL5123: color and quantization 34


Analog to Digital Conversion

1
T=0.1
Q=0.25

0.5

-0.5

A2D plot m
A2D_plot.m

-1

0 02
0.2 04
0.4 06
0.6 08
0.8 1

Yao Wang, NYU-Poly EL5123: color and quantization 35


How to determine T and Q?
• T (or fs) depends on the signal frequency range
– A fast varying signal should be sampled more frequently!
– Theoretically governed by the Nyquist sampling theorem
• fs > 2 fm (fm is the maximum signal frequency)
• For speech: fs >= 8 KHz; For music: fs >= 44 KHz;
• Q depends on the dynamic range of the signal
amplitude and perceptual sensitivity
– Q and the signal
g range
g D determine bits/sample
p R
• 2R=D/Q
• For speech and image: R = 8 bits; For music: R =16 bits;
• One can trade off T ((or fs) and Q ((or R))
– lower R -> higher fs; higher R -> lower fs
• We discuss quantization in this lecture. We will
discuss sampling later
later.

Yao Wang, NYU-Poly EL5123: color and quantization 36


A Quantizer
Q(f)
f Quantizer Q(f)
r7
Decision Levels {tk, k = 0, …, L}
r6
Reconstruction Levels {rk, k = 0, …, L-1}
r5
If f  [t k , t k 1 ) r4
Then Q(f) = rk f
t1 t2 t3 t4 t5 t6 t7
L levels need R  log 2 L  bits r3
returns the smallest integer r2
x  that is bigger than or equal to x Quantizer
r1 error
r0
r0 r1 r2 r3 r4 r5 r6 r7
f
t0=-∞ t1 t2 t3 t4 t5 t6 t7 t8=∞

Yao Wang, NYU-Poly EL5123: color and quantization 37


Uniform Quantization
• Equal distances between adjacent decision levels and
between adjacent reconstruction levels
– tl – tl-1 = rl – rl-1 = q
• Parameters of Uniform Quantization
– L: levels (L = 2R)
– B: dynamic range B = fmax – fmin
– q: quantization interval (step size)
– q = B/L = B2-R
• Quantization function

 f  f min  q N t
Note: x 
Q( f )     q   f min
returns the biggest
 q  2
g that is smaller
integer
than or equal to x

Yao Wang, NYU-Poly EL5123: color and quantization 38


Uniform Quantization:
Functional Representation

Q(f)
r7=fmax-q/2

r6

r5

r4
stepsize q=(fmax-fmin)/8
r3

r2

r1
r0=fmin+q/2
f
t0 t1 t2 t3 t4 t5 t6 t7 t8
fmin fmax

Yao Wang, NYU-Poly EL5123: color and quantization 39


Truncated Uniform Quantization
• Signal with infinite dynamic range
• Truncate the lower and higher values to
fmin and fmax
• Parameters
– fmin, fmax
– L (R)
• Quantization function
 f  f mini  q
   q   f min f min  f  f max
 q  2
Q( f )   f min  q / 2 f  f min
 f max  q / 2 f  f max


Yao Wang, NYU-Poly EL5123: color and quantization 40
Truncated Uniform Quantization:
Functional Representation

Q(f) overload
region
r7=fmax-q/2

r6

r5

r4
r3

r2

r1
r0=fmin+q/2
f
t0 =-∞ fmin t1 t2 t3 t4 t5 t6 t7 fmax t8 =∞
overload
region

Yao Wang, NYU-Poly EL5123: color and quantization 41


Example 1 of Uniform Quantizer
• Input signal is continuous
– The output of a Charge-Coupled
Charge Coupled Device
(CCD) camera is in the range of 0.0 to 5.0
volt.
– L = 256
– q = 5.0
5 0 / 256
– The output value in the interval (l * q, (l + 1) *
q] is represented by index l, l = 0, …, 255.
– The reconstruction level rl = l * q + q/2, l =
0,…,
, , 255.

Yao Wang, NYU-Poly EL5123: color and quantization 42


Example 2 of Uniform Quantizer
• Input signal is discrete
– Digital Image of 256 gray levels
– Quantize it into 4 levels
– fmin= 0,
0
– fmax = 256,
– q = 256 / 4 = 6464,
– q/2 = 32,
– Q( f )   f / 64 * 64  32

Yao Wang, NYU-Poly EL5123: color and quantization 43


Uniform Quantization on Images
=256

q=8, L=32
Original, L=
O 16, L=16

4, L=4
q=64
q=1

Yao Wang, NYU-Poly EL5123: color and quantization 44


Quantizer Performance
• Ideally we want to measure the performance by how
close is the quantized image to the original image --
Perceptual Difference
• But it is very hard to come up with an objective measure
that correlates very well with the perceptual quality
• Frequently used objective measure – mean square error
(MSE) between original and quantized samples or signal
to noise ratio (SNR) or Peak SNR (PSNR)

Yao Wang, NYU-Poly EL5123: color and quantization 45


MSE
• Mean square error (MSE) of a quantizer for a continuous
valued signal

MSE   q2  E{(Q( f )  f ) 2 } 
L 1


tL tl 1
 ( f  Q( f )) p ( f )df  ( f  rl ) 2 p ( f )df
2
t0 tl
l 0
– Where
Wh p(f)
(f) is
i the
th probability
b bilit ddensity
it ffunction
ti off f
• MSE for a specific image
N 1 M 1


1
MSE   q2  ( f (i, j )  Q( f (i, j ))) 2
MN i 0 j 0

Yao Wang, NYU-Poly EL5123: color and quantization 46


SNR and PSNR
• Signal to Noise Ratio (SNR)

 2f
SNR (dB )  10 log
 q2
N 1 M 1


1
Signal Variance  Signal Energy   2f  ( f (i, j )  mean) 2
MN i 0 j 0

• P k SNR
Peak
– For the error measure to be
independent of the signal
energy,
gy, use the dynamic
y
range square of the image as
255 2
the signal energy PSNR (dB )  10 log
– For 8 bit image, peak=255  q2

Yao Wang, NYU-Poly EL5123: color and quantization 47


MSE of a Uniform Quantizer for A
Uniform Source
1 /( f max  f min )  1 / B, f  ( f min , f max )
p( f )  
 0, otherwise
B2
 f    df 
f max

2 1
f 
2
f min B 12

Uniform quantization into L levels : q  B / L  B / L


Error in each bin is the same, and is uniformly distributed in (-q/2, q/2)

q/2 2  
B 2
B 2 2R

1 q
 q2  e 2 de   L  2   2f 2  2 R
q / 2 q 12 12 12
 2f
SNR  10 log10  10 log10 2 2 R  20 R log10 2  6 R (dB)
 q2
Every additional
ddi i l bit
bi increases
i the
h SNR by
b 6dB!
d

Yao Wang, NYU-Poly EL5123: color and quantization 48


Example: Nonuniform Source
• The pdf of a signal is shown below, we want to quantize
it to 2 levels. Determine the partition and reconstruction
levels that minimizes the quantization error (in terms of
MSE). Also compute the MSE and SNR.
• Go through in class.
class

p(f)
1/2

Exp(f) Exp(-f)

Yao Wang, NYU-Poly EL5123: color and quantization 49


MMSE Quantizer
• For any pdf, the quantizer that minimizes
MSE is known as Minimal MSE (MMSE)
quantizer.
• For uniform source,
source what is the MMSE
quantizer?

Yao Wang, NYU-Poly EL5123: color and quantization 50


Implementation of Quantization
• Two options
• Option 1:
– At each pixel, calculating quantized value for the
given pixel value
– For
F uniform
if quantization,
ti ti including
i l di one di division
i i andd
rounding, then multiplication
– Must repeat for all pixels
• Option 2:
– Precompute the quantized values for all possible
input values and save in a look
look-up
up table
– Change each pixel based on the look-up table
• Which one is more efficient?

Yao Wang, NYU-Poly EL5123: color and quantization 51


Sample Matlab Code for Option 2
• Setup the quantization function Q(f) for all possible input
level first.
x = imread('lena256_8.bmp');
i d('l 256 8 b ')
• Matlab code [height, width] = size(x);
x=int(x);
B = 256;
% Q isi ththe quantization
ti ti ttablebl
Q = zeros(256, 1);
% Quantized to 64 levels
L = 16;
q = B / L;L
for i = 0:255,
Q(i+1, 1) = floor(i / q) * q + q /2;
end
y = zeros(size(x));
for i = 1:height,
for j = 1:width,
y(i, j) = Q(x(i,j) + 1);
L = 16
16, MSE = 21
21.6
6 end
End
Is there a more efficient implementation? MSE = mean(mean((x-y).^2));
Yao Wang, NYU-Poly EL5123: color and quantization 52
Quantization Effect – False Contour
• 1-D Signal f(t) fˆ (t )

• 2-D Image t t

x=zeros(256,256);
(256 256)
for I =1:256,
for j = 1:256,
x(i,j)=max(i,j)-1;
endd
end
Figure;
imshow(uint(x));

f(i,j)=max(I,j)

Yao Wang, NYU-Poly EL5123: color and quantization 53


Perception Optimized Quantization
• Reduce the artifact of false contour
• Better visual
is al perception (H
(Human
man eeyes
es are
very sensitive to edges)
• MSE might be worse

Yao Wang, NYU-Poly EL5123: color and quantization 54


Pseudo Random Noise Quantizer

f + g Uniform Quantizer ĝ fˆ
+
+ Q() +
Step size: q
+ -

Random Noise Why do we first subtract and


Generator then add back the random
i ? What
noise? Wh t if we skip
ki one off
Uniform in (-q/2, q/2) them?

Yao Wang, NYU-Poly EL5123: color and quantization 55


Example
• Comparison

8 Level Pseudo Random


8 Level Uniform Quantizer Noise
o se Qua
Quantizer
t e
MSE=83.7 MSE=173.45
Which one is better to your eye?
Yao Wang, NYU-Poly EL5123: color and quantization 56
Halftoning
• Halftoning – Representing gray scale image using 2
levels (black and white)
• Used for printing gray scale photographs in B/W
newspaper/fax
• Can be extended to more than two levels
Two Level Quantizer
f + g fˆ
fw
+
+ fb

Why don’t we subtract the added


Dither Signal
dithered signal?
d

Yao Wang, NYU-Poly EL5123: color and quantization 57


Color Quantization
• In low end monitors, the monitor cannot display all
possible colors.
• Select a set of colors, save them in a look-up table (also
known as color map or color palette)
• Any color is quantized to one of the indexed colors
• Only needs to save the index as the image pixel value
and in the display
p y buffer
• Typically: k=8, m=8 (selecting 256 out of 16 million)

Input index (k bits) Red color (m bits) Green color (m bits) Blue color (m bits)

Index 1 … … …

……. … … …

Index 2^k … … …
Yao Wang, NYU-Poly EL5123: color and quantization 58
Web Colors: 216 Safe RGB Colors

These colors are those that can be rendered consistently by different computer systems. They are obtained
by quantizing the R,G,B component independently using uniform quanitization. Each component is
quantized
i d to 6 possible
ibl values:
l 0(0x00),
0(0 00) 51(0
51(0x33),
33) 102(0
102(0x66),
66) 153(0
153(0x99),
99) 204(0
204(0xCC),
CC) 255(0
255(0xFF).
FF)

Yao Wang, NYU-Poly EL5123: color and quantization 59


Uniform vs. Adaptive Quantization
• Uniform (scalar quantization)
– Quantize each color component uniformly
• E.g. 24 bit-> 8 bit can be realized by using 3 bits (8 levels) for
red, 3 bits (8 levels) for green, 2 bits (4 levels) for blue
• Do not pproduce g good result
• Adaptive (vector quantization)
– Treat each color ((a 3-D vector)) as one entity.
y Find the
N colors (vectors) that appear most often in a given
image, save them in the color palette (codebook).
Replace the color at each pixel by the closest
color in the codebook
– The codebook (I.e. color palette) varies from image to
image -> adaptive
Yao Wang, NYU-Poly EL5123: color and quantization 60
Illustration of Vector Quantization
y Codebook size: 25 y

x x

Uniform Quantization Vector Quantization

Yao Wang, NYU-Poly EL5123: color and quantization 61


Example of Color Quantization
24 bits -> 8 bits

Uniform quantization
Adaptive (non-uniform) quantization
(3 bits for R,G, 2 bits for B)
(vector quantization)

Yao Wang, NYU-Poly EL5123: color and quantization 62


Color Dithering
• Color quantization may cause contour effect when the
number of colors is not sufficient
• Dithering: randomly perturb the color values slightly to
break up the contour effect, by applying the dithering
technique for gray scale images to each color
component
– fixed pattern or random noise dithering
– diffusion dithering (the perturbed value of the next pixel depends
on the previous one)

Yao Wang, NYU-Poly EL5123: color and quantization 63


Example of Color Dithering

8 bit uniform 8 bit uniform


without dithering with diffusion dithering

Yao Wang, NYU-Poly EL5123: color and quantization 64


Demo Using Photoshop
• Show quantization results with different methods
using “image->mode->index
image mode index color”
color

Yao Wang, NYU-Poly EL5123: color and quantization 65


Homework
1. Describe how the cones in the retina behind the human eye enable us to perceive color. What
are the different types of cones we have? what colors are they each sensitive to?
2. What color do you see when you project equal amounts of red, green and blue lights on a screen?
What about red and green, and green and blue?
3. What color do you see when you mix equal amounts off cyan, magenta, and yellow? ? What about
cyan and magenta, magenta and yellow? what about mixing red, green, and blue in equal
proportions?
4. Consider the conversion between RGB and YCbCr coordinate. a) Determine the YCbCr
coordinate for a color that is specified in (R,G,B) coordinate with R=100,G=200, B=50. b)
Determine the (R (R,G,B)
G B) coordinate for a color specified in the YCbCr coordinate with
Y=100,Cb=50,Cr=30. Note that if you get R,G,B values that are outside the range of (0,255) you
should clip the values, so that values below 0 become 0, and values above 255 become 255.
5. Suppose you are given a 24 bit color image, with color components red, green, blue each
represented by 8 bits per pixel. Now, we would like to reduce it to an 8 bit image by uniformly
quantizing g the red and g
green components to 3 bits each, and the blue component to 2 bits.
Illustrate the quantizer that you would use for different components. For designing the quantizer,
you should assume the image values are uniformly distributed between 0 and 256 (instead of
255). Suppose a pixel has a color value of (R,G,B)=(200, 150, 40). What is the color after
quantization?
6. Consider a source with a pdf as shown below. If we want to quantize it into L=3 levels, what
should be the decision levels and reconstruction levels? Illustrate the results on the pdf
pdf, and
compute the quantizer MSE and SNR.

p(f)
1

-1 1 f
Yao Wang, NYU-Poly EL5123: color and quantization 66
Computer Assignment
1. Using Matlab or C, to implement uniform quantization of a grayscale image. Your
program should do the following: i) read a grayscale image into an array; ii) quantize
and save the quantized image in a different array; iii) compute the MSE, SNR, and
PSNR between the original
g and qquantized images;
g and iv)) display
p y and p
print the
quantized image. Your program should assume the input values are in the range of
(0,256), but allow you to vary the reconstruction level (L). Record the MSE obtained
with L=64, 32, 16, 8, and print the quantized images with corresponding L values.
Include the program, the image printout and MSE/SNR/PSNR values in your
submission. Comment on the image g q quality
y as yyou vary
y L.
2. Choose a 24 bit color RGB image, quantize the R, G, and B components to 3, 3, and
2 bits, respectively, using a uniform quantizer. Display the original and quantized
color image. Comment on the difference in color accuracy. Make sure you use a
computer that has a 24 bit color display, and the test image has good color contrast.
Note you can apply the uniform quantization function developed for Prob. 1 to each
color component. For this assignment, please include color printout of original and
quantized images. If you don’t have access to color printer, include a disk containing
your image files, or email the files to the grader.
3. Choose a 24 bit RGB color image, convert it to HSI format, and display the HSI
components as separate gray scale images
images. Observe these images to comment on
what does each of the H, S, I components represent. Include printout of the images
and your program and comments in your report. For this assignment, you should not
use the MATLAB built-in function for RGB to HSV conversion. You should write your
own function. The HSV images should be saved in double precision. You can use
imagesc( ) to display these images directly,
directly which automatically scale each image to
a gray scale between 0-255.

Yao Wang, NYU-Poly EL5123: color and quantization 67


Reading
• Gonzalez, “Digital Image Processing”,
Chapter 2 (Section 2.1,
21 2 2.2,
2 22.3,
3 22.4.1
41–
2.4.3), Chap. 6. (Sec. 6.1-6.3), Sec. 8.2
(p602-603 MMSE quantizer)
(p602-603,
• Jain, “Fundamentals of Digital Image
Processing” Chapter 4 (Section 4
Processing”, 4.5
5–
4.11)

Yao Wang, NYU-Poly EL5123: color and quantization 68

Das könnte Ihnen auch gefallen