0% found this document useful (0 votes)
37 views16 pages

Worksheet Paper - Digital Images Processing - March 2024

DIP Processing Digital images processing

Uploaded by

amir8ahamd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views16 pages

Worksheet Paper - Digital Images Processing - March 2024

DIP Processing Digital images processing

Uploaded by

amir8ahamd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

‫بسم هللا الرحمن الرحيم‬

SUDAN INTERNATIONAL UNIVERSITY


Kassala Center [Engineering College]
Computer Engineering

Digital Images Processing Worksheet Paper


Lecturer: Dr. Amir Ahmed Omer Yousif

Questions *and* Answers


##############################*****###############################

Question 1
Multiple choices (circle the most appropriate one):

1) Computer vision defined as a discipline in which -----------


a) Both the input and output of a process are images.
b) The input of a process is an image description and the output is image
c) Both the input and output of a process are descriptions.
d) The input of a process is an image and the output is an image description.

2) MRI Technology used band.


a) Gamma Rays b) CT Scan
c) Visible d) Radio waves

3) -----------Filter cannot be implemented using convolution mechanism.


a) Average b) Gaussian
c) Median d) Disk
4) To remove "salt-and-pepper" noise without blurring we use
a) Max Filter b) Median Filter
c) Min Filter d) Smoothing Filter
5) Edge detection in images is commonly accomplished by performing a
spatial ------of the image field.
a) Smoothing Filter b) Integration
-1- Dr. Amir Ahmed Omer Yousif
c) Differentiation d) Min Filter

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

7) Transforming the pixel values of an image using the log ( )


transformation is an example of contrast compression of the dark pixels
a) True b) False

8) Imaging Radar Technology is an application of band.


a) Radio waves
b) Gamma Rays
c) Ultra Violet
d) Micro Waves

9) One f the following functions is not an IPT (image processing toolbox)


function used to convert images.
a) dither ()
b) rgb2gray ()
c) gray2rgb ()
d) ind2gray ()

10) The colormap array of the indexed image is always of class


a) uint8
b) uint16
c) double
d) logical

11) By default, Matlab stores most data in arrays of class


a) uint8
b) uint16
c) double
d) logical

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

14) Sharpening the images is commonly accomplished by performing a


spatial …………. of the image field.
a) Min Filter
b) Smoothing Filter
c) Integration
d) Differentiation

15) One of the following filters is nonlinear


a) Gaussian Filter
b) Averaging Filter
c) Laplacian Filter
d) Median

##############################*****###############################
Question 2

a) List two kinds of image representation methods?

Solution:

• Boundary Representation
• Region Representation

b) Name the types of connectivity and explain

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 Θ

c) Name three types of sharpening filters?

Solution:

1) Perwitt filter.
2) Roberts filter
3) Sobel filter.
4) Unsharp filter

d) Give the formula for calculating D 4 (city block distance) and D 8


distance (chess board distance).

Solution:

D 4 Distance (city block distance) is defined by


D4( p, q) = x - s + y - t
D8 Distance (chess board distance) is defined by
D8 (p, q) = max (| x - s |, | y - t |) .

e) Explain the concept, steps and equations involved in unsharp masking


technique in image enhancement.
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.

Unsharp masking is expressed in equations form as follows:

-4- Dr. Amir Ahmed Omer Yousif


– Blurred I mage, original image, – unsharp mask.
Then we add a weighted portion of the mask back 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:

The complete code for this question as the following:


f = imread('pout.tif');
h = imhist(f);
h1 = h(1:10:256);
horiz = 1:10:256;
bar(horiz,h1);
xlabel('Intesity Level','fontsize',12);
ylabel('Count of Pixels','fontsize',12); title('Image Histogram');
axis([0 255 0 1500]);
set(gca,'xtick',[0:50:255]);
set(gca,'ytick',[0:200:1500]);

##############################*****###############################
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:

The complete code for this question as the following:

f = imread('pout.tif');

-5- Dr. Amir Ahmed Omer Yousif


f = im2double(f);
m= input('Enter the value of m ');
E= input('Enter the value of m '); %
g = 1./(1+(m./(f+eps)).^E);
figure,imshow(f),title('Original Image');
figure,imshow(g),
title('Contrast stretched Image');

##############################*****###############################
Question 5

Write an M-function for grayscale input image; call it "immaxmin" to


generate two images:
• The first image contains values computed by finding the maximum value
of a 3x3 pixel environment (neighborhood of required pixel) and by
setting the resulting center pixel to this value.
• The second image contains values computed by finding the minimum
value of 3x3 neighborhood of required pixel and by setting the resulting
center pixel to this value.
• Use preallocating array for image.
• Use low-level processing.

Solution:

The complete code for this question as the following:


function [mx, mm]=immaxmin(f)
%IMMAXMIN Computes the new Max and Min images
%[MX, MM]=IMMAXMIN(F) Computes MX and MM images
%obtained using 3x3 operations for each pixel
%(one operation:the max of the 3x3 pixel environment
%and the second opertion is the min of the 3x3).
%MX- the image obtained from the MAX Filter processing.
%MM - the image obtained from the MIN Filter
processing. [M N d] = size(f);
%preallocating arrays for
images mx =
uint8(zeros(M,N));
mm = uint8(zeros(M,N));
%using low-level
processing for x= 2:M-1
for y=2:N-1
fr = [f(x-1,y-1) f(x-1,y) f(x-1,y+1)];
sr = [f(x,y-1) f(x,y) f(x,y+1)];
tr = [f(x+1,y-1) f(x+1,y) f(x+1,y+1)];
mafm = [fr sr tr];
-6- Dr. Amir Ahmed Omer Yousif
mx(x,y) = max(mafm);
mm(x,y)=
min(mafm); end;
end;
imshow(mx), figure,
imshow(mm), figure, imshow(f);

