0% found this document useful (0 votes)
24 views6 pages

Assignment-0 DIP-CS406-Fal 2024

DIGITAL image processing

Uploaded by

jameelahmad
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)
24 views6 pages

Assignment-0 DIP-CS406-Fal 2024

DIGITAL image processing

Uploaded by

jameelahmad
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/ 6

CS406 Digital Image Processing

Assignment-0 Practice Assignment


CLO 1
Basics of MATLAB for Image Processing

Fall 2024

Submitted to
Dr. Jameel Ahmad

Submitted By:
<Student Name, ID>

Department of Computer Science


School of Systems and Technology
UMT
CLO-1: Describe the Fundamentals of Digital Image Processing
Students will be able to explain the basic principles of image
formation, representation, and digital image manipulation, including Cognitive, (C2)
concepts such as sampling, quantization, and color models.

Note1: Upload the folder (with your ID as its name) containing your code files and assignment
report on LMS by the deadline.
Note 2: For Q1, the name of your MATLAB code file is ‘q1.m’, for Q2, the name of your
MATLAB code file is ‘q2.m’ and so on
Note 3: One of the good viewer is Irfanview. Download from http://www.irfanview.com/
or locally. (You can convert images from other formats to the pgm or ppm format by opening
them in Irfanview and then saving in the desired format)

%Purpose: To introduce basics of MATLAB for Image Processing


%Date: March 15, 2024
%MATLAB Help: Install MATLAB on your working machine and practice following.
%-------------------------------------------------------------------
close all; %close already opened windows
%% 1) Reads and writes an image

im1 = imread('owl.pgm'); %reads an image


%shows the image
figure
imshow(im1);
imwrite(im1,'owl_Out.pgm'); %writes the image

%% 2) Copy im1 to im2_50 and add 50 to each pixel of im2_50 using for loop.
%displays and saves the image

%add 50 to the image using for loop


im2_50 = im1; %copy im1 matrix to im2_50

%add 50 to each pixel using for loop


for i=1:size(im1,1) %size(im1,1) gives rows of the image
for j=1:size(im1,2) %size(im1,2) gives cols of the image
im2_50(i,j) = im2_50(i,j) +50;
end
end
%view the image
figure
imshow(im2_50);
imwrite(im2_50, 'owl_50-For-Out2.pgm', 'pgm');
%% 3) Copy im1 to im3_50 and add 50 to each pixel without using for loop.
im3_50 = im1;
im3_50 = im3_50 + 50; %adds 50 to each pixel of image
Note 4: Images are available in the folder named: images

1) (10 )Write a MATLAB code to read the files (owl.pgm and mecca06.pgm) and write these
files with the following names.
owl.pgm should be written as owl_Out.pgm
mecca06.pgm should be written as mecca06_Out.pgm

2) (20) Write a MATLAB program that do the following:


a) Reads the files (owl.pgm and mecca06.pgm) in a matrix m1, m2, m3 etc.
b) Add 50 to each pixel of the matrix (m1, m2 etc.,) using for loop. If pixel value (after
adding 50) becomes greater than 255, then assign 255 to that pixel value. Save the
matrix in a files (owl_IntensityInc50_Out.pgm, mecca06_IntensityInc50_Out.pgm)
c) Take the logarithm (log) of base 10 of each pixel of the matrix (m1, m2 etc.) and save
the matrices in the files (owl_Log_Out.pgm, mecca06_Log_Out.pgm)
d) Add 20 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity20_Out.pgm and mecca_Intensity20_Out.pgm.
Add 40 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity40_Out.pgm and mecca_Intensity40_Out.pgm.
Add 60 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity60_Out.pgm and mecca_Intensity60_Out.pgm.

3) (10) Write MATLAB code to read the files owl.ppm in matrix m1 (it contains red, blue and
green color matrix). Similarly, read the file mecca06.ppm in matrix m2 (it contains red, blue
and green color matrix). Write these matrices in the files with the following names.
owl.ppm should be written as owl_Out.ppm
mecca06.ppm should be written as mecca06_Out.ppm

