Advanced MATLAB 046746. Topics Data Types Image Representation Image/Video I/O Matrix access Image Manipulation MEX - MATLAB Executable Data Visualization.

Slides:



Advertisements
Similar presentations
Matlab Image Processing
Advertisements

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)
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Part IV: Memory Management
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Matlab Tutorial. Session 1 Basics, Filters, Color Space, Derivatives, Pyramids, Optical Flow Gonzalo Vaca-Castano.
Image Processing with MATLAB
1 A L L A H. Command-Window Workspace & Directory Command- History The Matlab Command window - Finding your way around.
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
The Assembly Language Level
ITEC 352 Lecture 27 Memory(4). Review Questions? Cache control –L1/L2  Main memory example –Formulas for hits.
Image Processing in Matlab An Introductory Approach by Sabih D. Khan
Chapter 14 Landsat 7 image of the retreating Malaspina Glacier, Alaska.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
CS 104 Introduction to Computer Science and Graphics Problems
Introduction to Jitter & Eyesweb Volker Krüger Aalborg Media Lab Aalborg University Copenhagen
Programming with Matlab Day 5: Debugging, efficiency, advanced types of variables, logical indices, images.
Run-time Environment and Program Organization
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Computational Tools for Image Processing Lecture 1, Jan 22nd, 2007 Part 2 (8:10-9:20pm) by Lexing Xie EE4830 Digital Image Processing
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
1 © 2012 The MathWorks, Inc. Speeding up MATLAB Applications.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Sundermeyer MAR 550 Spring Laboratory in Oceanography: Data and Methods MAR550, Spring 2013 Miles A. Sundermeyer Image Processing/Analysis.
Matlab tutorial course Lesson 5: Loading and writing data, producing visual output
Introduction to Image Processing with MATLAB Medical Imaging Systems
Image and Video Processing in MATLAB Partly based on slides by Dmitri Roduy.
Introduction to MATLAB
MATLAB Week 4 01 December Outline More plotting – A few other 3-D plotting functions – Basic volume visualization Creating functions Vectorized.
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX.
MA/CS 3751 Fall 2002 Lecture 24. MA/CS 3752 ginput ginput is a Matlab function which takes one argument input: number of points to select in the image.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Image Arithmetic Image arithmetic is the implementation of standard arithmetic operations, such as addition, subtraction, multiplication, and division,
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
ITC Research Computing Support Using Matlab Effectively By: Ed Hall Research Computing Support Center Phone: Φ Fax:
Digital Image Processing Lecture4: Fundamentals. Digital Image Representation An image can be defined as a two- dimensional function, f(x,y), where x.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
CMPS1371 Introduction to Computing for Engineers IMAGES.
Outline Introduction to MATLAB Image Processing with MATLAB
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to MATLAB Ehsan Adeli M. Iran University of Science and Technology, E-Learing Center, Fall 2008 (1387)
6.S093: Visual Recognition through Machine Learning Competition MATLAB tutorial.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
Introduction to MATLAB CS 534 Fall What you'll be learning today ●MATLAB basics (debugging, IDE) ●Operators ●Matrix indexing ●Image I/O ●Image display,
การใช้งานโปรแกรม MATLAB ดร. อำนาจ ขาวเน. BASIC ELEMENTS OF MATLAB MATLAB Desktop MATLAB Editor Help System MATLAB (MATrix LABoratory)
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Virtual Memory By CS147 Maheshpriya Venkata. Agenda Review Cache Memory Virtual Memory Paging Segmentation Configuration Of Virtual Memory Cache Memory.
Basics of MATLAB 2- Programming in MATLAB By DR. Wafaa Shabana
Computer Application in Engineering Design
MATLAB® Image Processing Toolbox
L – Modeling and Simulating Social Systems with MATLAB
System Programming and administration
Computer Systems and Networks
CMSC 341 Prof. Michael Neary
CSE107 Matlab Introduction
Loop Statements & Vectorizing Code
CSE 307 Basics of Image Processing
Matlab Training Session 2: Matrix Operations and Relational Operators
MATLAB stands for MATrix LABoratory.
Loop Statements & Vectorizing Code
Presentation transcript:

Advanced MATLAB

Topics Data Types Image Representation Image/Video I/O Matrix access Image Manipulation MEX - MATLAB Executable Data Visualization General Tips Tricks

Data Types Relevant data types double – default in most cases (usually 64 bit) single – when you want to save memory (usually 32 bit) uint8 – [0 255] – native for images uint16 – [0 65,535] Logical – [0 1] – native for masks Simple casting: double(), uint8(). Useful when displaying images with a dynamic range not corresponding to its actual type. Conversion (of images): im2double(),im2uint8(),lab2double(),lab2uint8() rgb2ind(),ind2rgb(),makecform()

I = imread('world.jpg'); I2 = I-1.4; diffI = I-I2; fprintf('Max difference between images: %d\n',max(diffI(:))); I = imread('world.jpg'); I2 = I-1.4; diffI = I-I2; fprintf('Max difference between images: %d\n',max(diffI(:))); Common problem fprintf('Max difference between images: %2.1f\n',max(diffI(:))); Max difference between images: 1.4 Max difference between images: 1 display([ 'Max difference between images: ' num2str( max(diffI(:)) ) ]); A much better practice is: Max difference between images: 1.4

Image Representation 2D Matrix Intensity: Each pixel value in the dynamic range [minP, maxP]. Can represent a grayscale image, results of a 2d function, etc. Useful commands: imagesc(), axis, colormap(). Binary: a.k.a masks. Can represent absolute ground truth, etc. Useful commands: bwlabel(),bwmorph(),bwdist(),im2bw(),bwperim().

Image Representation 2D Matrix Indexed: Each pixel value in the range [minP, maxP]. Can represent segmentation. Useful commands: regionprops(),label2rgb()

Image Representation 3D Matrix True Color: Three 2D matrices stacked. Each represents a color component. (e.g. RGB) Can represent an RGB color image, LAB image, etc. Useful commands: imshow(),rgb2gray(),rgb2ind().

Image/Video I/O Useful Commands imread() – read image imwrite() – write image im2frame() – convert image to movie frame movie2avi() – write avi file aviread() – read avi file mmreader()/VideoReader() – read video (better) VideoWriter() – create video file (2011b+) movie() – show movie implay() – show video interactively

Matrix access Useful Commands: Ind = sub2ind(matrixSize, rowSub, colSub) convert subscript to index. [I,J] = ind2sub(siz,IND) – convert index to subscipt. meshgrid() – generate X,Y grids. F = scatteredInterpolant(x,y,v) - creates an interpolant that fits a surface of the form v = F(x,y). (replaced TriScatteredInterp)xyv

Image Manipulation Useful Commands: imcrop()– Useful for interactive cropping. imrotate()– Rotate image. imfilter() – Use kernal to convolve/correlation. nlfilter() – Sliding neighborhood operation. blkproc() – Perform function on (semi-)distinct blocks. fspecial() – Create common image filter kernels. imresize() – Resize image using defined interpolation. kron() – Kronecker tensor product padarray() – Pad image. colfilt() – Colum-stack filtering (faster) imfreehand()- Select region with mouse

MEX - MATLAB Executable Dynamically linked subroutines produced from C, C++ or Fortran source code. Useful when dealing with non efficient-Matlab algorithms (e.g. iterative algorithm implemented as loops). mex –setup : Setup mex compiling configurations.

Data Visualization Useful Commands: scatter()/plot() – Useful to plot points on image. imagesc() – Useful for 2D data. print() – Save figure as image on disk (careful with lossy compressions)

General Tips Avoid loops Manage memory (Clear unused variables) Useful command: clearvars() Avoid memory duplication – use nested functions function myfun A = magic(500); function setrowval(row, value) A(row,:) = value; end setrowval(400, 0); disp('The new value of A(399:401,1:10) is') A(399:401,1:10) end

