homework #1 image manipulation, image enhancement, noise ... · image manipulation, image...

9
1 EE569 Digital Image Processing (08/27/2010) Version 4 (9/9/2010) HOMEWORK #1 Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines and MATLAB Function Guidelines for more information about how to complete and submit the homework. Also, refer to the USC policy on academic integrity and penalties for cheating and plagiarism - these rules will be strictly enforced. Problem 1: Image Manipulation (20%) In this problem, you will be asked to do a series of simple manipulations on the pixels of grayscale and color images to get you used to accessing this data and modifying it. (a) Basic Image Input/Ouput (10%) First, given a grayscale image and its size, write functions that perform the following operations, making sure that the output file name and sizes are announced to the user after your code has finished running. Test all of your code for this problem with the bill.raw image shown in Figure 1. Figure 1: bill.raw (1) Cropping - given a single set of image coordinates (j,k), that should be within the length and width range of the image, design a function which crops the input image into 4 output images: top left (A), top right (B), bottom left (C), and bottom right (D), relative to the set of image coordinates. See below for an illustrative example: k j A B C D Columns (1,2, … ,k, … ,K) Rows (1, 2, … ,j, … ,J)

Upload: others

Post on 08-Jul-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

1

EE569 Digital Image Processing (08/27/2010) Version 4 (9/9/2010)

HOMEWORK #1

Image Manipulation, Image Enhancement, Noise Removal

Issued: 08/27/2010 Due: 09/17/2010

Please refer to Homework Guidelines and MATLAB Function Guidelines for more information about how to complete and submit the homework. Also, refer to the USC policy on academic integrity and penalties for cheating and plagiarism - these rules will be strictly enforced. Problem 1: Image Manipulation (20%) In this problem, you will be asked to do a series of simple manipulations on the pixels of grayscale and color images to get you used to accessing this data and modifying it.

(a) Basic Image Input/Ouput (10%)

First, given a grayscale image and its size, write functions that perform the following operations, making sure that the output file name and sizes are announced to the user after your code has finished running. Test all of your code for this problem with the bill.raw image shown in Figure 1.

Figure 1: bill.raw

(1) Cropping - given a single set of image coordinates (j,k), that should be within the length

and width range of the image, design a function which crops the input image into 4 output images: top left (A), top right (B), bottom left (C), and bottom right (D), relative to the set of image coordinates. See below for an illustrative example:

k

j A B

C D

Columns (1,2, … ,k, … ,K)

Rows (1, 2, … ,j, … ,J)

Page 2: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

2

Test your function with the two separate input coordinates of (100, 100) and (76, 214), and place the output images in your report. Discuss any problems you encountered. Make sure that you print the image names and sizes at output.

(2) Bit-Plane Extraction - design a function which extracts 8 bit-plane images from an input grayscale image. Each of these bit-planes should be a binary image where every pixel corresponds to the single bit from every respective grayscale pixel in the original image. Use the convention that if the bit is 0, the output pixel is 0 and if the bit is 1, the output pixel is 255. For instance, if the first pixel in the image has value 100 (or 01100100 in binary), then the first pixel in each of the 8 bit-plane images will have value 0, 255, 255, 0, 0, 255, 0, 0. Print all 8 bit-plane images from bill.raw and discuss the importance of information that is stored in each of these bit-planes.

(3) Negative - design a function which produces the "negative" of a grayscale image. Assuming that the input image is F(i,j) and the output is G(i,j), use the following formula for every pixel in the image in order to do this: Knowing what you've learned about histogram manipulation, what kind of transformation function would yield an image negative?

(b) Color Space Transformations (10%) Use the test image mandril.raw for all of the sub-problems below.

Figure 2: mandril.raw

Page 3: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

3

In this problem, you will examine a few of different color spaces that are frequently employed in various sub-fields within image processing. (1) CMY Color Space - One of the primary alternatives to the Red-Green-Blue (RGB)

color space is the Cyan-Magenta-Yellow (CMY) color space, frequently used in printing. Design a set of functions that transforms a color image from RGB to CMY, using the equations below:

C = 255 − RM = 255 −GY = 255 − B

Note that your function will have to take one input color image and produce 3 output grayscale images, each corresponding to the cyan, the magenta, and the yellow channel. Show these three grayscale images in your report. Discuss your results and try to explain why CMY is used in printing rather than RGB.

(2) HSV Color Space - an alternative representation of color images that is often used in graphics design is the Hue-Saturation-Value color space. Rather than being direct numerical indicators of color, the HSV channels each describe a different property of the color, so each channel isolates a particular piece of information. Hue and Saturation both describe the chromatic information of the pixel, while value defines the brightness of the pixel. Hue, an angle between 0 and 360 degrees, corresponds to the actual color of the pixel on the hue scale. Saturation, a number between 0 and 1, corresponds to the purity of the color. Value, a number between 0 and 1, corresponds to the actual lightness or darkness quality of the pixel. Use the formulas below to write a function, which generates the HSV channels for an image.

M = max(R,G,B) N = min(R,G,B) C = M − N

H =

0 C = 060 G − B

Cmod6

⎝ ⎜

⎠ ⎟ M = R

60 B − RC

+ 2⎛

⎝ ⎜

⎠ ⎟ M =G

60 R −GC

+ 4⎛

⎝ ⎜

⎠ ⎟ M = B

⎪ ⎪ ⎪

⎪ ⎪ ⎪

V = M S =0 C = 0CV

C ≠ 0⎧ ⎨ ⎪

⎩ ⎪

NOTE: For these formulas, R, G, and B should be first normalized to [0,1].

Page 4: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

4

Design a function which generates 3 separate grayscale images for a given input color image; one for each of the HSV channels. Note that you will have to renormalize each of the channels to the range 0-255. Show the results of the transformation in the report and comment on what kind of information each of the channels contains about the original.

Problem 2: Image Enhancement (40%) (a) Written Problems (15%)

We want to apply image enhancement techniques to the following image of size 5x5 given in Figure 3. Please note that each pixel can be represented with 4 bits, not 8 bits. In other words, gray scale values are between 0 and 15, not between 0 and 255.

5 3 3 5 4 2 3 4 3 3 1 2 4 2 1 3 4 5 2 2 2 3 3 4 3

Figure 3: Original Image with Size 5x5 before Image Enhancement

(1) Plot the histogram of the original image given Fig. 3 with gray scales values as the x

axis and number of pixels as the y axis.

(2) Apply full-range linear scaling to the original image. Plot the transfer function and the new histogram after full-range linear scaling.

(3) Apply histogram equalization to the original image. Use the algorithm based on cumulative histogram. Draw the cumulative histogram (normalize it on y-axis) and the new histogram. Hint: Please note that number of pixels assigned to each gray scale value bin in the histogram stays the same after histogram equalization. However, the distances between neighboring bins in the histogram are being changed. In other words, no pixels might be assigned to some gray scale value bins in the histogram.

(4) Apply the digital implementation of histogram equalization mentioned in the class to the original image. Draw the cumulative histogram (normalize it on the y-axis) and the new histogram. Hint: Please note that we want to make the number of pixels assigned to each bin as equal as possible here. In other words, the histogram should look similar to the uniform distribution.

Page 5: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

5

(b) Programming Problems (25%) After solving simple written problem in part A, we want to apply image enhancement techniques to real image lena.raw of size 256x256 given in Figure 4.

Figure 4: lena_dark.raw with size 256x256 (1) Plot the histogram of the original image given Figure 4 with gray scales values as the x

axis and number of pixels as the y axis.

(2) Apply full-range linear scaling to the original image. Plot the transfer function and the new histogram after full-range linear scaling.

(3) Apply histogram equalization to the original image. Use the algorithm based on cumulative histogram. Draw the cumulative histogram (normalize it on the y-axis) and the new histogram.

(4) Apply the digital implementation of histogram equalization mentioned in the class to the original image. Draw the cumulative histogram (normalize it on y-axis) and the new histogram.

