SlideShare a Scribd company logo
MATLAB WORKSHOP

   FOR
    EE, ECE, CS, Geophysics, B
    ioinformatics, Mechanical
    Engineering
Outline

• Introduction to MATLAB
  – Basics & Examples


• Image Processing with MATLAB
  – Basics & Examples
What is MATLAB?
• MATLAB = Matrix Laboratory

• “MATLAB is a high-level language and
  interactive environment that enables you to
  perform computationally intensive tasks faster
  than with traditional programming languages
  such as C, C++ and Fortran.”
  (www.mathworks.com)

• MATLAB is an interactive, interpreted language
  that is designed for fast numerical matrix
  calculations
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 your 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
More about the Workspace
• who, whos – current variables in the
  workspace
• save – save workspace variables to *.mat
  file
• load – load variables from *.mat file
• clear – clear workspace variables

- CODE
Matrices in MATLAB
• Matrix is the main MATLAB data type
• How to build a matrix?
  – A=[1 2 3; 4 5 6; 7 8 9];
  – Creates matrix A of size 3 x 3
• Special matrices:
  – zeros(n,m), ones(n,m), eye(n,m), r
    and(), randn()
Basic Operations on Matrices
• All operators in MATLAB are defined on
  matrices: +, -
  , *, /, ^, sqrt, sin, cos, etc.
• Element-wise operators defined with a
  preceding dot: .*, ./, .^
• size(A) – size vector
• sum(A) – columns’ sums vector
• sum(sum(A)) – sum of all the elements
- CODE
Variable Name in Matlab
• Variable naming rules
       - must be unique in the first 63 characters
       - must begin with a letter
       - may not contain blank spaces or other types of punctuation
      - may contain any combination of letters, digits, and
  underscores
       - are case-sensitive
       - should not use Matlab keyword
• Pre-defined variable names
    • pi
Logical Operators

• ==, <, >, (not equal) ~=, (not) ~

• find(‘condition’) – Returns indexes
  of A’s elements that satisfy the condition
Logical Operators (cont.)
• Example:
>>A=[7 3 5; 6 2 1], Idx=find(A<4)
 A=
      7 3 5
      6 2 1
 Idx=
      3
      4
      6
Flow Control
• MATLAB has five flow control constructs:
  – if statement
  – switch statement
  – for loop
  – while loop
  – break statement
if
• IF statement condition
  – The general form of the IF statement is
     IF expression
       statements
     ELSEIF expression
       statements
     ELSE
       statements
     END
switch
• SWITCH – Switch among several cases based
  on expression
• The general form of SWITCH statement is:
  SWITCH switch_expr
     CASE case_expr,
        statement, …, statement
     CASE {case_expr1, case_expr2, case_expr3, …}
        statement, …, statement
        …
     OTHERWISE
        statement, …, statement
  END
switch (cont.)
• Note:
  – Only the statements between the matching
    CASE and the next CASE, OTHERWISE, or END
    are executed
  – Unlike C, the SWITCH statement does not fall
    through (so BREAKs are unnecessary)
for
• FOR repeats statements a specific
  number of times

• The general form of a FOR statement is:
  FOR variable=expr
    statements
  END
Code
   Assume k has already been assigned a value.
    Create the Hilbert matrix, using zeros to
    preallocate the matrix to conserve memory:
    a = zeros(k,k) % Preallocate matrix
    for m = 1:k
       for n = 1:k
          a(m,n) = 1/(m+n -1);
       end
    end
while
• WHILE repeats statements an indefinite
  number of times
• The general form of a WHILE statement is:
  WHILE expression
    statements
  END
Scripts and Functions
• There are two kinds of M-files:

  – Scripts, which do not accept input arguments
    or return output arguments. They operate on
    data in the workspace


  – Functions, which can accept input arguments
    and return output arguments. Internal
    variables are local to the function
