Department of Electrical Engineering, Technion IIT Signal and Image Processing Laboratory. Yair Moshe

Similar documents
Mechanical Engineering Department Second Year (2015)

PROGRAMMING WITH MATLAB WEEK 6

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

GRAPHICS AND VISUALISATION WITH MATLAB Part 2

fplot Syntax Description Examples Plot Symbolic Expression Plot symbolic expression or function fplot(f) fplot(f,[xmin xmax])

Part #10. AE0B17MTB Matlab. Miloslav Čapek Viktor Adler, Pavel Valtr, Filip Kozák

More on Plots. Dmitry Adamskiy 30 Nov 2011

Introduction to MATLAB

Matlab Tutorial 1: Working with variables, arrays, and plotting

Graphics Example a final product:

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

Special Topics II: Graphical User Interfaces (GUIs)

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

Data Analysis in Geophysics ESCI Class 17. Bob Smalley. More Matlab.

Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures

What is Matlab? A software environment for interactive numerical computations

Introduction to MATLAB

QUICK INTRODUCTION TO MATLAB PART I

Computer Programming in MATLAB

MATLAB. Creating Graphical User Interfaces Version 7. The Language of Technical Computing

Introduction to MATLAB: Graphics

Introduction to Matlab

MATLAB Introduction to MATLAB Programming

Computational Methods of Scientific Programming. Matlab Lecture 3 Lecturers Thomas A Herring Chris Hill

Lecture 3 for Math 398 Section 952: Graphics in Matlab

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Table of Contents. Introduction.*.. 7. Part /: Getting Started With MATLAB 5. Chapter 1: Introducing MATLAB and Its Many Uses 7

EXERCISES Introduction to MATLAB: Graphics

Computational Methods of Scientific Programming

A General Introduction to Matlab

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

Introduction to Matlab

m-files Matlab offers this feature through m-files, which are ascii text files containing a set of Matlab commands.

Dr. Iyad Jafar. Adapted from the publisher slides

Additional Plot Types and Plot Formatting

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb

GUI Building for Test & Measurement Applications

SGN Introduction to Matlab

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

MATLAB 7. The Language of Technical Computing KEY FEATURES

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB

OPEN-SANKORE MANUAL. (Start) button and type Open-Sankoré in the search box, and then click on the Open Sankoré icon as displayed in

Computational Methods of Scientific Programming Fall 2008

L E S S O N 2 Background

Spring 2010 Instructor: Michele Merler.

GIMP ANIMATION EFFECTS

Basic MATLAB Intro III

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

BD CellQuest Pro Analysis Tutorial

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

GRAPHICS AND VISUALISATION WITH MATLAB

Graphics and plotting techniques

Computational Methods of Scientific Programming. Matlab Lecture 4 Lecturers Thomas A Herring Chris Hill

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

1 Introduction to Matlab

1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243

Adobe Illustrator CS Design Professional GETTING STARTED WITH ILLUSTRATOR

Adding Objects Creating Shapes Adding. Text Printing and Exporting Getting Started Creating a. Creating Shapes Adding Text Printing and Exporting

MATH 2221A Mathematics Laboratory II

ezimagex2 User s Guide Version 1.0

Introduction to MATLAB Practical 1

1. Register an account on: using your Oxford address

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

CSE 123. Plots in MATLAB

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

Purpose of the lecture MATLAB MATLAB

Basic Graphs. Dmitry Adamskiy 16 November 2011

MAT 343 Laboratory 4 Plotting and computer animation in MATLAB

INTRODUCTION TO MATLAB INTERACTIVE GRAPHICS EXERCISES

Scientific Functions Complex Numbers

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization

INTRODUCTION TO MATLAB

Camtasia Studio 5.0 PART I. The Basics

Customisation and production of Badges. Getting started with I-Color System Basic Light

Programming 1. Script files. help cd Example:

v Annotation Tools GMS 10.4 Tutorial Use scale bars, North arrows, floating images, text boxes, lines, arrows, circles/ovals, and rectangles.

IDL Tutorial. Working with Images. Copyright 2008 ITT Visual Information Solutions All Rights Reserved

Introduction to Matlab. WIAA Technical Workshop #2 10/20/2015

How to...create a Video VBOX Gauge in Inkscape. So you want to create your own gauge? How about a transparent background for those text elements?

The Language of Technical Computing. Computation. Visualization. Programming. Creating Graphical User Interfaces Version 1

MINT Interactive User s Guide