(5) Compare the cumulative histograms, the histograms, and the image enhancement results from (2), (3), and (4) and discuss your observations. Is there any difference between these results? If yes, why do you think there is performance difference between these schemes?

Page 6: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

6

Problem 3: Noise Removal (40%) This problem deals with images that contain noise, which may have been introduced during acquisition or transmission of the image. Your task is to remove as much noise as you can, using methods suggested below.

(a) Uniform Noise (5%)

Consider an LTI system with filters A and B:

From basic DSP knowledge we know that the two systems are equivalent. Verify that this is true by using two different low-pass filters introduced in the class to remove uniform noise from the following image and comparing the PSNR of final output images. Figure 5 shows the original image and Figure 6 shows the noisy image. Each image is of size 512x512.

Figure 5: peppers.raw Figure 6: peppers_uniform.raw Note that PSNR (Peak Signal-to-Noise Ratio) is calculated as follows:

PSNR (dB) = 20log10Max2

MSE⎛

⎝ ⎜

⎠ ⎟

where MSE =1NM

Y (i, j) − X(i, j)( )2

j=1

M

∑i=1

N

X : Original Image of size NxMY : Filterd Image of size NxMMax : Maximum possible pixel intensity = 255

A B

System I

B A

System II

Page 7: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

7

(b) Mixed Noise (15%)

Consider Fig. 7 showing an image with mixed noise – uniform and impulse. Since the image has mixed noise, we will need more than one filter to remove mixed noise.

Figure 7: peppers_mixed.raw (1) Which filters would you use for which noise type?

(2) Can you cascade them in any order? Justify your answer.

Hint: Compare this with LTI case in part 1 where the two LPF can be exchanged.

(3) Try your best to remove the noise. Clearly describe your approach.

(c) Low Pass Filter Performance on Edges (5%) Using the Lena image shown below (Figure 8) of size 256x256x3, we want to compare various LPF filters taught in class. Each R, G, B plane has been corrupted with noise separately. Filter the image using a simple averaging filter and a weighted average filter (of your choice) for 2 sizes: 3x3 and 5x5. Comment on their performance on edges. Explain which filter performs better on high frequency content of the image and why.

Figure 8: lena_noisy.raw

Page 8: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

8

(d) Non-Local Means (NML) Filter (15%)

Please refer to Reference [1] in the appendix for this part of the assignment (1) Using a NLM filter (write your own code or use any available online source code – but

include the source in your references), denoise the lena_noisy.raw image (Fig. 8). Each R, G, B plane has been corrupted with noise separately. Try several image parameters and clearly mention the choice of final NLM parameters which give best results.

(2) Compare the performance of the NLM filter on edges with that of filters used in part (c). Please explain why NLM filter performs better on edges. DO NOT quote statements directly from [1] or any other online source. Try and explain in your own words. Reports and source codes are subject to verification for any plagiarism.

Page 9: HOMEWORK #1 Image Manipulation, Image Enhancement, Noise ... · Image Manipulation, Image Enhancement, Noise Removal Issued: 08/27/2010 Due: 09/17/2010 Please refer to Homework Guidelines

9

Appendix: Files Used in This Project Problem 1: Edge Detection

Figure 1 bill.raw 188x448 8-bit grayscale Figure 2 mandril.raw 512x512 24-bit color

Problem 2: Morphological Processing

Figure 4 lena_dark.raw 256x256 8-bit grayscale Problem 3: Noise Removal

Figure 5 peppers.raw 512x512 8-bit grayscale Figure 6 peppers_uniform.raw 512x512 8-bit grayscale Figure 7 peppers_mixed.raw 512x512 8-bit grayscale Figure 8 lena_noisy.raw 256x256 24-bit color

Appendix: References

[1] A. Buades, B. Coll, J.M Morel, “A non local algorithm for image denoising”, IEEE

International Conference on Computer Vision and Pattern Recognition, CVPR 2005.vol. 2, pp: 60 - 65.