0% found this document useful (0 votes)
15 views4 pages

Dip Assignment No 1 21mdbs170

Uploaded by

madilscs129
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)
15 views4 pages

Dip Assignment No 1 21mdbs170

Uploaded by

madilscs129
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/ 4

University of Engineering & Technology, Mardan Department of

Computer Science

Assignment # 01 Name: Muhammad Shamil

Semester: 7th Reg No: 21MDBCS170


Subject: Digital Image Processing Due date: 15-10-2024

Explore the following concepts in MATLAB using different examples


i. The MATLAB Environment
ii. Matrices in MATLAB
iii. Basic Operations on Matrices
iv. Variable Name in Matlab
v. Logical Operators
vi. Flow Control
vii. Reading and displaying an image in MATLAB
viii. Taking computing the negative of an image
ix. Cropping out a portion of an image
x. Converting an RGB image to grayscale
xi. Adding and averaging multiple images of the same scene to remove noise.
xii. Change detection in scene using subtraction of images.
Ans:
Sure! Let’s explore each of these concepts in MATLAB with examples and explanations.
i. The MATLAB Environment
The MATLAB environment consists of several key components:
 Command Window: Where you can execute commands and see outputs.
 Workspace: Displays all the variables in memory.
 Editor: For writing and editing scripts and functions.
 Figure Window: For visualizing plots and graphics.
Example: Open MATLAB and type disp('Hello, MATLAB!') in the Command Window to print a
message.
ii. Matrices in MATLAB
MATLAB is fundamentally designed for matrix operations. You can create matrices using square
brackets.
A = [1, 2, 3; 4, 5, 6; 7, 8, 9];
This creates a 3x3 matrix.
iii. Basic Operations on Matrices
You can perform various operations like addition, subtraction, multiplication, and division.
Example:
B = [9, 8, 7; 6, 5, 4; 3, 2, 1];
C = A + B; % Matrix addition
D = A * B; % Matrix multiplication
iv. Variable Name in MATLAB
Variable names must start with a letter and can contain letters, numbers, and underscores.
They are case-sensitive.
Example:
myVariable = 10;
var_2 = [1, 2, 3];
v. Logical Operators
Logical operators (&&, ||, ~, etc.) are used to perform logical operations on arrays or variables.
Example:
x = 5;
y = 10;
result = (x < 10) && (y > 5); % result will be true
vi. Flow Control
MATLAB supports conditional statements (if, else, elseif) and loops (for, while).
Example:
for i = 1:5
disp(['Iteration: ', num2str(i)]);
end
vii. Reading and Displaying an Image in MATLAB
You can read an image using imread() and display it using imshow().
Example:
img = imread('image.jpg'); % Replace with your image file
imshow(img);
viii. Taking Computing the Negative of an Image
To compute the negative, subtract pixel values from 255 for grayscale images.
Example:
negative_img = 255 - img; % Works for grayscale images
imshow(negative_img);
ix. Cropping Out a Portion of an Image
You can crop an image by specifying the row and column indices.
Example:
cropped_img = img(100:200, 150:250, :); % Crops from row 100 to 200 and column 150 to 250
imshow(cropped_img);
x. Converting an RGB Image to Grayscale
Use rgb2gray() to convert an RGB image to grayscale.
Example:
gray_img = rgb2gray(img);
imshow(gray_img);
xi. Adding and Averaging Multiple Images to Remove Noise
To reduce noise, average several images of the same scene.
Example:
img1 = imread('image1.jpg');
img2 = imread('image2.jpg');
img3 = imread('image3.jpg');
avg_img = (double(img1) + double(img2) + double(img3)) / 3;
avg_img = uint8(avg_img); % Convert back to uint8
imshow(avg_img);
xii. Change Detection in Scene Using Subtraction of Images
Change detection can be performed by subtracting two images and thresholding.
Example:
img_before = imread('scene_before.jpg');
img_after = imread('scene_after.jpg');
change_detected = abs(double(img_after) - double(img_before));
change_detected = uint8(change_detected);
imshow(change_detected);
Summary
These examples provide a brief overview of various fundamental concepts in MATLAB, from
working with matrices to image processing techniques. You can explore each of these concepts
further by experimenting with different images and matrix operations!

You might also like