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
MATLAB’s 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
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
Row1to256
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 = immultiply(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
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','con
v');
 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
SettingsAll
Users.WINDOWSDocumentsMy
PicturesSample
Picturesavataar.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

Image Processing Using MATLAB

  • 1.
    Workshop on “Imageprocessing using MATLAB” Presented by Amarjeetsingh Thakur Asst. Professor Dept. of Electronics & Communication Engg. S.G.B.I.T. Belgaum
  • 2.
    Outline  What isMATLAB?  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
  • 3.
    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.
  • 4.
  • 5.
    Key Industries  Aerospaceand defense  Automotive  Biotech and pharmaceutical  Communications  Computers  Education  Electronics and semiconductors  Energy production  Industrial automation and machinery  Medical devices
  • 6.
    The MATLAB Environment MATLABwindow 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
  • 7.
    MATLAB Help • MATLABHelp 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
  • 8.
    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
  • 9.
    What is theImage Processing Toolbox? • The Image Processing Toolbox is a collection of functions that extend the capabilities of the MATLAB’s 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
  • 10.
    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
  • 11.
    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)
  • 12.
    Binary Images  Theyare also called “ Black & White ” images , containing ‘1’ for white and ‘0’(zero) for black  MATLAB code
  • 13.
    Intensity Images  Theyare also called ‘ Gray Scale images ’ , containging numbers in the range of 0 to 255
  • 14.
    Indexed Images  Theseare 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.
  • 15.
    How to readan image?? I=imread(‘steve.jpg’) figure Imshow(I) size(I) % 295 171 3
  • 17.
    Images and Matrices Column1 to 256 Row1to256 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);
  • 18.
    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
  • 19.
    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.
  • 20.
    Figure window showsaddition of two different images
  • 21.
    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
  • 22.
    Figure window shows Subtractionof two different images
  • 23.
    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.
  • 24.
    Figure window shows Multiplicationof two different images
  • 25.
    Contd.. 4. imdivide Syntax :Z = immultiply(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.
  • 26.
    Figure window showsDivision of two different images
  • 27.
    Converting RGB imageto 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
  • 28.
  • 29.
    RGB to BWimage conversion commands  i=imread('Sachin.jpg');  I=im2bw(I);  imshow(I)
  • 30.
  • 31.
    Image rotation bysome 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)
  • 33.
    Deblurring operation onan blurred image using wiener filter  I=imread(‘Sachin.jpg');  figure  imshow(I)
  • 34.
    Commands for blurringthe image  PSF=fspecial('motion');  Blurred=imfilter(I,PSF,'circular','con v');  figure, imshow(Blurred)
  • 35.
  • 36.
    Commands for deblurringthe image  wnr1=deconvwnr(Blurred,PSF);  figure, imshow(wnr1);  title('Restored image');
  • 37.
  • 38.
    Fill in specifiedregion of interest (ROI) polygon in grayscale image I = imread('eight.tif'); J = roifill(I); figure, imshow(J)
  • 42.
  • 44.
    ROI fill (contd..) K = roifill(J);  figure  imshow(K)
  • 45.
  • 46.
  • 47.
    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
  • 48.
  • 49.
    References  www.mathworks.com  “DigitalImage Processing using MATLAB” by Rafael C. Gonzalez, Richard E. Woods, Steven L. Eddins.
  • 50.

Editor's Notes