Functions in MATLAB (cont.)
• Example:
   – A file called STAT.M:
       function [mean, stdev]=stat(x)
       %STAT Interesting statistics.
       n=length(x);
       mean=sum(x)/n;
       stdev=sqrt(sum((x-mean).^2)/n);
   – Defines a new function called STAT that calculates
     the mean and standard deviation of a vector. Function
     name and file name should be the SAME!
Visualization and Graphics
•   plot(x,y),plot(x,sin(x)) – plot 1D function
•   figure, figure(k) – open a new figure
•   hold on, hold off – refreshing
•   axis([xmin xmax ymin ymax]) – change axes
•   title(‘figure titile’) – add title to figure
•   mesh(x_ax,y_ax,z_mat) – view surface
•   contour(z_mat) – view z as topo map
•   subplot(3,1,2) – locate several plots in figure
Saving your Work
• save mysession
     % creates mysession.mat with all variables
• save mysession a b
     % save only variables a and b
• clear all
     % clear all variables
• clear a b
     % clear variables a and b
• load mysession
     % load session
Outline

• Introduction to MATLAB
  – Basics & Examples


• Image Processing with MATLAB
  – Basics & Examples
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
   –   Neighborhood and block 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            • Data types in MATLAB
  several image formats:                 – Double (64-bit double-precision
   – BMP (Microsoft Windows                floating point)
     Bitmap)                             – Single (32-bit single-precision
   – GIF (Graphics Interchange             floating point)
     Files)                              – Int32 (32-bit signed integer)
   – HDF (Hierarchical Data Format)      – Int16 (16-bit signed integer)
   – JPEG (Joint Photographic            – Int8 (8-bit signed integer)
     Experts Group)                      – Uint32 (32-bit unsigned integer)
   – PCX (Paintbrush)                    – Uint16 (16-bit unsigned integer)
   – PNG (Portable Network               – Uint8 (8-bit unsigned integer)
     Graphics)
   – TIFF (Tagged Image File
     Format)
   – XWD (X Window Dump)
   – raw-data and other types of
     image data
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)
Image Import and Export
• Read and write images in Matlab
   img = imread('apple.jpg');
   dim = size(img);
   figure;
   imshow(img);
   imwrite(img, 'output.bmp', 'bmp');

• Alternatives to imshow
   imagesc(I)
   imtool(I)
   image(I)
Images and Matrices
                                                   [0, 0]
How to build a matrix
(or image)?                             o
Intensity Image:




                         Row 1 to 256
row = 256;
col = 256;
img = zeros(row, col);
img(100:105, :) = 0.5;
img(:, 100:105) = 1;
figure;
                                                                    o
imshow(img);
                                            Column 1 to 256
                                                              [256, 256]
Images and Matrices
Binary Image:

row = 256;
col = 256;
img = rand(row,
col);
img = round(img);
figure;
imshow(img);
Image Display
•   image - create and display image object
•   imagesc - scale and display as image
•   imshow - display image
•   colorbar - display colorbar
•   getimage - get image data from axes
•   truesize - adjust display size of image
•   zoom - zoom in and zoom out of 2D plot
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
Image Operations
•   RGB image to gray image
•   Image resize
•   Image crop
•   Image rotate
•   Image histogram
•   Image histogram equalization
•   Image DCT/IDCT
•   Convolution
Outline

• Introduction to MATLAB
  – Basics & Examples
• Image Processing with MATLAB
  – Basics & Examples
Examples working with Images
           (1/2)
         Blending two images
Examples working with Images
           (2/2)
     Sobel descriptor to detect object edge
Performance Issues
•   The idea: MATLAB is
    – very fast on vector and matrix operations
    – Correspondingly slow with loops



•   Try to avoid loops
•   Try to vectorize your code
    http://www.mathworks.com/support/tech-
    notes/1100/1109.html