Introduction to version Instruction date

Following a tour is the easiest way to learn Prism.

Advanced Programming in MATLAB

There are two ways to launch Graphical User Interface (GUI). You can either

Graphics in MATLAB. Responsible teacher: Anatoliy Malyarenko. November 10, Abstract. Basic Plotting Commands

Working with Plan Production ObjectsChapter1:

Introduction to MATLAB

GIMP TEXT EFFECTS. Text Effects: Outline Completed Project

How to create an animated face

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs...

Transcription:

Department of Electrical Engineering, Technion IIT Signal and Image Processing Laboratory Advanced MATLAB Part I: Graphics and GUI Yair Moshe March, 2010

Outline Graphics Animation Image and Video Handle Graphics Objects Creating GUI using GUIDE 2

2-D Plotting x=0:.1:2*pi; y=sin(x); plot(x,y) grid on hold on plot(x, exp(-x), 'r:*') hold off axis([0 2*pi 0 1]) title('2-d Plot') xlabel('time') ylabel('f(t)') text(pi/3, sin(pi/3), '<--sin(\pi/3) ') legend('sine Wave', 'Decaying Exponential') 3

Line Specification Specifier Line Color Specifier Marker r red. point g green o circle b blue x cross c cyan + plus m magenta * asterix y yellow s square k black d diamond w white v triangle down Specifier Line Style ^ triangle up - solid < triangle left -- dashed > triangle right : dotted p pentagram :. dash-dot h hexagram 4

The Figure Window The figure window contains useful actions in its menu and toolbars: Zooming in and out Panning Rotating 3-D axes (and other camera actions) Copying & pasting Plot Edit Mode Plot tools (interactive plotting) Figure Palette Plot Browser Property Inspector Data Cursor Mode Data brushing and linking 5

The Figure Window Generate M-Code to reproduce the figure Saving & exporting Figures can be saved in a binary.fig file format Figures can be exported to many standard graphics file formats etc., EPS (recommended),tiff, JPEG, GIF, PNG, BMP, EMF. Printing 6

Subplots & Scales for Axes subplot(2,2,1) x=0:.1:2*pi; plot(x, exp(-x)) subplot(2,2,2) semilogy(x, exp(-x)) subplot(2,2,3) t = 0:900; z1 = 1000*exp(-0.005*t); z2 = sin(0.005*t); plotyy(t,z1,t,z2,'semilogy','plot'); subplot(2,2,4) plot(peaks) 7

Interactive Plotting 8

Data Brushing and Linking Data Brushing Manually select observations on an interactive data display Can select, remove, and replace individual data values Data Linking Linked plots visibly respond to changes in the current workspace variables they display and vice versa Each one of these tools is useful by itself but when used together they are very powerful 9

Data Statistics & Curve Fitting Data Statistics Tool Calculates basic statistics about the central tendency and variability of data plotted in a graph Plots any of the statistics the a graph Basic Fitting Interface Fits data using a spline interpolant, a shape-preserving interpolant, or a polynomial up to degree 10 Plots multiple fits simultaneously for a given data set Examines the numerical results of a fit Annotates the plot with the numerical fit results and the norm of residuals 10

3-D Plotting z = 0:0.1:10*pi; x = exp(-z/20).*cos(z); y = exp(-z/20).*sin(z); plot3(x,y,z,'linewidth',2) grid on xlabel('x') ylabel('y') zlabel('z') 11

Specialized Plotting Routines 12

3-D Meshes and Surfaces 13

3-D Meshes and Surfaces 14

3-D Meshes and Surfaces 15

Outline Graphics Animation Image and Video Handle Graphics Objects Creating GUI using GUIDE 16

Animation MATLAB provides two ways of generating moving, animated graphics: 1. On the fly - Continually erase and then redraw the objects on the screen, making incremental changes with each redraw 2. Frame by frame capture and playback - Save a number of different pictures and then play them back as a movie 17

On the Fly Animation, 1 st example % initialize surface object x = -pi:0.1:pi; xsize = size(x,2); f = zeros(xsize); for y = 1:xsize f(:,y) = cos(y/xsize*pi) + sin(x); end % draw surface first time hsurface = surface(f, 'LineStyle', 'none'); view(3); % set the default 3D view 18

On the Fly Animation, 1 st example % function drawing loop for j=0:0.3:10 % update surface function for y = 1:xsize f(:,y) = cos(y/xsize*pi+j) + sin(x+j); end % update surface ZData set(hsurface, 'ZData', f); drawnow; end 19