General Tips Avoid memory duplication – don’t want to use nested functions? Simply use the same variable name: function x = demo x=rand(10000); x=func(x); function a=func(a) a=a*2;

General Tips Preallocating Arrays Preallocate correctly tic x = 0; for k = 2: x(k) = x(k-1) + 5; end toc Elapsed time is seconds. tic x = zeros(1, ); for k = 2: x(k) = x(k-1) + 5; end toc Elapsed time is seconds. A = int8(zeros(100)); A = zeros(100, 'int8');

General Tips You will be amazed of the variety of built in functions that Matlab offers. In fact, assume that the function you need is built in Matlab. It’s probably true! Use Matlab “help” to understand how to use functions Use Google to search for new functions!

General Tips Long-Term Usage (Windows Systems Only) On 32-bit Microsoft Windows, the workspace of MATLAB can fragment over time due to the fact that the Windows memory manager does not return blocks of certain types and sizes to the operating system. Clearing the MATLAB workspace does not fix this problem. You can minimize the problem by allocating the largest variables first. This cannot address, however, the eventual fragmentation of the workspace that occurs from continual use of MATLAB over many days and weeks, for example. The only solution to this is to save your work and restart MATLAB. The pack command, which saves all variables to disk and loads them back, does not help with this situation.pack Long-Term Usage (Windows Systems Only) On 32-bit Microsoft Windows, the workspace of MATLAB can fragment over time due to the fact that the Windows memory manager does not return blocks of certain types and sizes to the operating system. Clearing the MATLAB workspace does not fix this problem. You can minimize the problem by allocating the largest variables first. This cannot address, however, the eventual fragmentation of the workspace that occurs from continual use of MATLAB over many days and weeks, for example. The only solution to this is to save your work and restart MATLAB. The pack command, which saves all variables to disk and loads them back, does not help with this situation.pack

Tricks Stenography (Wikipedia) The art of hiding a message within another larger message

Tricks I= imread('StenographyOriginal.png'); I4=85*mod(I,4); figure; subplot(1,2,1) imshow(I); title('Original'); subplot(1,2,2) imshow(I4);title('Result'); I= imread('StenographyOriginal.png'); I4=85*mod(I,4); figure; subplot(1,2,1) imshow(I); title('Original'); subplot(1,2,2) imshow(I4);title('Result'); Stenography (Wikipedia) The art of hiding a message within another larger message

Tricks Almost Connected (Steve Eddins’ Blog)

Tricks url = ' bw = imread(url); lbl = bwlabel(bw); figure; imagesc(lbl); axis image; url = ' bw = imread(url); lbl = bwlabel(bw); figure; imagesc(lbl); axis image; Almost Connected (Steve Eddins’ Blog)

Tricks bw2 = bwdist(bw) <= 12.5; lbl2 = bwlabel(bw2); figure; imshow(bw2); figure; imagesc(lbl2); axis image; bw2 = bwdist(bw) <= 12.5; lbl2 = bwlabel(bw2); figure; imshow(bw2); figure; imagesc(lbl2); axis image; Almost Connected (Steve Eddins’ Blog)

Tricks lbl3 = lbl2.*bw; figure; imagesc(lbl3); axis image; lbl3 = lbl2.*bw; figure; imagesc(lbl3); axis image; Almost Connected (Steve Eddins’ Blog)

Tricks bw = imread('text.png'); dots = rand(size(bw))>0.99; bw = imread('text.png'); dots = rand(size(bw))>0.99; Feature AND (Steve Eddins’ Blog)

Tricks touching_pixels = bw & dots; Feature AND (Steve Eddins’ Blog)

Tricks out = imreconstruct(touching_pixels, bw); Feature AND (Steve Eddins’ Blog) out = imreconstruct(dots, bw); Of course this will work just as well: