EIE4512  Digital Image Processing – Assignment #1
Problem 1 (5 points)
Instructor: Zhen Li
Due on 2024/06/21 23:59 pm
Part I Written Exercises
A common measure of transmission for digital data is the baud rate, defined as the number of bits transmitted per second. Generally, transmission is accomplished in packets consisting of a start bit, a byte (8 bits) of information, and a stop bit. Using these facts, answer the following:
(a) How many minutes would it take to transmit a image 512 × 512 with 256 intensity levels using a 56K baud modem?
(b) What would the time be at 3000K baud, a representative medium speed of a phone DSL (Digital Subscriber Line) connection?
Problem 2 (5 points)
Consider the two image subsets, S1 and S2 , shown in the following figure. For V = {1}, determine whether these two subsets are (a) 4adjacent, (b) 8adjacent, or (c) madjacent.
Problem 3 (5 points)
Propose a set of intensityslicing transformations capable of producing all the individual bit planes of an 8bit monochrome image. (For example, a transformation function with the property T(r) = 0, for r in the range [0, 127], and for r in the range [128, 255] produces an image of the 8th bit plane in an 8bit image.)
Problem 4 (5 points)
Explain why the discrete histogram equalization technique does not, in general, yield a flat histogram.
1
Problem 5 (5 points)
The images shown below are quite different, but their histograms are the same. Suppose that
each image is blurred with a averaging mask.
(a) Would the histograms of the blurred images still be equal? Explain.
(b) If your answer is no, sketch the two histograms.
Problem 6 (5 points)

(a) Suppose that you filter an image, f(x, y) , with a spatial filter mask, w(x, y) , using convolution, as defined as follows,
where the mask is smaller than the image in both spatial directions. Show the important property that, if the coefficients of the mask sum to zero, then the sum of all the elements in the resulting convolution array (filtered image) will be zero also (you may ignore computational inaccuracies). Also, you may assume that the border of the image has been padded with the appropriate number of zeros.

(b) Would the result to (a) be the same if the filtering is implemented using correlation, as defined as follows?
Problem 7 (5 points)

(a) Isolated clusters of dark or light (with respect to the background) pixels whose area is less than onehalf the area of a median filter are eliminated (forced to the median value of the neighbors) by the filter. Assume a filter of size n × n with n odd, and explain why this is so.

(b) Consider an image having various sets of pixel clusters. Assume that all points in a cluster are lighter or darker than the background (but not both simultaneously in the same cluster), and that the area of each cluster is less than or equal to n2/2. In terms of n, under what
2
condition would one or more of these clusters cease to be isolated in the sense described in part (a)?
Problem 8 (10 points)
The three images shown were blurred using square averaging masks of sizes n = 23,25, and 45, respectively. The vertical bars on the left lower part of (a) and (c) are blurred, but a clear separation exists between them. However, the bars have merged in image (b), in spite of the fact that the mask that produced this image is significantly smaller than the mask that produced image (c). Explain the reason for this.
Submission List:
• All answers in the file your_school_id_name.pdf (e.g., 1190190xx_San_Zhang.pdf ).
Part II Programming Exercises Problem 1 Histogram Equalization and Matching (20 points)
Please use “coding_input.jpg” as the input and the “coding_reference.jpg” as the reference image. You can only use the following Python libraries: OpenCV (only for loading and writing images), numpy, math, and matplotlib.
Submission List:

Codes for part (a), (b), and (c) in the file hist.py.

Display the results for part (a), (b), and (c) in the file your_school_id_name.pdf. (e.g.,
1190190xx_San_Zhang.pdf ).
3
•
(a) Implement the function histShow(img). Display the histograms of the input image and the reference image. (Hint: Use numpy.histogram)
(b) Implement the function histEqual(img). Perform histogram equalization on the input image, and compare the histogram differences between the input image and output image.
(c) Implement the function histMatch(img, img_ref). Perform histogram matching on the RGB channels from the reference image to the input image, and display the output image. (Hint: The input image is a gray image.)
Problem 2 Spatial Filtering (35 points)
Please use “sport_car.png” as the input. You can only use the following Python libraries: OpenCV (only for loading and writing images), numpy, math, and matplotlib.
Submission List:

Codes for the implementation in part (a) and (b) in the file noise.py.

Codes for the implementation in part (c) in the file median_filter.py.

Codes for the implementation in part (d) in the file gaussian_filter.py.

Codes for displaying results in part (b), (c), and (d) in the file main.py.

Display the results for part (a), (b), (c) and (d) in the your_school_id_name.pdf. (e.g.,
1190190xx_San_Zhang.pdf ).
(a) Generate two different random matrices whose values are evenly distributed in the interval[0, 255], t1(x, y) and t2(x, y), t1(x, y) ≠ t2(x, y) . (Hint: Use numpy.random)
(b) Denote the input image as f0 (x, y). Implement a function genNoise(img) to generate animage with saltandpepper noise f (x, y) based on the following function:
(c) Implement a median filter of size 3 × 3 medianFilter(img). Perform median filtering on the image with saltandpepper noise f (x, y) in (b). Compare the filtered result with the image that applies (Any filtering interfaces from the Python libraries, e.g., not allowed in implementation.)
(d) Implement a Gaussian filter of kernel size 3 × 3 gaussianFilter(img, sigma). Perform Gaussian filtering on the image with saltandpepper noise f (x, y) in (b) with the sigma of
cv2.medianBlur in OpenCV.
cv2.medianBlur in OpenCV, are
4
0.5, 0.8, and 1.0. Compare the filtered result with the image that applies cv2.GaussianBlur and cv2.getGaussianKernel in OpenCV. (Hint: Implement the Gaussian kernel function gaussianKernel(sigma) before gaussianFilter(img, sigma). Any filtering interfaces from the Python libraries, e.g., cv2.GaussianBlur in OpenCV, are not allowed in implementation.)