##############################*****###############################
Question 6

Write a matlab function called "Noise_EdgeFilter" that accepts a string


(image file name) and displays images as shown in figure 1 (original image,
image using Gaussian filter, Laplacian image and image using Laplacian
filter).
Do the following steps with the input image:
• To reduce the noise use the low pass linear spatial filter "Gaussian".
• For edge detection use the high pass linear spatial filter "Laplacian".
• Use fspecial matlab command to generate the filters mask.

Solution:

The complete code for this question as the following:

function Noise_EdgeFilter (filename)


-7- Dr. Amir Ahmed Omer Yousif
%Read and display the input image f = imread(filename);
f = im2double(f); subplot(2,2,1);
imshow(f,[]);
title('Input Image');

%Noise Reduction using Gaussian filter


h1 = fspecial('gaussian',[5 5],0.5);
%create the Gaussian mask g1 = imfilter(f,h1,'replicate');
subplot(2,2,2);
imshow(g1,[]);
title('image using Gaussian filter');

%Edge Detection using Laplacian filter


h2 = fspecial('laplacian',0.5);
g2 = imfilter(g1,h2,'replicate');
subplot(2,2,3);
imshow(g2,[]);
title('Laplacian image');

g3 = g1 - g2;
subplot(2,2,4);
imshow(g3,[]);
title('image using Laplacian filter');

##############################*****###############################
Question 7
Classify Images sources by energy

Solution:

 Radiation from Electromagnetic Spectrum


 Acoustic
 Ultrasonic
 Electronic (in the form of electron beams used in electron microscopy)
 Computer (synthetic images used for modeling and visualization)

##############################*****###############################
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)

-8- Dr. Amir Ahmed Omer Yousif


Solution:

Number of
Image Type Data Classes Range matrices

1. Intensity uint8 0-255


(Grayscale uint16 0-65535 1
images) double 0-1
2. Binary Image logical 0 or 1 1
3. Indexed Image Index image ( uint8, As in
uint16,double) Color intensity 2
mapped image (double) images
uint8 As in
4. RGB Images uint16 intensity 3
double images

##############################*****###############################
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:

The complete code for this question as the following:

RGB = imread('peppers.png');
red = RGB(:,:,1);
green = RGB(:,:,2);

blue = RGB(:,:,3);
imshow(red), figure ,
imshow(green),figure
imshow(blue), figure,

imshow (RGB);

-9- Dr. Amir Ahmed Omer Yousif


##############################*****###############################
Question 10
Write an M-function; call it "imblend" to
• Generate a blended (mix or combine) version from two grayscale input
images of the same size using the following equation:

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:

The complete code for this question as the following:

function [q] = imblend(p1,p2,br)


%IMBLEND Computes the blended version of two grayscale input
images
%[Q]=IMBLEND(P1,P2,BR) Computes Q blended image
%using the equation Q(I,J)=BR*P1(I,J)+(1-BR)*P2(I,J)
%using low-level processing
%X: Mixing proportion or blending ratio, which determine the
influences
[M N d] = size(p1);
q = uint8(zeros(M,N));

for x= 1:M
for y=1:N
q(x,y)=uint8(br*p1(x,y)+(1-br)*p2(x,y));
end
end

image(q),figure, image(p1), figure, image(p2)

##############################*****###############################
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:

The complete code for this sub question as the following:

A=imread('cameraman.tif'); % Read in 1st image


B=imread('pout.tif'); % Read in 2nd image

A1 = A(1:200,1:200);
B1 = B(end-199:end,end-199:end);

subplot(1,3,1), imshow(A); title('1st image') % Display


1st image subplot(1,3,2), imshow(B); title('2nd image')
% Display 2nd image Output = imsubtract(A1, B1);

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.

-11- Dr. Amir Ahmed Omer Yousif


Solution:

Let p and q be as shown in Fig. Then,

##############################*****###############################
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.

Compute the following:


(a) The output of a 3 × 3 mean (average) filter at (3, 3).
(b) The output of the 3 × 3 Laplacian filter shown above at (3, 3).
(c) The output of the 3 × 3 low-pass filter shown above at (3, 3).
(d) The histogram of the whole image.

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

with standard deviation equal 5 and filtering mode ='conv'

3. imf_gaussian (imagefilename, 'special', filtersize, sigma, filterMode )


The 'special' option uses the 'fspecial' function to create the Gaussian
filter mask with size defined by filtersize, standard deviation defined by
sigma and filtering Mode defined by filterMode.
The default value are filtersize = [5 5], sigma =1, filtermode = 'corr'
 Display the original image and the filtered image depending on the
calling mode.

Solution:

The complete code for this question as the following:

-15- Dr. Amir Ahmed Omer Yousif


##############################*****###############################

-16- Dr. Amir Ahmed Omer Yousif

You might also like