Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
30 views

Introduction To Image Processing in MATLAB

This experiment introduces various image processing techniques in MATLAB, including reading and displaying images, extracting image properties, changing color spaces, separating color channels, and performing arithmetic operations on pixels. Key functions covered are imread(), imshow(), imfinfo(), rgb2gray(), rgb2hsv(), and arithmetic operators for addition, subtraction, multiplication, and division. The document demonstrates how these tools can be used for tasks like color correction, feature extraction, image enhancement, and noise reduction.

Uploaded by

MUHAMMAD ARSLAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Introduction To Image Processing in MATLAB

This experiment introduces various image processing techniques in MATLAB, including reading and displaying images, extracting image properties, changing color spaces, separating color channels, and performing arithmetic operations on pixels. Key functions covered are imread(), imshow(), imfinfo(), rgb2gray(), rgb2hsv(), and arithmetic operators for addition, subtraction, multiplication, and division. The document demonstrates how these tools can be used for tasks like color correction, feature extraction, image enhancement, and noise reduction.

Uploaded by

MUHAMMAD ARSLAN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment

Introduction to Image Processing in MATLAB


1. Objective:
The objective of this lab report is to provide with a foundational understanding of image processing in
MATLAB, focusing on basic operations such as reading, displaying, labeling, and titling images.

2. Introduction
Image processing is a method to perform some operations on an image, in order to get an enhanced
image or to extract some useful information from it. Image processing is a crucial field with applications
ranging from medical imaging to remote sensing. MATLAB provides powerful tools and functions for
performing various image processing tasks efficiently.

2.1 Extracting Image Properties:

Iminfo: This command is used to find the image information.


Filename: This command is used to find the name of the image.
ColorType: This command is used to find the color of the image.
Width: This command is used to find the color of the image.
FileSize: This command is used to find the size of the image.
Height: This command is used to find the height of the image.

Code

a=imfinfo('C:\Users\Sawera\Desktop\img1.jpeg'); % Finding info of image


Name = a.Filename; % File Name
Color = a.ColorType; % Image Color
Width = a. Width; % Image Width
Size = a.FileSize; % File Size
Color_Depth = a.BitDepth; % Image Depth
Height = a.Height; % Image Height
Modification_Date = a.FileModDate; % Modification Date
Sample_number = a.NumberOfSamples; % Number of Sample
Coding_Method = a.CodingMethod; % Coding Method
Coding_Process = a.CodingMethod; % Coding Process

❖ Img1 is the name of file in your system

2.2 Image Acquisition:

imread: This command is used to read the image in Matlab


inshow: This command is used to display the image in Matlab
imwrite: This command is used to save the image

Code
b=imread('img1.jpeg'); % Load the image into a variable
imshow(b); % For display the image
imwrite(b, 'D:/img2.jpg','jpg'); % For saving the image with new name
imwrite(b, 'D:/img2.png','png'); % For changing the image format while saving

❖ The loaded image (img1) is stored in a variable named b


❖ Img2 is new name of file.
2.3 Displaying Images in MATLAB with Title:
In many images processing tasks, it's common to compare or visualize multiple images simultaneously.
MATLAB provides the subplot function to display multiple images within the same figure window. This is
how you can use subplot to display images side by side:

Actual filename of the image you want to load


Code
File extension / type of file
% Load sample images
img1 = imread('img1.jpeg');
img2 = imread('img2.jpeg');
img3 = imread('img3.jpg');

%How to plot multiple picture in one frame

% First image in the 1st subplot % Second image in the 2nd subplot % Third image in the 3rd subplot

subplot (1,3,1); subplot (1,3,2); subplot (1,3,3);


imshow('img1.jpeg'); imshow('img2.jpeg'); imshow('img3.jpg');
title('Image 1'); title('Image 2'); title('Image 3');

In this example, we use subplot (1, 3, 1) to create a grid of one row and three columns of subplots, and
we specify the position of each subplot using the third argument. Each subplot is then populated with
an image using imshow, and titles are added to each subplot using the title function.

2.4 Changing Color Space:


Changing color space in MATLAB can serve several purposes, depending on the specific requirements of
your image processing task like feature extraction, color correction, visualization. The LAB, HSV, and RGB
color spaces are three different ways of representing colors, each with its own characteristics and
advantages.

RGB (Red, Green, Blue): RGB is the most common color space used in digital imaging systems and
displays. In RGB, colors are represented as combinations of red, green, and blue light intensities.

