Upload
duongnhan
View
237
Download
3
Embed Size (px)
Citation preview
1051-361 Digital Image Processing I HW1—Solutions
1. (a) Quantizing from m bits to n bits can be modeled by using
Q{f [x]} =⌊f [x]
2m−n
⌋(1)
where f ∈ Z, 0 ≤ f ≤ 2m − 1, and bxc is the floor of x. The expression
Q{f [x]} =
f [x]fmax − fmin
2m − 1
+12
(2)
is used when quantizing a function to m bits where f is continuos, i.e. f ∈ R, fmin ≤ f ≤ fmax. An example of thistype of function might be:
f [x] =[−1 3.34
√2 π 7
11
](3)
Table 1: Solution to 1a.f [x] 12 12 13 13 10 13 57 54f [x]/8 1.5 1.5 1.75 1.75 1.25 1.75 7.125 6.75bf [x]/8c 1 1 1 1 1 1 7 6
(b) NOTE: When performing IGS quantization from m bits to n bits, if the n most significant bits of f(x) are all “on”[(111) for this problem], the error added is set to 0 [(000) for this problem]. This prevents the output from beinggreater than 2n − 1 which would require n+ 1 bits to store.
Table 2: Solution to 1b.Index Gray Binary Binary + Error Binary IGS Gray IGS−1 N/A (000)(000) N/A N/A N/A
0 12 (001)(100) (001)(100) + (000)(000) = (001)(100) (001) 11 12 (001)(100) (001)(100) + (000)(100) = (010)(000) (010) 22 13 (001)(101) (001)(101) + (000)(000) = (001)(101) (001) 13 13 (001)(101) (001)(101) + (000)(101) = (010)(010) (010) 24 10 (001)(010) (001)(010) + (000)(010) = (001)(100) (001) 15 13 (001)(101) (001)(101) + (000)(100) = (010)(001) (010) 26 57 (111)(001) (111)(001) + (000)(000) = (111)(001) (111) 77 54 (110)(110) (110)(110) + (000)(001) = (110)(111) (110) 6
2. NOTE: The output fq[x] has values of 0 or 2m−1 where m is the bit-depth of the original image. The mean of the output“image” should be the same as the mean of the input “image.”
E [fq[x]] = E [f [x]] = f [x] (4)
It should be further noted that this ideal condition will only occur when the last error is 0.
Table 3: Solution to 2.x f [x] f [x] + ε[x− 1] fq[x] ε[x]−1 N/A N/A N/A 0
0 12 12 + 0 = 12 0 12− 0 = 121 12 12 + 12 = 24 0 24− 0 = 242 13 13 + 24 = 37 63 37− 63 = −263 13 13 +−26 = −13 0 −13− 0 = −134 10 10 +−13 = −3 0 −3− 0 = −35 13 13 +−3 = 10 0 10− 0 = 106 57 57 + 10 = 67 63 67− 63 = 47 54 54 + 4 = 58 63 58− 63 = −5
1 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
3. The following Matlab code can be used to produce the images:
outpath = ’~/Documents/RIT/2010-1/DIP1/HW1/Figures/’;
sx = 128; % set the x sizesy = 128; % set the y sizebd = 8; % set the bit depth
% create an image with half the maximum bit depthim1 = uint8( zeros( sy, sx ) );im1( : ) = uint8( 2^( bd - 1 ) - 1 );imwrite( im1, [ outpath ’image1.png’ ] )figureimshow( im1, [ 0 2^bd-1 ] )
% create an image with one quarter the maximum bit depthim2 = uint8( zeros( sy, sx ) );im2( : ) = uint8( 2^( bd - 2 ) - 1 );imwrite( im2, [ outpath ’image2.png’ ] )figureimshow( im2, [ 0, 2^bd-1 ] )
% create an image with a ramp from 112 to 144
f_max = 144;f_min = 112;
x = ones( sy, 1 ) * ( 1:sx );im3 = uint8( ( x - 1 ) ./ ( sx - 1 ) .* ( f_max - f_min ) + f_min );imwrite( im3, [ outpath ’image3.png’ ] )figureimshow( im3, [ 0, 2^bd-1 ] )
(a) (b) (c)
Figure 1: (a) mid gray, (b) quarter gray, and (c) ramp from 112 to 144.
4. (a) Psuedo-code for one implementation of IGS
input Image Input the imagesx, sy = size(image) Find the size of the image
2 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
newImage = array(sx, sy) Create a new array the same size as the input imagefor i = 1 to sx do
error = 0 Set the error to zerofor j = 1 to sy do
newImage[i, j] = Q(Image[i, j] + error) Run a quantizer on the current location with errorcompute error Compute the new error
endendoutput newImage Output the new image
(b) Psuedo-code for one implementation of 2-D error diffusion
input Image Input the imagesx, sy = size(image) Find the size of the imagenewImage = array(sx, sy) Create a new array the same size as the input imagefor i = j to sy do
for i = 1 to sx donewImage(i, j) = compute output Compute the output value at location (i, j)compute error Compute the new errordistribute error Distribute the error appropriately
endendoutput newImage Output the new image
5. Figures 2, 4, and 6 show the original three images and the following quantizations of the images: uniform quantization(quantized to 1-7 bits), IGS quantization (quantized to 1-7 bits), and 2–D error diffusion (quantized to 1 bit). Note thatyou only had to show images (a) and [(l) or (p)] for credit. The rest of the images are for reference. In all cases IGS isrun with errors propagating from left to right. Histograms of all images are also included for reference and to help withinterpretation. The y-axis scale on histograms vary.
6. Figures 8 and 10 show the original two images and the following quantizations of the images: uniform quantization(quantized to 1-7 bits), IGS quantization (quantized to 1-7 bits), and 2–D error diffusion (quantized to 1 bit). Note thatyou only had to show images (a) and [(l) or (p)] for credit. The rest of the images are for reference. In all cases IGS isrun with errors propagating from left to right. Histograms of all images are also included for reference and to help withinterpretation. The y-axis scale on histograms vary.
3 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
(a) (b) (c) (d)
(e) (f) (g) (h)
(i) (j) (k) (l)
(m) (n) (o) (p)
Figure 2: Quantizations of image 1 (uniform mid-gray). (a) original, (b) uniform quantization to 7 bits, (c) uniform quantizationto 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g) uniformquantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits, (k)igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
4 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
(a) (b) (c) (d)
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
(e) (f) (g) (h)
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
DC
#
0 50 100 150 200 2500
5000
10000
15000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
(i) (j) (k) (l)
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
(m) (n) (o) (p)
Figure 3: Histograms of quantizations of image 1 (uniform mid-gray). (a) original, (b) uniform quantization to 7 bits, (c) uniformquantization to 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits,(g) uniform quantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits,(k) igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
5 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
(a) (b) (c) (d)
(e) (f) (g) (h)
(i) (j) (k) (l)
(m) (n) (o) (p)
Figure 4: Quantizations of image 2 (uniform quarter-gray). (a) original, (b) uniform quantization to 7 bits, (c) uniform quan-tization to 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g)uniform quantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits,(k) igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
6 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
(a) (b) (c) (d)
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
18000
DC
#
(e) (f) (g) (h)
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
DC
#
0 50 100 150 200 2500
5000
10000
15000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
(i) (j) (k) (l)
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
DC
#
(m) (n) (o) (p)
Figure 5: Quantizations of image 2 (uniform quarter-gray). (a) original, (b) uniform quantization to 7 bits, (c) uniform quan-tization to 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g)uniform quantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits,(k) igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
7 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
(a) (b) (c) (d)
(e) (f) (g) (h)
(i) (j) (k) (l)
(m) (n) (o) (p)
Figure 6: Quantizations of image 3 (ramp). (a) original, (b) uniform quantization to 7 bits, (c) uniform quantization to 6 bits,(d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g) uniform quantizationto 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits, (k) igs quantization to5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igs quantization to 1 bits,and (p) 1-bit error diffusion.
8 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
0 50 100 150 200 2500
100
200
300
400
500
DC
#
0 50 100 150 200 2500
200
400
600
800
1000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
2500
3000
3500
4000
4500
DC
#
(a) (b) (c) (d)
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
(e) (f) (g) (h)
0 50 100 150 200 2500
200
400
600
800
1000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
2500
3000
3500
4000
4500
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
(i) (j) (k) (l)
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
DC
#
0 50 100 150 200 2500
5000
10000
15000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
14000
16000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
(m) (n) (o) (p)
Figure 7: Histograms of quantizations of image 3 (ramp). (a) original, (b) uniform quantization to 7 bits, (c) uniform quantizationto 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g) uniformquantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits, (k)igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
9 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
(a) (b) (c) (d)
(e) (f) (g) (h)
(i) (j) (k) (l)
(m) (n) (o) (p)
Figure 8: Quantizations of image 4 (extended ramp). (a) original, (b) uniform quantization to 7 bits, (c) uniform quantizationto 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g) uniformquantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits, (k)igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
10 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
0 50 100 150 200 2500
20
40
60
80
100
120
140
DC
#
0 50 100 150 200 2500
20
40
60
80
100
120
140
DC
#
0 50 100 150 200 2500
50
100
150
200
250
DC
#
0 50 100 150 200 2500
100
200
300
400
500
DC
#
(a) (b) (c) (d)
0 50 100 150 200 2500
200
400
600
800
1000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
2500
3000
3500
4000
4500
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
(e) (f) (g) (h)
0 50 100 150 200 2500
50
100
150
200
250
DC
#
0 50 100 150 200 2500
50
100
150
200
250
300
350
400
DC
#
0 50 100 150 200 2500
100
200
300
400
500
600
700
800
DC
#
0 50 100 150 200 2500
200
400
600
800
1000
1200
1400
1600
DC
#
(i) (j) (k) (l)
0 50 100 150 200 2500
500
1000
1500
2000
2500
3000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
DC
#
0 50 100 150 200 2500
2000
4000
6000
8000
10000
12000
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
9000
DC
#
(m) (n) (o) (p)
Figure 9: Histograms of quantizations of image 4 (extended ramp). (a) original, (b) uniform quantization to 7 bits, (c) uniformquantization to 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits,(g) uniform quantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits,(k) igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
11 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
(a) (b) (c) (d)
(e) (f) (g) (h)
(i) (j) (k) (l)
(m) (n) (o) (p)
Figure 10: Quantizations of image 5 (lena). (a) original, (b) uniform quantization to 7 bits, (c) uniform quantization to 6 bits,(d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits, (g) uniform quantizationto 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits, (k) igs quantization to5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igs quantization to 1 bits,and (p) 1-bit error diffusion.
12 October 5, 2010
1051-361 Digital Image Processing I HW1—Solutions
0 50 100 150 200 2500
100
200
300
400
500
600
DC
#
0 50 100 150 200 2500
200
400
600
800
1000
1200
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
2500
3000
3500
4000
DC
#
(a) (b) (c) (d)
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
DC
#
0 50 100 150 200 2500
5000
10000
15000
DC
#
0 50 100 150 200 2500
0.5
1
1.5
2
2.5
3
x 104
DC
#
0 50 100 150 200 2500
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
x 104
DC
#
(e) (f) (g) (h)
0 50 100 150 200 2500
200
400
600
800
1000
1200
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
DC
#
0 50 100 150 200 2500
500
1000
1500
2000
2500
3000
3500
4000
4500
DC
#
0 50 100 150 200 2500
1000
2000
3000
4000
5000
6000
7000
8000
DC
#
(i) (j) (k) (l)
0 50 100 150 200 2500
5000
10000
15000
DC
#
0 50 100 150 200 2500
0.5
1
1.5
2
2.5
x 104
DC
#
0 50 100 150 200 2500
0.5
1
1.5
2
2.5
3
3.5
4
4.5
x 104
DC
#
0 50 100 150 200 2500
0.5
1
1.5
2
2.5
3
3.5
4
x 104
DC
#
(m) (n) (o) (p)
Figure 11: Quantizations of image 2 (uniform quarter-gray). (a) original, (b) uniform quantization to 7 bits, (c) uniformquantization to 6 bits, (d) uniform quantization to 5 bits, (e) uniform quantization to 4 bits, (f) uniform quantization to 3 bits,(g) uniform quantization to 2 bits, (h) uniform quantization to 1 bits, (i) igs quantization to 7 bits, (j) igs quantization to 6 bits,(k) igs quantization to 5 bits, (l) igs quantization to 4 bits, (m) igs quantization to 3 bits, (n) igs quantization to 2 bits, (o) igsquantization to 1 bits, and (p) 1-bit error diffusion.
13 October 5, 2010