1 A L L A H. Command-Window Workspace & Directory Command- History The Matlab Command window - Finding your way around.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Image Segmentation Longin Jan Latecki CIS 601. Image Segmentation Segmentation divides an image into its constituent regions or objects. Segmentation.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Image Processing Dr. Kourosh Kiani
Introduction to MATLAB The language of Technical Computing.
Introduction to Computer Vision Image Texture Analysis
Image Processing with MATLAB
Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Automation and Drives SIMATIC HMI The Human Machine Interface for internal use only Scope of Presentation Dept. of Industrial Electronics and Control Eng.
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Laboratory of Image Processing Pier Luigi Mazzeo
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Image Display MATLAB functions for displaying image Bit Planes
MATLAB Image Processing Toolbox. Introduction  Collection of functions (MATLAB files) that supports a wide range of image processing operations  Documentation.
Introduction to MATLAB and image processing. MATLAB and images The help in MATLAB is very good, use it! An image in MATLAB is treated as a matrix Every.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Digital Image Processing Lecture3: Introduction to MATLAB.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Topics Introduction Hardware and Software How Computers Store Data
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
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.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Introduction to MATLAB
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Image Processing:Fundementals Lecture: Introduction –An image is digitized to convert it to a form which can be stored in a computer's memory or.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
What Matlab can do for me? Matlab stands for MATrix LABoratory Matlab is a software package for high-performance numerical computation and visualization.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
Digital Image Processing Lecture4: Fundamentals. Digital Image Representation An image can be defined as a two- dimensional function, f(x,y), where x.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
CSE123 Lecture 3 Files and File ManagementScripts.
CMPS1371 Introduction to Computing for Engineers IMAGES.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Lecture 27: Image Processing
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Introduction to MATLAB Ehsan Adeli M. Iran University of Science and Technology, E-Learing Center, Fall 2008 (1387)
การใช้งานโปรแกรม MATLAB ดร. อำนาจ ขาวเน. BASIC ELEMENTS OF MATLAB MATLAB Desktop MATLAB Editor Help System MATLAB (MATrix LABoratory)
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Basics of MATLAB 2- Programming in MATLAB By DR. Wafaa Shabana
Computer Application in Engineering Design
Reading and Writing Image Files
MATLAB® Image Processing Toolbox
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Digital Image Processing
CSE 307 Basics of Image Processing
Fundamentals of Image Processing Digital Image Representation
MATLAB stands for MATrix LABoratory.
Presentation transcript:

1 A L L A H

Command-Window Workspace & Directory Command- History The Matlab Command window - Finding your way around

The Working Directory When you start Matlab it runs under a default directory/folder which is determined at the time of installation. Issue the command pwd (“present working directory”) to find out what your default working directory/folder is –

To change this to my own chosen directory e:/chris/my_matlabstuff, we use the command cd (change directory). The Matlab Search Path Typing the Matlab function path will show the current Matlab search path on yourcomputer. Try typing :–

Getting started - The Matlab workspace The first and simplest way to use Matlab is to enter commands at the Matlab prompt(usually one at a time) and allow Matlab to respond accordingly. Enter the following sequence of Matlab commands :– Typing the command whos at the Matlab prompt shows what variables currently exist in the workspace:–

Saving, clearing and loading Data The easiest way to save the results of a Matlab session is to use the save command :– Typing clear with no specific variables named will clear all variables from the workspace. Loading the previous session as a result all variable will be restored

M files – scripts and functions Typing directly into the command window is a useful way to get familiar with Matlab and is ideal for trying out relatively simple sequences of commands. the next step up is to write programs. Matlab programs are called “m-files In the Matlab command window, left-click the file drop- down menu and select 1. New – Blank M-file. 2· The Matlab text editor appears. 3· We type a sequence of Matlab commands :–” and there are two basic kinds – scripts and functions

Creating and running a Matlab Script file To run this file, type the name of the script file at the Matlab prompt and press return -

