Worksheet Paper - Digital Images Processing - March 2024
Worksheet Paper - Digital Images Processing - March 2024
Question 1
Multiple choices (circle the most appropriate one):
6) Both the -------- and -------- filters are used to enhance horizontal edges
(or vertical if transposed).
a) Prewitt and Sobel b) Sobel and Gaussian
c) Prewitt and Laplacian d) Sobel and Laplacian
12) To map a narrow range of low gray-level input image into a wider
range of output levels , we use
a) Log Intensity Transformation Function
-2- Dr. Amir Ahmed Omer Yousif
b) Power-law Intensity Transformation Function
c) Inverse Log Intensity Transformation Function
d) Identity Intensity Transformation Function
13) The sum of all elements in the mask of the smoothing averaging spatial
filtering must be equal to
a) m rows
b) n columns
c) m*n
d) 1
##############################*****###############################
Question 2
Solution:
• Boundary Representation
• Region Representation
Solution:
a) 4-connectivity:
-3- Dr. Amir Ahmed Omer Yousif
Two pixels p and q with values from V are 4-connected if q is in the set N4 (p)
b) 8- connectivity:
Two pixels p and q with values from V are 8-connected if q is in the set N8 (p)
c) m- connectivity:
Two pixels p and q with values from V are m-connected if
i. q is in N4 (p) or
ii. q is in ND (p) and the set N4(p) n N4(q) s Θ
Solution:
1) Perwitt filter.
2) Roberts filter
3) Sobel filter.
4) Unsharp filter
Solution:
Unsharp masking:
The process of subtracting an unsharp (smoothed) version of an image from the original
images to get sharpened images (high pass filtering).
The process consists of the following steps:
a) Blur the original image.
b) Subtract the blured image from the original (the resulting difference is called the mask).
c) Add the mask to the original image.
##############################*****###############################
Question 3
Write a Matlab script code to display the histogram of an image using a bar
graph reduce the resolution of the horizontal axis into 10 bands. Add suitable
horizontal and vertical axes, xtick and ytick for your graph.
Solution:
##############################*****###############################
Question 4
Write matlab script code to read a gray scale image named "pout.tif" and
apply the following mathematical function to stretch its contrast levels:
Where:
g is the enhanced output image , f is the input image, m and E must be
interactively entered by the user using Matlab input command. Display the
original and the contrast stretched images.
Solution:
f = imread('pout.tif');
##############################*****###############################
Question 5
Solution:
##############################*****###############################
Question 6
Solution:
g3 = g1 - g2;
subplot(2,2,4);
imshow(g3,[]);
title('image using Laplacian filter');
##############################*****###############################
Question 7
Classify Images sources by energy
Solution:
##############################*****###############################
Question 8
List four types of digital images used in Matlab programming language;
explain the Data Classes, the range for each type and how many matrices used
for each type (fill the table)
Number of
Image Type Data Classes Range matrices
##############################*****###############################
Question 9
Write a Matlab script code to
• Read a simple RGB image "football.jpg".
• Create a separate image for each color planes (red, green and blue) of
the image.
• Display each color plane image separately, and also display the original
image.
Solution:
RGB = imread('peppers.png');
red = RGB(:,:,1);
green = RGB(:,:,2);
blue = RGB(:,:,3);
imshow(red), figure ,
imshow(green),figure
imshow(blue), figure,
imshow (RGB);
Where:
Br: Blending ratio (0-1), q : output image, g 1, g 2 : input images,
• Use preallocating array for image.
• Use low-level processing.
• Display the input and the output images.
Solution:
for x= 1:M
for y=1:N
q(x,y)=uint8(br*p1(x,y)+(1-br)*p2(x,y));
end
end
##############################*****###############################
Question 11:
Write a matlab script code to
• Read images "cameraman.tif" and "pout.tif".
• Display both images as shown in figure
-10- Dr. Amir Ahmed Omer Yousif
• Subtract the first 200x200 pixels of the first image from the last 200x200
of the second image.
Solution:
A1 = A(1:200,1:200);
B1 = B(end-199:end,end-199:end);
subplot(1,3,3), imshow(Output);
title('subtract images') % subtract images
##############################*****###############################
Question 12
Consider the two image subsets, whether these two subsets are S 1 and S2 ,
shown in the following figure. For V = {1}, determine whether these two
subsets are:
(a) 4-adjacent, (b) 8-adjacent, or (c) m-adjacent.
##############################*****###############################
Question 13
Explain the Gray-level slicing concept, its two methods and plots.
Solution:
Highlighting a specific range of gray levels in an image: Display a high value of all gray
levels in the range of interest and a low value for all other gray levels.
a) Transformation highlights range [A, B] of gray level and reduces all others to a
constant level
b) Transformation highlights range [A, B] but preserves all other levels
##############################*****###############################
-12- Dr. Amir Ahmed Omer Yousif
Question 14
The following figures show
(a) a 3-bit image of size 5-by-5 image in the square, with x and y
coordinates specified,
(b) a Laplacian filter and
(c) a low-pass filter.
Solution:
a) 3.67
b) 16
c) 3.59
d) histogram of the whole image:
Intensity 0 1 2 3 4 5 6 7
Frequency 2 4 5 2 3 3 3 3
##############################*****###############################
Question 15
Write a Matlab script code to
• Read an image "pout.tif" (256 gray levels).
• Calculate and plot the Cumulative Distribution Function for the image
'pout.tif'
• Add labels, text and title for your plot.
Solution:
-13- Dr. Amir Ahmed Omer Yousif
The complete code for this question as the following:
f = imread('pout.tif');
cdf = cumsum(imhist(f)./numel(f));
x = linspace(0,1,100); plot(x,cdf);
axis([0 1 0 1]);
set(gca,'xtick',0:0.2:1);
set(gca,'ytick',0:0.2:1);
xlabel('Input Intensity Values','fontsize', 9);
ylabel('Output Intensity Values','fontsize', 9);
text(0.5,0.5,'Transformation
Function','fontsize',9);
##############################*****###############################
Question 16
Write a Matlab function called "imf_gaussian" that can handle a variable
number of inputs, the code must contain error checking and validate the
number of input arguments, the function must
Read an image (the name of the image is given as an input argument).
Perform smoothing using "Gaussian" filter mask with different options
as the following.
1. imf_gaussian (imagefilename , 'default' )
The 'default' option uses the 'fspecial' function to create the Gaussian
filter mask, size of 7 rows and 7 columns, standard deviation equal 5,
and filtering mode ='conv'.
2. imf_gaussian (imagefilename ,'manual')
-14- Dr. Amir Ahmed Omer Yousif
The 'manual' option creates manually a Gaussian filter mask
Solution: