Beruflich Dokumente
Kultur Dokumente
Color Representation
and Quantization
Yao Wang g
Polytechnic Institute of NYU, Brooklyn, NY 11201
Ci C ( )ai ( )d , i r , g , b, y
Red
Green Blue
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.
C 1 R R 1 C
M 1 G , G 1 M .
Y 1 B B 1 Y
Color
C4
C3
C2
C1
f0 =0 f1 f2 f3 f4 Gray level
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
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
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
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
q=8, L=32
Original, L=
O 16, L=16
4, L=4
q=64
q=1
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
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
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
p(f)
1/2
Exp(f) Exp(-f)
• 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)
f + g Uniform Quantizer ĝ fˆ
+
+ Q() +
Step size: q
+ -
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)
x x
Uniform quantization
Adaptive (non-uniform) quantization
(3 bits for R,G, 2 bits for B)
(vector quantization)
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.