On the Fly Animation, 2 nd example t = 0:pi/20:2*pi; y = exp(sin(t)); h = plot(t,y,'ydatasource','y'); for k = 1:.1:10 y = exp(sin(t.*k)); refreshdata(h,'caller') drawnow; pause(.1) end % Evaluate y in the function workspace 20

Frame by Frame Animation Example of frame by frame movie creation and playing: [x,y] = meshgrid([-10:0.5:10]); for j = 1:15 z = bessel(0, (j-1)*0.2 + sqrt(x.^2 +y.^2)); surf(x,y,z) axis([-10 10-10 10 -.5 1]) M(j) = getframe; end frame_order = [1:15 14:-1:1]; number_repeats = 5; movie(m, [number_repeats frame_order]); 21

Outline Graphics Animation Image and Video Handle Graphics Objects Creating GUI using GUIDE 22

Images [x,map]=... imread('peppers.png'); image(x) colormap(map) Image I/O imread, imwrite, iminfo Image display image Display imagesc Scale and display 23

Images a = magic(4); image(a); map = hsv(16); colormap(map) colorbar 24

Image Processing Toolbox Image display imshow Display subimage Display multiple images in a single figure even if they have different colormaps Image exploration imtool Provides tools for pixel information, pixel region, distance, image information, adjust contrast, crop image, and display range Movie Player implay Play movie, video, or image sequence Multi-frame to movie immovie - Make MATLAB movie from a multiframe image 25

Video AVI aviread, avifile, addframe, close, aviinfo Allows frame-byframe manipulation of AVI files movie2avi Make AVI file from MATLAB movie Multimedia reader mmreader, read, mmfileinfo - Allows frame-by-frame manipulation of video files Newer and better than counterpart AVI functions Supports many formats using installed Windows video codecs Media Player mplay - View video from MATLAB workspace, multimedia file, or Simulink model 26

Related Toolboxes Image Acquisition Toolbox Acquire images and video Support for a large range of imaging devices Video and Image Processing Blockset Multimedia I/O, video viewer, and display blocks Can work in real-time Can read from / write to MATLAB workspace 27

Outline Graphics Animation Image and Video Handle Graphics Objects Creating GUI using GUIDE 28

Handle Graphics Objects Handle Graphics is an object-oriented structure for creating, manipulating and displaying graphics Graphics objects are the basic drawing elements used in MATLAB Every graphics object has: A unique identifier, called a handle A set of characteristics, called properties 29

Graphics Objects Hierarchy Objects are organized into a hierarchy: 30

Core Graphics Objects Line Figure Text Surface Axes (3-D) Image Axes (2-D) Patch 31

Composite Graphics Objects Composite Objects are core objects that have been grouped together to provide a more convenient interface Plot objects areaseries, barseries, contourgroup, errorbarseries, lineseries, quivergroup, scattergroup, stairseries, stemseries, surfaceplot Group objects hggroup Enables to control visibility or selectability of a group of objects hgtransform Enables to transform (etc., rotate, translate, scale) a group of objects Annotation objects Created in a hidden axes that extends the full size of the figure Enables to specify the locations anywhere in the figure using normalized coordinates 32

Obtaining an Object s Handle Upon creation, for example: h = plot(x_data, y_data, ) Using utility functions: 0 - root object handle (the screen) gcf returns the handle of the current figure gca - returns the handle of the current axis in the current figure gco - returns the handle of the current object in the current figure gcbo - returns the handle of the object whose callback is currently executing gcbf - returns the handle of the figure that contains the object whose callback is currently executing findobj(handles, PropertyName,PropertyValue) return objects with specific properties 33

Setting and Getting Properties Return a list of all object properties and their current values: get(handle) Return current value of an object property: get(handle, PropertyName ) Example: get(gcf, 'Color') Return a list of all user-settable object properties and their current values: set(handle) Return a list of all possible values for an object property: set(handle, PropertyName ) Example: set(gca, 'XDir') Set an object property to a new value: set(handle, PropertyName, NewPropertyValue ) Example: set(gca, 'XDir', 'Reverse') All the above can also be done (but not at runtime) using the Property Editor 34

Example Specifying Figure Position space = 5; top_space = 80; scn_size = get(0,'screensize'); pos1 = [space, 2/3*scn_size(4) + space,... scn_size(3)/2-2*space, scn_size(4)/3 - (top_space + space)]; pos2 = [pos1(1) + scn_size(3)/2, pos1(2),... pos1(3), pos1(4)]; h1 = figure(1); peaks; h2 = figure(2); membrane; set(h1, 'Position', pos1) set(h2, 'Position', pos2) 35

