Professional Documents
Culture Documents
Dip Lab 7
Dip Lab 7
TECHNOLOGY, TAXILA
ELECTRICAL ENGINEERING
DEPARTMENT
SUBMITTED BY:
Rabeah Farrakh
20-EE-02
SUBMITTED TO:
OBJECTIVE:
To implement and understand the use of spatial filters for image processing.
LEARNING TASKS:
Download chapter 3 images of the Gonzalez DIP 3rd edition book from the link given below.
https://www.imageprocessingplace.com/DIP-3E/dip3e_book_images_downloads.htm
b. Filter the image with the filter 𝑤 defined above using the imfilter command.
View the filtered image and verify your response to part-a. While using
imfilter command, try to understand the boundary options available with this
command.
c. A 3 × 3 filter 𝑤 defined below shifts the image towards right one pixel unit when
applied on the image. Try this kernel and explain why this happens? Write down
a filter kernel which would shift the image towards left by 3-pixel units.
0 0 0
𝑤 = [0 0 1]
0 0 0
d. Write a code in MATLAB based on filters to shift the image 𝑛 −pixel units
towards left or right based on the user inputs. AVOID hardcoding.
MATLAB CODE:
img=imread('kidney.tif');
inp = input('enter value: ');
z = zeros((n*2)+1);
z(round(length(z)/2),length(z))=1;
f=imfilter(img,z);
imshow(f)
title('Output Image')
suptitle('20-EE-02')
2. Read and view Fig0333(a)(test_pattern_blurring_orig).tif in MATLAB.
1 1 1 1 1 1 2 1
𝑤1 = × [1 1 1], 𝑤2 = × [2 4 2]
9 16
1 1 1 1 2 1
a. Filter kernel 𝑤1 is a 3 × 3 smoothing/averaging box (square) filter. Why is it
called a smoothing or averaging filter? Think, how the filtered output image will
be different visually when the input image is convolved with this filter?
b. Create the 𝑤1 kernel and apply the filter using the imfilter command. View
the filtered image. Is the smoothing filter a LPF or HPF?
c. Write down the kernel for a 5 × 5 averaging box filter. Verify your answer by
creating a 5 × 5 averaging kernel using the fspecial command.
d. Create a 3 × 2 subplot grid to show the original image and the filtered images
with averaging box filter of sizes 5, 9, 15, 35 and 51. Use the fspecial
command to create filters of different sizes. What happens to the smoothing
operation when the filter kernel size is increased?
e. Filter kernel 𝑤2 is one representation of a 3 × 3 weighted smoothing/averaging
filter also called the Gaussian smoothing filter. Which pixel value is given the
highest weight in this kernel? Repeat part-d using the Gaussian filter. How the
standard deviation parameter in Gaussian filter impact the weights of the kernel?
f. Create a 1 × 3 subplot grid to show the original image and the filtered images
with averaging box filter and the Gaussian filter of size 15. Compare the output
images.
b. Binarize the filtered image. Let’s set the threshold value equal to the 25% of the
highest intensity value in the filtered image. View the resulting mask image.
c. Multiply the mask image with the original image and view the resulting image.
Record your observations.
c. Use the order-statistic (non-linear) filters to remove the noise. Use max, min and
median filters using the ordfilt2 command. View the filtered images from these
three filters in a 1 × 3 subplot grid.
d. Which filter is most suitable for removing the noise. Justify your observations.