COSC 445 A2b Histogram equalization, Spatial Filtering

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (5 votes)

Focus: Histogram equalization, Spatial Filtering

For all questions, you need to include code to check whether the input image is grayscale. If it is not,
convert it first to grayscale then process it as required in each question.

1. [7 points] In the previous assignment A2a, you wrote code for contrast stretching. In this assignment,
write a function my_histeq that equalizes the histogram of an image. You cannot use the predefined
Matlab histogram functions such as imhist or histeq. Instead, you need to write your own code to
perform histogram operations (Hint: see slides #35 and #38 in the Histogram lecture notes).

Here is a sample run using the image “fig0315c.bmp” attached with the assignment and the code below:
I = imread(‘fig0315c.bmp’); %download fig0315c.bmp from Connect
I2 = my_histeq(I);
I3 = histeq(I); % to compare your code vs. Matlab’s function
subplot(1,3,1),imshow(I),title(‘original’);
subplot(1,3,2),imshow(I2),title(‘using Matlab histeq’)
subplot(1,3,3),imshow(I3),title(‘using my equalizer’);
Marking guide:
+3 for computing the PDF
+2 for computing the
transformation function
+2 for equalizing the
histogram

2. [13 points] One way to add shadows behind a group of items in an image is as follows:
a. Create a new image I2 with only the items drawn in black on a white background. I2 should
have the same size as the original image.

b. Blur I2 in order to soften the edges of the black areas, creating the illusion of the shadows.
I2 should only have the shadows on a white background.

c. Break the original image into two images with the same size: I3 with the items drawn on
black background, and I4 with only the background (the items are replaced with black color).
d. Create a new image by combining the three images I2, I3, and I4 using arithmetic and/or
logic operators.

Write a Matlab function the takes as arguments the following:
 a grayscale image,
 the threshold used to separate the foreground (item) from the background (for simplicity,
assume foreground items are brighter than the background and can be separated by
thresholding),

 the amount of shadow blurring, and
 the distance of the shadow from the item.

Here is a sample run using the “coins” image attached with the assignment and the code below:
I = imread(‘coins.png’); % Image must be grayscale from 0 to 255
I2 = add_shadow(I,90,5,10); % Threshold=90, blur amount=5, distance=10
subplot(1,2,1), imshow(I), title(‘original’);
subplot(1,2,2), imshow(I2), title(‘with shadows’);
Marking guide:
+3 for breaking the image into
foreground and background.
+5 for creating the shadow effect
for the foreground.
+4 for properly building the final
image.
+1 for logic and simplicity

Submission Instructions

For each question, write a separate Matlab program or function. If you are required to explain
things, write your answer as a comment in your Matlab code. Submit everything as one zip file to
Blackboard Connect. Note that you can resubmit an assignment, but the new submission
overwrites the old submission and receives a new timestamp.