Matlab Function Files The second kind of m-file is the Matlab function. Functions are also sequences of Matlab commands but differ from scripts in an important way. The key difference between scripts and functions is that when a function is executed only the declared output arguments are returned to the workspace. Any other variables created within the function vanish when Matlab returns to the workspace.

To run this file and see what it does, type the following at the Matlab prompt -

Building Expressions in Matlab Expressions in Matlab employ a combination of variables, operators, numbers and functions. For example, in the following expression :- Vectorizations: The nice thing about implicit vectorisation is that it helps to avoid ungainly loops and allows us to write more compact,intuitive expressions.

Saving and printing graphics You use the Matlab print function with the specified options. print allows you to save an image or graph in a very large number of standard formats. Type For example, typing :-

Programming in Matlab Creating arrays in Matlab The simplest way of creating small arrays in Matlab is to manually enter the elements in the command window, row by row. Try entering the commands given below:– A vector is just a 1-D array :–

Programming in Matlab contd.. We can turn a row vector into a column vector, by using the transpose operator or, of course, transpose a 2-D array :– We can also create ‘string’ arrays which contain text –

Individual array elements are accessed using subscripts as follows:- We can change or correct the values of array elements by indexing them individually:– Arrays can be 3-D (or have even higher dimensionality) :–

Matlab has a very important and powerful colon operator ( : ). This can be used to create vectors and for subscripting arrays. Here’s a couple of examples of its use in creating vectors - We can also access groups of elements in an array by using the colon operator to specify the vector indices. Try the following :- We can also use the colon operator to extract entire rows or columns of an array:-

Assignment

We can easily concatenate (join together) arrays to make a larger array The arrays which form the elements of the concatenated array must be of conformable dimension – i.e. the resulting array must be rectangular. For example, trying to form the arrays :–

Creating and Dealing With Larger Arrays

The next example creates an array that randomly allocates values of 0 or 1 to the rows of an array by “flipping a coin”:– A second way in which larger arrays can be constructed is through use of appropriate loop constructs.

Avoiding loops

Determining the size of arrays

Here are some fun examples to try out :–

Relational and logical operators Try the examples below :- Try the examples for logical operators below :-

Try some of these basic examples –

If statements If else statements

For loop

Indexing Vectors

Indexing Vectors contd..

Image Processing Toolbox

Introduction Collection of functions (MATLAB files) that supports a wide range of image processing operations Documentation

Read an Image Read in an image Validates the graphic format (bmp, hdf, jpeg, pcx, png, tiff, xwd) Store it in an array clear, close all I = imread(‘pout.tif`); [X, map] = imread(‘pout.tif’);

Display an Image imshow(I)

Check the Image in Memory whos Name Size Bytes Class ans 291x uint8 array Grand total is elements using bytes uint8[0, 255] uint16[0, 65535] double[0, 1]

Histogram Equalization Histogram: distribution of intensities figure, imhist(I) Equalize Image (contrast) I2 = histeq(I); figure, imshow(I2) figure, imhist(I2)

Histogram Equalization (cont.)

Write the Image Validates the extension Writes the image to disk imwrite(I2, ’pout2.png’); imwrite(I2, ‘pout2.png’, ‘BitDepth’, 4);

Morphological Opening Remove objects that cannot completely contain a structuring element Estimate background illumination clear, close all I = imread(‘rice.tif’); imshow(I) background = imopen(I, strel(‘disk’, 15)); imshow(background)

Morphological Opening (cont.)

Subtract Images Create a more uniform background I2 = imsubtract(I, background); figure, imshow(I2)

Adjust the Image Contrast stretchlim computes [low hight] to be mapped into [bottom top] I3 = imadjust(I2, stretchlim(I2), [0 1]); figure, imshow(I3)

Apply Thresholding to the Image Create a binary thresholded image 1. Compute a threshold to convert the intensity image to binary 2. Perform thresholding creating a logical matrix (binary image) level = graythresh(I3); bw = im2bw(I3, level); figure, imshow(bw)

Apply Thresholding to the Image (cont.)

Labeling Connected Components Determine the number of objects in the image Accuracy (size of objects, approximated background, connectivity parameter, touching objects) [labeled, numObjects] = bwlabel(bw, 4); numObjects {= 80} max(labeled(:))

Select and Display Pixels in a Region Interactive selection grain = imcrop(labeled) Colormap creation function RGB_label = ‘c’, ‘shuffle’); imshow(RGB_label); rect = [ ]; roi = imcrop(labeled, rect)

Object Properties Measure object or region properties graindata = regionprops(labeled, ‘basic’) graindata(51).Area{296} graindata(51).BoundingBox{ } graindata(51).Centroid{ } Create a vector which holds just one property for each object allgrains = [graindata.Area]; whos

Statistical Properties of Objects max(allgrains) { 695 } Return the component label of a grain size biggrain = find(allgrains == 695) { 68 } Mean grain size mean(allgrains) { 249 } Histogram (#bins) hist(allgrains, 20)

Statistical Properties of Objects (cont.)

Storage Classes double (64-bit), uint8 (8-bit), and uint16 (16-bit) Converting (rescale or offset) double im2double (automatic rescale and offsetting) RGB2 = im2uint8(RGB1); im2uint16 imapprox (reduce number of colors: indexed images)

Image Types Index Data matrix (uint8, uint16, double) Colormap matrix (m x 3 array of double [0 1]) Intensity (black = 0, white =  ) Binary (0, 1) B = logical(uint8(round(A))); (logical flag on) B = +A; (logical flag off) RGB (m x n x 3 of truecolor)

Converting Image Types dither gray2ind grayslice im2bw ind2gray ind2rgb mat2gray rgb2gray rgb2ind

Multiframe Image Arrays Same size, #planes, colormap Store separate images into one multiframe array A = cat(4, A1, A2, A3, A4, A5) Extract frames from a multiframe array FRM3 = MULTI(:, :, :, 3) Display a frame imshow(MULTI(:, :, :, 7))

Image Arithmetic imabsdiff imadd imcomplement imdivide imlincomb immultiply imsubtract

Adding Images I = imread(‘rice.tif’); J = imread(‘cameraman.tif’); K = imadd(I, J); imshow(K) Brighten an image results saturation RGB = imread(‘flowers.tif’); RGB2 = imadd(RGB, 50); subplot(1, 2, 1); imshow(RGB); subplot(1, 2, 2); imshow(RGB2);

Adding Images (cont.)

Subtracting Images Background of a scene rice = imread(‘rice.tif’); background = imopen(rice, strel(‘disk’, 15)); rice2 = imsubtract(rice, background); imshow(rice), figure, imshow(rice2); Negative values imabsdiff

Subtracting Images (cont.)

Multiplying Images Scaling: multiply by a constant (brightens >1, darkens <1) Preserves relative contrast I = imread(‘moon.tif’); J = immultiply(I, 1.2); imshow(I); figure, imshow(J)

Multiplying Images (cont.)

Dividing Images (Ratioing) I = imread(‘rice.tif’); background = imopen(I, strel(‘disk’, 15)); Ip = imdivide(I, background); imshow(Ip, []) Linear combination only truncates the final result K = imlincomb(.5, I,.5, I2);

Dividing Images (cont.)

Coordinate Systems Pixel Coordinates Discrete unit (integer) (r, c)  = (1, 1) Spatial Coordinates Continuous unit (x, y)  = (0.5, 0.5) 123

Non-default Spatial Coordinate System A = magic(5); x = [ ]; y = [ ]; image(A, ‘xData’, x, ‘yData’, y), axis image, colormap(jet(25))

Spatial Transformations Map pixel locations in an input image to new locations in an output image Resizing Rotation Cropping

Resizing Images Change the size of an image I = imread(‘ic.tif’); J = imresize(I, 1.25); K = imresize(I, [ ]); figure, imshow(J) figure, imshow(K)

Resizing Images (cont.)

Rotating Images Rotate an image by an angle in degrees I = imread(‘ic.tif’); J = imrotate(I, 35, ‘bilinear’); imshow(I) figure, imshow(J)

Rotating Images (cont.)

Cropping Images Extract a rectangular portion of an image imshow ic.tif I = imcrop;