EECE\CS 253 Image Processing
Lecture Notes: Pixelization and Quantization Lecture Notes
Richard Alan Peters II
Department of Electrical Engineering and Computer Science
Fall Semester 2011
This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
Pixelization
is a special effect often used to hide identities
19 October 2011 1999-2011 by Richard Alan Peters II 2
Pixelization
or to clean up an image.
19 October 2011 1999-2011 by Richard Alan Peters II 3
Pixelization and Quantization
high-res image
pixelated
quantized
pixelated & quantized
19 October 2011
1999-2011 by Richard Alan Peters II
Pixelization and Quantization
pixel grid
column index
row index
high-res image
pixelated
quantized
pixelated & quantized
19 October 2011
1999-2011 by Richard Alan Peters II
Pixelization
Take the average within each square.
I ( r , c)
high-res image
I P (r , c)
1 (r+1)D-1 (c+1)D-1 I DS (r , c) = 2 I (r , c); I P = I DS D D r=rD c=cD (upsampled)
1999-2011 by Richard Alan Peters II
pixelated image
19 October 2011
Pixelization
Take the average within each square.
I ( r , c)
high-res image
I P (r , c)
1 (r+1)D-1 (c+1)D-1 I DS (r , c) = 2 I (r , c); I P = I DS D D r=rD c=cD (upsampled)
1999-2011 by Richard Alan Peters II
pixelated image
19 October 2011
Pixelization
Take the average within each square.
I ( r , c)
high-res image
I P (r , c)
1 (r+1)D-1 (c+1)D-1 I DS (r , c) = 2 I (r , c); I P = I DS D D r=rD c=cD (upsampled)
1999-2011 by Richard Alan Peters II
pixelated image
19 October 2011
Pixelization
Take the average within each square.
I ( r , c)
high-res image
I P (r , c)
1 (r+1)D-1 (c+1)D-1 I DS (r , c) = 2 I (r , c); I P = I DS D D r=rD c=cD (upsampled)
1999-2011 by Richard Alan Peters II
pixelated image
19 October 2011
Pixelization Procedure (Part 1)
To pixelize an RCB image I by a factor, s: Let IDS be an R/s C/s B image. Let the value of IDS at location (r,c,b) be the average value of I in the s-square neighborhood starting at (rs,cs,b).
I DS (r , c, b) = mean { I ( r , c, b) } ,
(r ,c) NI (r ,c)
where
{rs, rs + 1, , (r + 1) s 1}, NI (r , c ) = ( , ) . { ( ) } cs, cs + 1, , c + 1 s 1 Notation: r & c are indices in the downsampled image. IDS = I s
rs & cs are indices in the original image.
IDS is I downsampled by a factor of s.
19 October 2011 1999-2011 by Richard Alan Peters II
10
Pixelization Procedure (Part 2)
Let IP be an RCB image. Let the value of IP in neighborhood, N(r,c) be IDS(r,c).
I P ( r , c, b) = I DS (r , c, b) for (r , c) NI P (r , c).
where
r {rs, rs + 1, , (r + 1) s -1} , NI P ( r , c ) = ( r , c ) . c {cs, cs + 1, , (c + 1) s -1} Notation:
IP = IDS s IP is IDS upsampled by a factor of s.
19 October 2011
r & c are indices in the downsampled image. rs & cs are indices in the upsampled image.
1999-2011 by Richard Alan Peters II
11
Pixelization
8 of 8: 256x256
19 October 2011
1999-2011 by Richard Alan Peters II
12
Pixelization
7 of 8: 128x128
19 October 2011
1999-2011 by Richard Alan Peters II
13
Pixelization
6 of 8: 64x64
19 October 2011
1999-2011 by Richard Alan Peters II
14
Pixelization
5 of 8: 32x32
19 October 2011
1999-2011 by Richard Alan Peters II
15
Pixelization
4 of 8: 16x16
19 October 2011
1999-2011 by Richard Alan Peters II
16
Pixelization
3 of 8: 8x8
19 October 2011
1999-2011 by Richard Alan Peters II
17
Pixelization
2 of 8: 4x4
19 October 2011
1999-2011 by Richard Alan Peters II
18
Pixelization
1 of 8: 2x2
19 October 2011
1999-2011 by Richard Alan Peters II
19
Pixelization
original image
19 October 2011
1999-2011 by Richard Alan Peters II
20
Pixelization by Factor 32
Cross-fade 1/5
19 October 2011
1999-2011 by Richard Alan Peters II
21
Pixelization by Factor 32
Cross-fade 2/5
19 October 2011
1999-2011 by Richard Alan Peters II
22
Pixelization by Factor 32
Cross-fade 3/5
19 October 2011
1999-2011 by Richard Alan Peters II
23
Pixelization by Factor 32
Cross-fade 4/5
19 October 2011
1999-2011 by Richard Alan Peters II
24
Pixelization by Factor 32
Cross-fade 5/5
19 October 2011
1999-2011 by Richard Alan Peters II
25
Pixelization by Factor 32
original image
19 October 2011
1999-2011 by Richard Alan Peters II
26
Quantization
16 million colors
19 October 2011
16 colors
1999-2011 by Richard Alan Peters II
27
Quantization
8 bits 256 levels
7 bits 128 levels
6 bits 64 levels
5 bits 32 levels
4 bits 16 levels
19 October 2011
3 bits 8 levels
2 bits 4 levels
1 bit 2 levels
28
1999-2011 by Richard Alan Peters II
Intensity Quantization
19 October 2011
1999-2011 by Richard Alan Peters II
29
Intensity Quantization
Usually with 2-bit quantization, the output intensities are mapped to {0,85,170,255}, and with with 1-bit quantization, the output intensities are taken to be {0,255}.
19 October 2011
1999-2011 by Richard Alan Peters II
30
Enhancement of an 8-bit image
a. original
19 October 2011
b. contrast enh.
b. dark enhanced
b. bright enh.
31
1999-2011 by Richard Alan Peters II
Enhancement of a 16-bit image
a. original
19 October 2011
b. contrast enh.
b. dark enhanced
b. bright enh.
32
1999-2011 by Richard Alan Peters II
Effect of Quantization on Equalization
d. bright enh.
d. bright enh.
c. dark enh.
c. dark enh.
b. contrast enh.
b. contrast enh.
a. original
a. original
19 October 2011
1999-2011 by Richard Alan Peters II
33
Effect of Quantization on Equalization
19 October 2011
1999-2011 by Richard Alan Peters II
34
Effect of Quantization on Equalization
enhanced 8-bit
19 October 2011
enhanced 16-bit
35
1999-2011 by Richard Alan Peters II
Effect of Quantization on Equalization
enhanced 16-bit
19 October 2011
enhanced 8-bit
36
1999-2011 by Richard Alan Peters II
Effect of Quantization on Equalization
16-bit enhanced
8-bit enhanced
original
19 October 2011
1999-2011 by Richard Alan Peters II
37
Whats in the lower eight bits?
19 October 2011
1999-2011 by Richard Alan Peters II
38
8-bit-per-band, 3-band, original image
Application of Quantization: Steganography
Pieter Bruegel (the Elder, ca. 1525-69), The Peasant Dance, 1568, Oil on oak panel, 114x164 cm, Kunsthistorisches Museum Wien, Vienna
If an image is quantized, say from 8 bits to 6 bits and redisplayed it can be all but impossible to tell the difference visually between the two.
19 October 2011 1999-2011 by Richard Alan Peters II 39
6-bit-per-band, 3-band, quantized image
Application of Quantization: Steganography
Pieter Bruegel (the Elder, ca. 1525-69), The Peasant Dance, 1568, Oil on oak panel, 114x164 cm, Kunsthistorisches Museum Wien, Vienna
If an image is quantized, say from 8 bits to 6 bits and redisplayed it can be all but impossible to tell the difference visually between the two.
19 October 2011 1999-2011 by Richard Alan Peters II 40
Application of Quantization: Steganography
green-band histogram of 8-bit image green-band histogram of 6-bit image
With simple image analysis, it is easy to tell the difference: The histograms of the two versions indicate which is which. If the 6-bit version is displayed as an 8-bit image it has only pixels with values 0, 4, 8, , 252.
19 October 2011 1999-2011 by Richard Alan Peters II 41
Application of Quantization: Steganography
If the 6-bit version is displayed as an 8-bit image then the 8-bit pixels all have zeros in the lower 2 bits:
b b b b b b 0 0
That other information could be a message, perhaps encrypted, or even another image.
Image 1 R-Shift 2 L-Shift 2
logical
OR
Image 2 R-Shift 6
b = 0 or 1
always 0
This introduces the possibility of encoding other information in the low-order bits.
19 October 2011
Image Out
X-Shift n = logical left or right shift by n bits. 42
1999-2011 by Richard Alan Peters II
Image 1 in upper 6-bits. Image 2 in lower 2-bits.
Application of Quantization: Steganography
Pieter Bruegel (the Elder, ca. 1525-69), The Peasant Dance, 1568, Oil on oak panel, 114x164 cm, Kunsthistorisches Museum Wien, Vienna
The second image is invisible because the value of each pixel is between 0 and 3. For any given pixel, its value is added to the to the collocated pixel in the first image that has a value from the set {0, 4, 8, , 252}. The 2nd image is noise on the 1st.
19 October 2011 1999-2011 by Richard Alan Peters II 43
Image 1 in upper 6-bits. Image 2 in lower 2-bits.
Application of Quantization: Steganography
Pieter Bruegel (the Elder, ca. 1525-69), The Peasant Dance, 1568, Oil on oak panel, 114x164 cm, Kunsthistorisches Museum Wien, Vienna
L-Shift 6
?
To recover the second image (which is 2 bits per pixel per band) simply left shift the combined image by 6 bits.
19 October 2011 1999-2011 by Richard Alan Peters II
44
Image 2 in upper 2-bits. Image 1 shifted out
Application of Quantization: Steganography
From the video game, ZeroWing, by Toaplan. See http://en.wikipedia.org/wiki/All_your_base
image
L-Shift 6
To recover the second image (which is 2 bits per pixel per band) simply left shift the combined image by 6 bits.
19 October 2011 1999-2011 by Richard Alan Peters II 45
Application of Quantization: Steganography
This is so effective that two 4-bit-per-pixel images can be superimposed with only the image in the high-order bits visible. Both images contain the same amount of information but because one takes on values between 0 and 15, the other takes on values from {16, 32, 48, , 240}, and the smaller values are added to the larger, the image in the low-order bits is effectively invisible
Images 1 and 2 each have 4-bits per pixel when combined.
Image 1 R-Shift 4 L-Shift 4
Image 2 R-Shift 4
Image Out
19 October 2011
1999-2011 by Richard Alan Peters II
46
Original Image
Application of Quantization: Steganography
Photo: CypherOne http://www.flickr.com/people/cypherone/
19 October 2011
1999-2011 by Richard Alan Peters II
47
Image quantized to 4-bits per pixel.
Application of Quantization: Steganography
Photo: CypherOne http://www.flickr.com/people/cypherone/
19 October 2011
1999-2011 by Richard Alan Peters II
48
Image 1 in upper 4-bits. Image 2 in lower 4-bits.
Application of Quantization: Steganography
Photo: CypherOne http://www.flickr.com/people/cypherone/
19 October 2011
1999-2011 by Richard Alan Peters II
49
Image 2 in upper 4-bits. Image 1 shifted out.
Application of Quantization: Steganography
Phototographer Unknown
19 October 2011
1999-2011 by Richard Alan Peters II
50
Separate EQ of Dark and Light Regions in 16-bit Images
original 16-bit image
19 October 2011
contr. stretched dark reg.
1999-2011 by Richard Alan Peters II
contr. stretched light reg.
51
Separate EQ of Dark and Light Regions in 16-bit Images
original 16-bit image
19 October 2011
contr. stretched light + dark reg.
52
1999-2011 by Richard Alan Peters II
Dithering: Noise Improves Quantization
Quantizing an image into 1, 2, or 3 bits can introduce false contours. The addition of signed noise to the image before quantization can improve the appearance of the result. This is called dithering. The noise usually should have = 0. The of the noise must be determined through experimentation since it depends on the image being quantized. A reasonable first choice for uniformly distributed noise is = M/q, where M is the maximum intensity value in the image (e.g. 255) and q is the number of bits in the quantized image.
I + N(,)
Quant(q)
19 October 2011
1999-2011 by Richard Alan Peters II
53
Dithering: use noise to reduce quant. error
8 bits
19 October 2011
4 bits
1999-2011 by Richard Alan Peters II
4 bits + noise
54
Dithering: use noise to reduce quant. error
8 bits
19 October 2011
3 bits
1999-2011 by Richard Alan Peters II
3 bits + noise
55
Dithering: use noise to reduce quant. error
8 bits
19 October 2011
2 bits
1999-2011 by Richard Alan Peters II
2 bits + noise
56
Dithering: use noise to reduce quant. error
8 bits
19 October 2011
1 bit
1999-2011 by Richard Alan Peters II
1 bit + noise
57