You are on page 1of 52

Workshop on Image processing

using MATLAB
Presented by
Amarjeetsingh Thakur
Asst. Professor
Dept. of Electronics & Communication
Engg.
S.G.B.I.T. Belgaum
Outline
What is MATLAB?
Image Processing tool box
Image formats
How to read an image?
Image conversion
Arithmetic operations on images
Conversion of an image into different formats
Image rotation
Image blurring and deblurring
Fill in ROI in grayscale image
References





What is MATLAB?
MATLAB = MATrix LABoratory

MATLAB is a high-level language and
interactive environment that enables us to
perform computationally intensive tasks faster
than with traditional programming languages
such as C, C++ and Fortran.

MATLAB is an interactive, interpreted language
that is designed for fast numerical matrix
calculations.
Who uses MATLAB?

Key Industries

Aerospace and defense
Automotive
Biotech and pharmaceutical
Communications
Computers
Education
Electronics and semiconductors
Energy production
Industrial automation and machinery
Medical devices

The MATLAB Environment
MATLAB window
components:
Workspace
> Displays all the defined
variables
Command Window
> To execute commands
in the MATLAB
environment
Command History
> Displays record of the
commands used
File Editor Window
> Define functions

MATLAB Help
MATLAB Help is an
extremely powerful
assistance to learning
MATLAB

Help not only contains the
theoretical background,
but also shows demos for
implementation

MATLAB Help can be
opened by using the
HELP pull-down menu
MATLAB Help (cont.)
Any command description
can be found by typing
the command in the
search field

As shown above, the
command to take square
root (sqrt) is searched

We can also utilize
MATLAB Help from the
command window as
shown
What is the Image Processing
Toolbox?
The Image Processing Toolbox is a collection of
functions that extend the capabilities of the
MATLABs numeric computing environment. The
toolbox supports a wide range of image
processing operations, including:
Geometric operations
Linear filtering and filter design
Transforms
Image analysis and enhancement
Binary image operations
Region of interest operations
Images in MATLAB
MATLAB can import/export
several image formats:
BMP (Microsoft Windows
Bitmap)
GIF (Graphics
Interchange Files)
HDF (Hierarchical Data
Format)
JPEG (Joint Photographic
Experts Group)
PCX (Paintbrush)
PNG (Portable Network
Graphics)
TIFF (Tagged Image File
Format)

Data types in MATLAB
Double (64-bit double-
precision floating point)
Single (32-bit single-
precision floating point)
Int32 (32-bit signed
integer)
Int16 (16-bit signed
integer)
Int8 (8-bit signed integer)
Uint32 (32-bit unsigned
integer)
Uint16 (16-bit unsigned
integer)
Uint8 (8-bit unsigned
integer)

Images in MATLAB
Binary images : {0,1}
Intensity images : [0,1] or uint8, double etc.
RGB images : m n 3
Multidimensional images: m n p (p is the number of layers)
Binary Images
They are also called Black & White images ,
containing 1 for white and 0(zero) for black
MATLAB code
Intensity Images
They are also called Gray Scale images ,
containging numbers in the range of 0 to 255

Indexed Images
These are the color images and also represented
as RGB image.
In RGB Images there exist three indexed images.
First image contains all the red portion of the
image, second green and third contains the blue
portion.

How to read an image??
I=imread(steve.jpg)
figure
Imshow(I)
size(I) % 295 171 3
Images and Matrices
Column 1 to 256
R
o
w

1

t
o

2
5
6

o
[0, 0]
o
[256, 256]
How to build a matrix
(or image)?
Intensity Image:

row = 256;
col = 256;
img = zeros(row, col);
img(100:105, :) = 0.5;
img(:, 100:105) = 1;
figure;
imshow(img);