HSV (Hue, Saturation, Value): HSV is often used for color-based image processing tasks, such as
segmentation, because it separates color information from intensity.

LAB (Lightness): LAB is a device-independent color space, meaning that it is not tied to specific display or
capture devices. It is often used for color correction, image processing, and color management tasks
where accurate color representation is important.

Code

% Conversion of RGB image into gray scale % Conversion of RGB image into HSC Space

original = imread ('img2.jpeg'); original = imread ('img2.jpeg');


imshow(original) imshow(original)

gray = rgb2gray (original); HSV = rgb2hsv (original);


imshow(gray) imshow(HSV)
2.5 Separating / Splitting Channels using MATLAB
Separating or splitting color channels in MATLAB can be useful for various image processing tasks and
analyses.
1. Image Enhancement: Separating color channels allows you to individually process and enhance
specific color components of an image.
2. Feature Extraction: Different color channels contain different types of information about an image.
By separating channels, you can extract specific features or characteristics from each channel.
3. Color Analysis: Separating color channels enables you to perform detailed analysis on specific color
components of an image.
4. Color Correction: Separating channels allows you to selectively modify the intensity of specific color
components to achieve the desired color balance in the final image.
5. Channel Fusion: After processing individual color channels, you can recombine them to create new
color images with enhanced or modified color characteristics.

How to remove red, green and blue effect from picture

Code
% Original RGB Image % Remove red effect from image

image =imread('img1.jpeg') image =imread('img1.jpeg')


subplot(1,4,1); red_channel = image(:, :, 1)
imshow(image); subplot(1,4,1);
title("Original Image") imshow(red_channel);
title ("Red Channel")

% Remove green effect from image % Remove blue effect from image

image =imread('img1.jpeg'); image =imread('img1.jpeg')


green_channel = image (:, :, 2) blue_channel = image (:, :, 3)
subplot(1,4,1); subplot(1,4,1);
imshow(green_channel); imshow(blue_channel);
title ("Green Channel ") title ("Blue Channel")

❖ (:,:,1) extracts the red channel from the RGB image


❖ (:,:,2) extracts the red channel from the RGB image
❖ (:,:,3) extracts the red channel from the RGB image

Output
2.6 Arithmetic operation on image using MATLAB
Performing arithmetic operations on images using MATLAB allows you to manipulate pixel values to
achieve various effects or perform specific tasks.

❖ Imadd Command is used to add pixels.


❖ + is use for addition
❖ - is used to subtraction
❖ .* is used to multiply two images
❖ ./ is use for division
❖ Immultiply: multiply image with an integer.
❖ Imdivide: divide the image with an integer.

Adding Pixel Values using MATLAB


Image Enhancement: Increasing the number of pixels in an image can enhance its quality, especially when
upscaling a low-resolution image. By adding more pixels through interpolation, the image can appear
smoother, brighter and contain more details.

Code
image=imread('img1.jpeg');

adding_50 = imadd(image, 50);


adding_100 = imadd(image, 100);
adding_200 = imadd(image, 200);

subplot(2,2,1), imshow(image); title('Original Image');


subplot(2,2,2), imshow(adding_50); title('After Adding 50');
subplot(2,2,3), imshow(adding_100); title('After Adding 100');
subplot(2,2,4), imshow(adding_200); title('After Adding 200');

Addition, Subtraction, Multiplication, Addition on image in MATLAB

Image Fusion: Addition and subtraction operations are commonly used in image fusion techniques to
combine information from multiple images into a single image.

Noise Reduction: Multiplication and division operations can be used to reduce noise in images.
Multiplying an image by a constant value can amplify the signal-to-noise ratio thus increasing the contrast,
while dividing by a constant can attenuate noise.
Code
image_1 = imread('image1.jpeg'); subplot(1,6,1); imshow(image_1);
image_2 = imread('image2.jpeg'); subplot(1,6,2); imshow(image_2)
image_addition = image_1 + image_2; subplot(1,6,3); imshow(image_addition)
image_subtract = image_1 - image_2; subplot(1,6,4); imshow(image_subtraction)
image_multiply = image_1 .* image_2; subplot(1,6,5); imshow(image_multiplication)
image_division = image_1 ./ image_2; subplot(1,6,6); imshow(image_division)

image=imread('image1.jpeg'); subplot(2,2,1); imshow(image); title('Original Image');


image_multiply=immultiply(image, 1.5);subplot(2,2,2);imshow(image_multiply);title('Multiplied);
image_division=imdivide(image, 4);subplot(2,2,3);imshow(image_division);title('Dividied');

You might also like