Example Background Image % Create background axes and move them to the background hback = axes('units','normalized','position',[0 0 1 1]); uistack(hback,'bottom'); % Load background image and display it [back map]=imread('sipl.gif'); image(back) colormap(map) % Turn the handlevisibility off so that we don't inadvertently plot into % the axes again. Also, make the axes invisible set(hback,'handlevisibility','off','visible','off') % Now we can use the figure as required axes('position',[0.1,0.1,0.85,0.35]) plot(rand(10)) 36

Outline Graphics Animation Image and Video Handle Graphics Objects Creating GUI using GUIDE 37

What is GUIDE? GUIDE is MATLAB s Graphical User Interface (GUI) Development Environment GUIDE stores GUIs in two files:.fig file - Contains a complete description of the GUI figure layout and the GUI components Changes to this file are made in the Layout Editor.m file - Contains the code that controls the GUI Initialization code and callbacks You can program the behavior of the GUI in this file using the M-file Editor 38

Creating a GUI Typical stages of creating a GUI are: 1. Designing the GUI 2. Laying out the GUI Using the Layout Editor 3. Programming the GUI Writing callbacks in the M-file Editor 4. Saving and Running the GUI It is also possible to create a GUI programmatically 39

The Layout Editor Align Objects Menu Editor Tab Order Editor Toolbar Editor Run GUI Component Palette Object Browser Property Inspector M-file Editor Layout Area Resize Box 40

Hands-On GUIDE Example 41

Callbacks A callback is a function that executes when a specific event occurs on a graphics object Also called event handler in some programming languages A property of a graphics object All objects: ButtonDownFnc, CreateFnc, DeleteFnc User interface controls: Callback, KeyPressFcn, Figure: CloseRequestFcn, KeyPressFcn, KeyReleaseFcn, ResizeFcn, WindowButtonDownFcn, WindowButtonMotionFcn, WindowButtonUpFcn, WindowKeyPressFcn, WindowKeyReleaseFcn, WindowScrollWheelFcn Stored in the GUI s M-file 42

Writing Callbacks A callback is usually made of the following stages: 1. Getting the handle of the object initiating the action (the object provides event / information / values) 2. Getting the handles of the objects being affected (the object whose properties are to be changed) 3. Getting necessary information / values 4. Doing some calculations and processing 5. Setting relevant object properties to effect action 6. Save any changes that have been made to the handles structure by using guidata(hobject, handles) hobject is the handle to the component object that executes the callback 43

Writing Callbacks Callback from example: % --- Executes on button press in plot_button. function plot_button_callback(hobject, eventdata, handles) % hobject handle to plot_button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get user input from GUI f1 = str2double(get(handles.f1_input,'string')); f2 = str2double(get(handles.f2_input,'string')); t = eval(get(handles.t_input,'string')); % Calculate data % Create frequency plot axes(handles.frequency_axes) % Select the proper axes plot(f,m(1:257)) xlabel('frequency'); set(handles.frequency_axes,'xminortick','on') grid on 44

Managing Data Most GUIs generate or use data specific to the application GUI components often need to communicate data to one another Several basic mechanism serve this need: UserData property Application data (getappdata, setappdata, isappdata, rmappdata) Using the handles structure (guidata) Nested functions It is also possible to make several different GUIs work together Communicate by setting each other s properties or by returning outputs 45

Image Processing Modular Tools Many of the interactive tools of the Image Processing Toolbox are modular and can be combined into your custom GUI For image processing applications imcontrast, imcolormaptool, imcrop, imdisplayrange, imdistline, imageinfo, immagbox, imoverview, impixelinfo, impixelregion, impixelregionpanel, imsave, imscrollpane 46

More Information MATLAB user manuals Graphics, 3-D Visualization, Creating Graphical User Interfaces, Image Processing Toolbox, Image Acquisition Toolbox, Video and Image Processing Blockset, Marchand P., Holland T. O., Graphics and GUIs with MATLAB, 3 ed, 2003, CRC Press Smith T. S., MATLAB Advanced GUI Development, 2006, Dog Ear Publishing Documents from Mathworks can be found at: http://www.mathworks.com/access/helpdesk/help/techdoc/ Most of this info can also be found in MATLAB Help 47

48