Image Conversion
gray2ind - intensity image to index image
im2bw - image to binary
im2double - image to double precision
im2uint8 - image to 8-bit unsigned integers
im2uint16 - image to 16-bit unsigned integers
ind2gray - indexed image to intensity image
mat2gray - matrix to intensity image
rgb2gray - RGB image to grayscale
rgb2ind - RGB image to indexed image
Arithmetic operations on
images
1. Imadd
Syntax : Z = imadd(X,Y)
Description: Z = imadd(X,Y) adds
each element in array X with the
corresponding element in array Y and
returns the sum in the corresponding
element of the output array Z.




Figure window shows addition of
two different images
Contd..
2. imsubtract
Syntax : Z = imsubtract(X,Y)
Description: Z = imsubtract(X,Y) subtracts
each element in array Y from the
corresponding element in array X and
returns the difference in the corresponding
element of the output array Z

Figure window shows
Subtraction of two different
images
Contd..
3. immultiply
Syntax : Z = immultiply(X,Y)
Description: Z = immultiply(X,Y)
multiplies each element in array X by the
corresponding element in array Y and
returns the product in the corresponding
element of the output array Z.

Figure window shows
Multiplication of two different
images
Contd..
4. imdivide
Syntax : Z = imdivide(X,Y)
Description: Z = imdivide(X,Y) divides
each element in the array X by the
corresponding element in array Y and
returns the result in the corresponding
element of the output array Z.
Figure window shows Division of
two different images
Sample code for addition of
images (both image size is not
same)
i=imread('C:\Documents and
Settings\student\My
Documents\pictures\steve.jpg');%read an
image
size(i) %295 171 3
j=imread('C:\Documents and
Settings\student\My
Documents\pictures\sun.jpg');
size(j) %219 230 3
k=i(1:150,1:150);
l=j(1:150,1:150);
m=imadd(k,l);
figure,imshow(m)
title('addition of two images')

Figure window displaying
Addition of two images
Converting RGB image to gray
format
I=imread(Sachin.jpg'); % Read an
image
I=rgb2gray(I); % RGB to gray
conversion
figure % Figure window
imshow(I) % Display figure on
figure window

Figure window displaying Gray
image
RGB to BW image conversion
commands
I=imread('Sachin.jpg');
I=im2bw(I);
imshow(I)
Figure window shows BW
image
Image rotation by some angle
I=imread('steve.jpg');
J=imrotate(I,45); % Rotate image
anticlockwise
by an angle
45
K=imrotate(I,-45); % Rotate image
clockwise by
an angle 45
imshow(J)
Imshow(K)
Deblurring operation on an
blurred image using wiener filter
I=imread(Sachin.jpg');
figure
imshow(I)

Commands for blurring the
image
PSF=fspecial('motion');
Blurred=imfilter(I,PSF,'circular','conv');
figure, imshow(Blurred)

Blurred image
Commands for deblurring the
image
wnr1=deconvwnr(Blurred,PSF);
figure, imshow(wnr1);
title('Restored image');

Recovered image
Fill in specified region of interest
(ROI) polygon in grayscale
image

I = imread('eight.tif');
J = roifill(I);
figure, imshow(J)
ROI fill
I=imread('C:\Documents and
Settings\All
Users.WINDOWS\Documents\My
Pictures\Sample
Pictures\avataar.jpg');
figure
imshow(I)
J=rgb2gray(I);
figure
imshow(J)

ROI fill (contd..)
K = roifill(J);
figure
imshow(K)
ROI fill (contd..)
ROI fill (contd..)
Applications of image
processing
BIOLOGICAL: automated systems for analysis of
samples.
DEFENSE/INTELLIGENCE: enhancement and
interpretation of images to find and track targets.
DOCUMENT PROCESSING: scanning, archiving,
transmission.
FACTORY AUTOMATION: visual inspection of
products.
MATERIALS TESTING: detection and quantification
of cracks, impurities, etc.
MEDICAL: disease detection and monitoring,
therapy/surgery planning

ANY QUERRIES????????
References
www.mathworks.com
Digital Image Processing using
MATLAB by Rafael C. Gonzalez,
Richard E. Woods, Steven L. Eddins.
THANK YOU

You might also like