4) (45= 5+ 5+ ….+5) Write a MATLAB program that do the following:


a) Reads the files (owl.ppm and mecca06.ppm) in a matrix m1 and m2 (in general m1
contains R, G and B matrices of first image i.e., owl.ppm and m2 contains R, G and B
matrices of second image i.e., mecca06.ppm).

b) Make each pixel of the G matrix and B matrix of both the images to 0 (i.e., make the
G and B matrix of m1 to zero. Similarly make G and B matrix of m2 to zero). Write
the matrix (each comprising of red, green and blue matrix) of each image in a file
named owl_Red_out.ppm and mecca06_Red_out.ppm.

c) Make each pixel of the R matrix and B matrix of both the images to 0. Write these
three matrices of each image in a file named owl_Green_out.ppm and
mecca06_Green_out.ppm.

d) Make each pixel of the R matrix and G matrix of both the images to 0. Write the
matrix of each image in a file named owl_Blue_out.ppm and
mecca06_Blue_out.ppm.
e) Make each pixel of the R matrix to zero. Write the matrix of each image in a file
named owl_GreenBlue_out.ppm and mecca06_GreenBlue_out.ppm.

f) Make each pixel of the G matrix to zero. Write the matrix of each image in a file
named owl_RedBlue_out.ppm and mecca06_RedBlue_out.ppm.

g) Make each pixel of the B matrix to zero. Write the matrix of each image in a file
named owl_RedGreen_out.ppm and mecca06_RedGreen_out.ppm

h) Take the logarithm (log) of base 10 of each pixel of the three (red, green and blue)
matrices of the each images and save the matrices in the files (owl_Log_Out.ppm and
mecca06_Log_Out.ppm)

i) Generate the gray scale image of these colored images i.e., owl.ppm and mecca.ppm.
Take the average of pixels of these three matrices of each image and generate one
matrix. Later save this matrix in a file named owl_grayScale_Out.pgm and
mecca06_grayScale_Out.pgm

Report: Your report should contain your MATLAB code, the explanation of code/algorithm in
simple English, input images and output images.

If you have discussed (only discussed not copied) your assignment with any other student, then
write the name of your discussion partner in your report. The template of the assignment report is
given below with this assignment.

Report Template for Assignment-1 Solution


Discussion Partner.................................................................................................................................................
Question 1............................................................................................................................................................5
Code.................................................................................................................................................................5
Description of Code.........................................................................................................................................5
Result...............................................................................................................................................................5
Input Images....................................................................................................................................................5
Output Image...................................................................................................................................................5
Question 2............................................................................................................................................................6
Code.................................................................................................................................................................6
Description of Code.........................................................................................................................................6
Result...............................................................................................................................................................6
Input Images....................................................................................................................................................6
Output Image...................................................................................................................................................6
Question 3
Code
Description of Code
Result
Input Images
Output Image
Question 1
<Question Statement>

Code
<Write your code in italic>

Description of Code
<Describe you code/algorithm in simple plain English >

Result
<Describe the result of your code i.e., explain the output of your algorithm. Do also explain the output images that
are obtained by applying your algorithm/code to the input images.>

Input Images
<Paste your input images>
Q1

Output Image
<Paste your output images.>
Q1
Question 2
<Question Statement>

Code
<Write your code in italic>

Description of Code
<Describe you code/algorithm in simple plain English >

Result
<Describe the result of your code i.e., explain the output of your algorithm. Do also explain the output images that
are obtained by applying your algorithm/code to the input images.>

Input Images
<Paste your input images>
Q2 a) Q2 b) Q2 c) Q2 d) Q2 e)

Output Image
<Paste your output images.>
Q2 a) Q2 b) Q2 c) Q2 d) Q2 e)

You might also like