Vectorize Loops
•   Example
     – Given image matrices, A and B, of the same size (540*380), blend
       these two images
       apple = imread(‘apple.jpg');
       orange = imread(‘orange.jpg’);
•   Poor Style
      % measure performance using stopwatch timer
      tic
      for i = 1 : size(apple, 1)
         for j = 1 : size(apple, 2)
                for k = 1 : size(apple, 3)
                      output(i, j, k) = (apple(i, j, k) +
    orange(i, j, k))/2;
                end
         end
      end
      toc
•   Elapsed time is 0.138116 seconds
Vectorize Loops (cont.)
•   Example
     –   Given image matrices, A and B, of the same size (600*400), blend
         these two images
         apple = imread(‘apple.jpg');
         orange = imread(‘orange.jpg’);

•   Better Style
     tic % measure performance using stopwatch timer
     Output = (apple + orange)/2;
     toc
     •   Elapsed time is 0.099802 seconds

•   Computation is faster!
THE END

• Thanks for your attention! 

• Questions?

More Related Content

What's hot

03 digital image fundamentals DIP
03 digital image fundamentals DIP03 digital image fundamentals DIP
03 digital image fundamentals DIP
babak danyal
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
Sanu Philip
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Shaleen Saini
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithm
KKARUNKARTHIK
 
Lecture 4 Relationship between pixels
Lecture 4 Relationship between pixelsLecture 4 Relationship between pixels
Lecture 4 Relationship between pixels
VARUN KUMAR
 
Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...
Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...
Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...
Ulaş Bağcı
 
Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
chauhankapil
 
Chapter-05c-Image-Restoration-(Reconstruction-from-Projections).ppt
Chapter-05c-Image-Restoration-(Reconstruction-from-Projections).pptChapter-05c-Image-Restoration-(Reconstruction-from-Projections).ppt
Chapter-05c-Image-Restoration-(Reconstruction-from-Projections).ppt
VSUDHEER4
 
Concept of basic illumination model
Concept of basic illumination modelConcept of basic illumination model
Concept of basic illumination model
Ankit Garg
 
IMAGE SEGMENTATION TECHNIQUES
IMAGE SEGMENTATION TECHNIQUESIMAGE SEGMENTATION TECHNIQUES
IMAGE SEGMENTATION TECHNIQUES
Vicky Kumar
 
Fundamentals steps in Digital Image processing
Fundamentals steps in Digital Image processingFundamentals steps in Digital Image processing
Fundamentals steps in Digital Image processing
KarthicaMarasamy
 
6.frequency domain image_processing
6.frequency domain image_processing6.frequency domain image_processing
6.frequency domain image_processing
Nashid Alam
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphicsAmandeep Kaur
 
Image Acquisition
Image AcquisitionImage Acquisition
Image Acquisition
shail288
 
Basics of pixel neighbor.
Basics of pixel neighbor.Basics of pixel neighbor.
Basics of pixel neighbor.
raheel rajput
 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Image Processing and Computer Vision
Image Processing and Computer VisionImage Processing and Computer Vision
Image Processing and Computer Vision
Silicon Mentor
 

What's hot (20)

03 digital image fundamentals DIP
03 digital image fundamentals DIP03 digital image fundamentals DIP
03 digital image fundamentals DIP
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithm
 
Lecture 4 Relationship between pixels
Lecture 4 Relationship between pixelsLecture 4 Relationship between pixels
Lecture 4 Relationship between pixels
 
Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...
Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...
Lec7: Medical Image Segmentation (I) (Radiology Applications of Segmentation,...
 
Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
 
Chapter-05c-Image-Restoration-(Reconstruction-from-Projections).ppt
Chapter-05c-Image-Restoration-(Reconstruction-from-Projections).pptChapter-05c-Image-Restoration-(Reconstruction-from-Projections).ppt
Chapter-05c-Image-Restoration-(Reconstruction-from-Projections).ppt
 
Concept of basic illumination model
Concept of basic illumination modelConcept of basic illumination model
Concept of basic illumination model
 
IMAGE SEGMENTATION TECHNIQUES
IMAGE SEGMENTATION TECHNIQUESIMAGE SEGMENTATION TECHNIQUES
IMAGE SEGMENTATION TECHNIQUES
 
Fundamentals steps in Digital Image processing
Fundamentals steps in Digital Image processingFundamentals steps in Digital Image processing
Fundamentals steps in Digital Image processing
 
6.frequency domain image_processing
6.frequency domain image_processing6.frequency domain image_processing
6.frequency domain image_processing
 
Ray tracing
 Ray tracing Ray tracing
Ray tracing
 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
 
Mathematical tools in dip
Mathematical tools in dipMathematical tools in dip
Mathematical tools in dip
 
Image Acquisition
Image AcquisitionImage Acquisition
Image Acquisition
 
Basics of pixel neighbor.
Basics of pixel neighbor.Basics of pixel neighbor.
Basics of pixel neighbor.
 
Illumination Models & Shading
Illumination Models & ShadingIllumination Models & Shading
Illumination Models & Shading
 
Image Processing and Computer Vision
Image Processing and Computer VisionImage Processing and Computer Vision
Image Processing and Computer Vision
 
Lecture24
Lecture24Lecture24
Lecture24
 

Viewers also liked

Basics of Image Processing using MATLAB
Basics of Image Processing using MATLABBasics of Image Processing using MATLAB
Basics of Image Processing using MATLABvkn13
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
Muhammad Rizwan
 
Digital image processing using matlab
Digital image processing using matlab Digital image processing using matlab
Digital image processing using matlab
Amr Rashed
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
ideas2ignite
 
Introduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABIntroduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLAB
Ray Phan
 
Matlab training workshop for freshers
Matlab training workshop for freshersMatlab training workshop for freshers
Matlab training workshop for freshers
Multisoft Systems
 
Two Days workshop on MATLAB
Two Days workshop on MATLABTwo Days workshop on MATLAB
Two Days workshop on MATLABBhavesh Shah
 
Multi Processor Architecture for image processing
Multi Processor Architecture for image processingMulti Processor Architecture for image processing
Multi Processor Architecture for image processingideas2ignite
 
Brendan_Salmond_Resume_2015_V4
Brendan_Salmond_Resume_2015_V4Brendan_Salmond_Resume_2015_V4
Brendan_Salmond_Resume_2015_V4Brendan Salmond
 
Introduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab ToolboxIntroduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab Toolbox
Shahriar Yazdipour
 
Image Processing Using MATLAB
Image Processing Using MATLABImage Processing Using MATLAB
Image Processing Using MATLAB
Amarjeetsingh Thakur
 
Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG
Sulaf Almagooshi
 
Brainstorming and MATLAB report
Brainstorming and MATLAB reportBrainstorming and MATLAB report
Brainstorming and MATLAB reportTommy Reynolds
 
Mechanical design of mems gyroscopes
Mechanical design of mems gyroscopesMechanical design of mems gyroscopes
Mechanical design of mems gyroscopesAhmed El-Sayed
 
ÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICS
ÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICSÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICS
ÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICS
Ali Osman Öncel
 
Reduction of gravity data
Reduction of gravity dataReduction of gravity data
Reduction of gravity data
Amin khalil
 
Solving dynamics problems with matlab
Solving dynamics problems with matlabSolving dynamics problems with matlab
Solving dynamics problems with matlab
Sérgio Castilho
 

Viewers also liked (20)

Basics of Image Processing using MATLAB
Basics of Image Processing using MATLABBasics of Image Processing using MATLAB
Basics of Image Processing using MATLAB
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Digital image processing using matlab
Digital image processing using matlab Digital image processing using matlab
Digital image processing using matlab
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
ADVANCED WORKSHOP IN MATLAB
ADVANCED WORKSHOP IN MATLABADVANCED WORKSHOP IN MATLAB
ADVANCED WORKSHOP IN MATLAB
 
Introduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABIntroduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLAB
 
Matlab training workshop for freshers
Matlab training workshop for freshersMatlab training workshop for freshers
Matlab training workshop for freshers
 
Two Days workshop on MATLAB
Two Days workshop on MATLABTwo Days workshop on MATLAB
Two Days workshop on MATLAB
 
Multi Processor Architecture for image processing
Multi Processor Architecture for image processingMulti Processor Architecture for image processing
Multi Processor Architecture for image processing
 
Brendan_Salmond_Resume_2015_V4
Brendan_Salmond_Resume_2015_V4Brendan_Salmond_Resume_2015_V4
Brendan_Salmond_Resume_2015_V4
 
Introduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab ToolboxIntroduction in Image Processing Matlab Toolbox
Introduction in Image Processing Matlab Toolbox
 
Image Processing Using MATLAB
Image Processing Using MATLABImage Processing Using MATLAB
Image Processing Using MATLAB
 
Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG Matlab and Image Processing Workshop-SKERG
Matlab and Image Processing Workshop-SKERG
 
Brainstorming and MATLAB report
Brainstorming and MATLAB reportBrainstorming and MATLAB report
Brainstorming and MATLAB report
 
Mechanical design of mems gyroscopes
Mechanical design of mems gyroscopesMechanical design of mems gyroscopes
Mechanical design of mems gyroscopes
 
Matlab
MatlabMatlab
Matlab
 
ÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICS
ÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICSÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICS
ÖNCEL AKADEMİ: INTRODUCTION TO GEOPHYSICS
 
Mechanics 3
Mechanics 3Mechanics 3
Mechanics 3
 
Reduction of gravity data
Reduction of gravity dataReduction of gravity data
Reduction of gravity data
 
Solving dynamics problems with matlab
Solving dynamics problems with matlabSolving dynamics problems with matlab
Solving dynamics problems with matlab
 

Similar to MATLAB & Image Processing

Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
ssuserff72e4
 
Matlab intro
Matlab introMatlab intro
Matlab introfvijayami
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
Vinay Kumar
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
AkashSingh728626
 
Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
Austin Baird
 
INTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.pptINTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.ppt
Karthik537368
 
Image processing
Image processingImage processing
Image processing
Pooya Sagharchiha
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
aboma2hawi
 
MATLAB workshop lecture 1MATLAB work.ppt
MATLAB workshop lecture 1MATLAB work.pptMATLAB workshop lecture 1MATLAB work.ppt
MATLAB workshop lecture 1MATLAB work.ppt
ssuserdee4d8
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
RaviMuthamala1
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islamIslam Alabbasy
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
Smee Kaem Chann
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
Faizan Shabbir
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabSantosh V
 
Matlab_Harshal.pptx
Matlab_Harshal.pptxMatlab_Harshal.pptx
Matlab_Harshal.pptx
HarshalGosavi8
 
Basic concept of MATLAB.ppt
Basic concept of MATLAB.pptBasic concept of MATLAB.ppt
Basic concept of MATLAB.ppt
aliraza2732
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 

Similar to MATLAB & Image Processing (20)

Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Mit6 094 iap10_lec05
Mit6 094 iap10_lec05Mit6 094 iap10_lec05
Mit6 094 iap10_lec05
 
Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
 
INTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.pptINTRODUCTION TO MATLAB for PG students.ppt
INTRODUCTION TO MATLAB for PG students.ppt
 
Image processing
Image processingImage processing
Image processing
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
 
MATLAB workshop lecture 1MATLAB work.ppt
MATLAB workshop lecture 1MATLAB work.pptMATLAB workshop lecture 1MATLAB work.ppt
MATLAB workshop lecture 1MATLAB work.ppt
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
Intro matlab
Intro matlabIntro matlab
Intro matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab_Harshal.pptx
Matlab_Harshal.pptxMatlab_Harshal.pptx
Matlab_Harshal.pptx
 
Basic concept of MATLAB.ppt
Basic concept of MATLAB.pptBasic concept of MATLAB.ppt
Basic concept of MATLAB.ppt
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 

Recently uploaded

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

MATLAB & Image Processing

  • 1. MATLAB WORKSHOP  FOR EE, ECE, CS, Geophysics, B ioinformatics, Mechanical Engineering
  • 2. Outline • Introduction to MATLAB – Basics & Examples • Image Processing with MATLAB – Basics & Examples
  • 3. What is MATLAB? • MATLAB = Matrix Laboratory • “MATLAB is a high-level language and interactive environment that enables you to perform computationally intensive tasks faster than with traditional programming languages such as C, C++ and Fortran.” (www.mathworks.com) • MATLAB is an interactive, interpreted language that is designed for fast numerical matrix calculations
  • 4. 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 your functions
  • 5. 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
  • 6. 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
  • 7. More about the Workspace • who, whos – current variables in the workspace • save – save workspace variables to *.mat file • load – load variables from *.mat file • clear – clear workspace variables - CODE
  • 8. Matrices in MATLAB • Matrix is the main MATLAB data type • How to build a matrix? – A=[1 2 3; 4 5 6; 7 8 9]; – Creates matrix A of size 3 x 3 • Special matrices: – zeros(n,m), ones(n,m), eye(n,m), r and(), randn()
  • 9. Basic Operations on Matrices • All operators in MATLAB are defined on matrices: +, - , *, /, ^, sqrt, sin, cos, etc. • Element-wise operators defined with a preceding dot: .*, ./, .^ • size(A) – size vector • sum(A) – columns’ sums vector • sum(sum(A)) – sum of all the elements - CODE
  • 10. Variable Name in Matlab • Variable naming rules - must be unique in the first 63 characters - must begin with a letter - may not contain blank spaces or other types of punctuation - may contain any combination of letters, digits, and underscores - are case-sensitive - should not use Matlab keyword • Pre-defined variable names • pi
  • 11. Logical Operators • ==, <, >, (not equal) ~=, (not) ~ • find(‘condition’) – Returns indexes of A’s elements that satisfy the condition
  • 12. Logical Operators (cont.) • Example: >>A=[7 3 5; 6 2 1], Idx=find(A<4) A= 7 3 5 6 2 1 Idx= 3 4 6
  • 13. Flow Control • MATLAB has five flow control constructs: – if statement – switch statement – for loop – while loop – break statement
  • 14. if • IF statement condition – The general form of the IF statement is IF expression statements ELSEIF expression statements ELSE statements END
  • 15. switch • SWITCH – Switch among several cases based on expression • The general form of SWITCH statement is: SWITCH switch_expr CASE case_expr, statement, …, statement CASE {case_expr1, case_expr2, case_expr3, …} statement, …, statement … OTHERWISE statement, …, statement END
  • 16. switch (cont.) • Note: – Only the statements between the matching CASE and the next CASE, OTHERWISE, or END are executed – Unlike C, the SWITCH statement does not fall through (so BREAKs are unnecessary)
  • 17. for • FOR repeats statements a specific number of times • The general form of a FOR statement is: FOR variable=expr statements END
  • 18. Code  Assume k has already been assigned a value. Create the Hilbert matrix, using zeros to preallocate the matrix to conserve memory: a = zeros(k,k) % Preallocate matrix for m = 1:k for n = 1:k a(m,n) = 1/(m+n -1); end end
  • 19. while • WHILE repeats statements an indefinite number of times • The general form of a WHILE statement is: WHILE expression statements END
  • 20. Scripts and Functions • There are two kinds of M-files: – Scripts, which do not accept input arguments or return output arguments. They operate on data in the workspace – Functions, which can accept input arguments and return output arguments. Internal variables are local to the function
  • 21. Functions in MATLAB (cont.) • Example: – A file called STAT.M: function [mean, stdev]=stat(x) %STAT Interesting statistics. n=length(x); mean=sum(x)/n; stdev=sqrt(sum((x-mean).^2)/n); – Defines a new function called STAT that calculates the mean and standard deviation of a vector. Function name and file name should be the SAME!
  • 22. Visualization and Graphics • plot(x,y),plot(x,sin(x)) – plot 1D function • figure, figure(k) – open a new figure • hold on, hold off – refreshing • axis([xmin xmax ymin ymax]) – change axes • title(‘figure titile’) – add title to figure • mesh(x_ax,y_ax,z_mat) – view surface • contour(z_mat) – view z as topo map • subplot(3,1,2) – locate several plots in figure
  • 23. Saving your Work • save mysession % creates mysession.mat with all variables • save mysession a b % save only variables a and b • clear all % clear all variables • clear a b % clear variables a and b • load mysession % load session
  • 24. Outline • Introduction to MATLAB – Basics & Examples • Image Processing with MATLAB – Basics & Examples
  • 25. 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 – Neighborhood and block operations – Linear filtering and filter design – Transforms – Image analysis and enhancement – Binary image operations – Region of interest operations
  • 26. Images in MATLAB • MATLAB can import/export • Data types in MATLAB several image formats: – Double (64-bit double-precision – BMP (Microsoft Windows floating point) Bitmap) – Single (32-bit single-precision – GIF (Graphics Interchange floating point) Files) – Int32 (32-bit signed integer) – HDF (Hierarchical Data Format) – Int16 (16-bit signed integer) – JPEG (Joint Photographic – Int8 (8-bit signed integer) Experts Group) – Uint32 (32-bit unsigned integer) – PCX (Paintbrush) – Uint16 (16-bit unsigned integer) – PNG (Portable Network – Uint8 (8-bit unsigned integer) Graphics) – TIFF (Tagged Image File Format) – XWD (X Window Dump) – raw-data and other types of image data
  • 27. 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)
  • 28. Image Import and Export • Read and write images in Matlab img = imread('apple.jpg'); dim = size(img); figure; imshow(img); imwrite(img, 'output.bmp', 'bmp'); • Alternatives to imshow imagesc(I) imtool(I) image(I)
  • 29. Images and Matrices [0, 0] How to build a matrix (or image)? o Intensity Image: Row 1 to 256 row = 256; col = 256; img = zeros(row, col); img(100:105, :) = 0.5; img(:, 100:105) = 1; figure; o imshow(img); Column 1 to 256 [256, 256]
  • 30. Images and Matrices Binary Image: row = 256; col = 256; img = rand(row, col); img = round(img); figure; imshow(img);
  • 31. Image Display • image - create and display image object • imagesc - scale and display as image • imshow - display image • colorbar - display colorbar • getimage - get image data from axes • truesize - adjust display size of image • zoom - zoom in and zoom out of 2D plot
  • 32. 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
  • 33. Image Operations • RGB image to gray image • Image resize • Image crop • Image rotate • Image histogram • Image histogram equalization • Image DCT/IDCT • Convolution
  • 34. Outline • Introduction to MATLAB – Basics & Examples • Image Processing with MATLAB – Basics & Examples
  • 35. Examples working with Images (1/2) Blending two images
  • 36. Examples working with Images (2/2) Sobel descriptor to detect object edge
  • 37. Performance Issues • The idea: MATLAB is – very fast on vector and matrix operations – Correspondingly slow with loops • Try to avoid loops • Try to vectorize your code http://www.mathworks.com/support/tech- notes/1100/1109.html
  • 38. Vectorize Loops • Example – Given image matrices, A and B, of the same size (540*380), blend these two images apple = imread(‘apple.jpg'); orange = imread(‘orange.jpg’); • Poor Style % measure performance using stopwatch timer tic for i = 1 : size(apple, 1) for j = 1 : size(apple, 2) for k = 1 : size(apple, 3) output(i, j, k) = (apple(i, j, k) + orange(i, j, k))/2; end end end toc • Elapsed time is 0.138116 seconds
  • 39. Vectorize Loops (cont.) • Example – Given image matrices, A and B, of the same size (600*400), blend these two images apple = imread(‘apple.jpg'); orange = imread(‘orange.jpg’); • Better Style tic % measure performance using stopwatch timer Output = (apple + orange)/2; toc • Elapsed time is 0.099802 seconds • Computation is faster!
  • 40. THE END • Thanks for your attention!  • Questions?