Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab
Matlab Image Processing
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
StatLab Workshop Yale University Maximiliano Appendino, Economics October 18 th, 2013.
Lecture 5.
Introduction to MATLAB The language of Technical Computing.
Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
Image Processing with MATLAB
Introduction to Matlab
Introduction to MATLAB
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
CS231A Matlab Tutorial Philip Lee Winter Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
Introduction to MATLAB ES 156 Signals and Systems 2008 Harvard SEAS.
Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.
Digital Image Processing Lecture3: Introduction to MATLAB.
MATLAB for Image Processing CS638-1 TA: Tuo Wang Feb 12 th, 2010.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Outline Introduction to MATLAB Image Processing with MATLAB
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
Getting started with Matlab: Outline
Reading and Writing Image Files
Introduction to MATLAB
Introduction to Matlab
Appendix B MathScript Basics
Lecture 25.
Lecture: MATLAB Chapter 1 Introduction
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
(Mohammed Sami) Ashhab
Matlab Workshop 9/22/2018.
Introduction to MATLAB
StatLab Matlab Workshop
Part I – Matlab Basics.
Use of Mathematics using Technology (Maltlab)
MATLAB – What Is It ? Name is from matrix laboratory Powerful tool for
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
CSE107 Matlab Introduction
Digital Image Processing
Communication and Coding Theory Lab(CS491)
CSE 307 Basics of Image Processing
Simulation And Modeling
MATLAB stands for MATrix LABoratory.
Presentation transcript:

Tutorial on Matlab and OpenCV Rui Ma TA of CMPT 414 May 14, 2013 Office hours: Fridays 11:00-12:00, CSIL TA Office 1 (ASB 9838)

What is Matlab MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. MATLAB = Matrix Laboratory Designed for fast numerical matrix calculations

Why Matlab Matlab integrates computation, visualization, and programming in a easy ­to­ use environment Matlab has been widely used for: Math and computation Algorithm development Modeling, simulation, and prototyping Scientific and engineering graphics

Matlab Environment Workspace History Command window

Matlab Help A powerful guide to learn Matlab Not only contains command definition, but also examples and demos

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]; Special matrices: zeros(n,m), ones(n,m), eye(n,m), rand()

Matrix Operations All operators in Matlab have definition on matrices: +, -, *, /, ^, sqrt, sin, cos, etc. Element-wise operators defined with a preceding dot:.*,./,.^ A*B and A.*B is different Others: size(A), A’, inv(A), Eig(A)

Accessing matrix elements If A=[1 2 3; 4 5 6; 7 8 9], then % get value a = A(2,1); b = A(1,:); c = A(:,:); d = A(:); % assign value A(2,1) = 10; A(1,:) = [11,12,13]; A(:,1) = [14,15,16]’;

Flow Control in Matlab The if conditional block if condition … end ● The for loop block for n = list … end The while block while condition … end

Script and Function Script does not have arguments and return values just a group of commands Function has arguments and usually with a return list Function rt_val_list = f(param_list) … (function body) Usually function is stored as a m file named as *.m

M-file A script file or a simple text file where you can place MATLAB commands Be organized and effective when writing complicated codes Create: File->New->Script Run: for test.m, type test in Matlab command window

Data I/O A native file format mat to save and load workspaces Use keywords load and save save test % creates test.mat with all variables save test a b % save only variables a and b load test % load session clear all % clear all variables clear a b % clear variables a and b

Graphics - 2D Plots plot(xdata, ydata, ‘marker_style’); For example x=-5:0.1:5; sqr=x.^2; pl1=plot(x, sqr, 'r:s');

Graphics - Annotation title('Demo plot'); xlabel('X Axis'); ylabel('Y Axis'); legend(pl1,'x^2');

Subplots Use subplot to divide a plotting window into several panes x=0:0.1:10; figure; subplot(1,2,1); plot(x,cos(x),'r'); grid on; title('Cosine') subplot(1,2,2); plot(x,sin(x),'d'); grid on; title('Sine');

Image Processing using Matlab Image Processing Toolbox A collection of image processing functions 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 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)

Images and Matrices 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); Column 1 to 256 Row 1 to 256 o [0, 0] o [256, 256]

Image I/O Read and write images in Matlab img = imread(‘sfu.jpg'); imwrite(img, ‘sfu.bmp', 'bmp'); Show the image figure; %show image in a new figure window imshow(img);

An example im = imread('SFU.jpg'); im = rgb2gray(im); ciThres = 160; im2 = zeros(size(im)); im2(logical(im > ciThres)) = 255; imshow(im2); imwrite(im2, 'SFU_2.bmp', 'bmp');

Summary MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. However, Matlab is slow while doing iterations: try to vectorize the process instead of using iterations Pre­allocate memory for a matrix Rewrite bottleneck procedures using c

What is OpenCV OpenCV is an open source C/C++ library for image processing and computer vision. In 2006, Intel released the first stable version of OpenCV In 2008, OpenCV obtained corporate support from Willow Garage

What can OpenCV do Basic data structures for matrix operation and image processing A bunch of functions to process visual data and extract information for images/videos

Where to get OpenCV Download and installation Versions for Windows, Mac or Linux Both source code and pre-built version(for Windows) are available

Pros and Cons about OpenCV Pros: Highly optimized, very fast and efficient A good tool if you want to implement realtime systems Well supported, ready-to-use algorithms Cons: Not easy of use, C or C++ coding Memory management, may crash

A VERY Simple OpenCV Program #include "cv.h" #include "highgui.h" void main() { IplImage *image = cvLoadImage("SFU.jpg"); cvNamedWindow("SFU Image", CV_WINDOW_AUTOSIZE); cvShowImage("SFU Image", image); cvWaitKey(0); cvReleaseImage(&image); }

More about Matlab and OpenCV Matlab Matlab Help OpenCV OpenCV Cheatsheet