Computer Vision & Digital Image Processing MATLAB for Image Processing Dr. D. J. Jackson Lecture 4- Matlab introduction Basic MATLAB commands MATLAB windows Reading images Displaying images image() colormap() mesh() view() Basic matrix operations MATLAB Web site: http://www.mathworks.com Dr. D. J. Jackson Lecture 4-
Starting MATLAB On the PC, click the matlab icon On a workstation, type matlab Dr. D. J. Jackson Lecture 4- Creating a window (MATLAB figure) figure: Create figure window. figure, by itself, creates a new figure window, and returns its handle. figure(h) makes H the current figure, forces it to become visible, and raises it above all other figures on the screen. If Figure H does not exist, and H is an integer, a new figure is created with handle H. GCF returns the handle to the current figure. Execute get(h) to see a list of figure properties and their current values. Execute set(h) to see a list of figure properties and their possible values. Dr. D. J. Jackson Lecture 4-4
An example figure An example figure (window) created with figure() Dr. D. J. Jackson Lecture 4-5 Reading images bmpread: Read a Microsoft Windows Bitmap file from disk. [X,MAP] bmpread('filename') Reads the file 'filename' and returns the indexed image X and associated colormap MAP. If no extension is given for the filename, the extension '.bmp' is assumed. [R,G,B] bmpread('filename') Reads the 4-bit BMP file from the file 'filename'. BPP bmpread('filename') Returns the number of bits per pixel in the BMP file. BMPREAD does not read -bit or compressed BMP files. Dr. D. J. Jackson Lecture 4-6
Example bitmap file read [lena,lmap]bmpread('lena8.bmp'); Name of the array which will hold the colormap Name of the array which will hold the pixel data File to read: in this case lena64.bmp is a 8x8 image with a gray scale colormap Dr. D. J. Jackson Lecture 4-7 Displaying the image To display the image in the current figure, use the image() command image(lena); Dr. D. J. Jackson Lecture 4-8
Setting the colormap To set the colormap for a particular figure, use the colormap() function colormap(lmap); combined commands: image(lena);colormap(lmap); Dr. D. J. Jackson Lecture 4-9 Other ways of viewing the image The image() command gives an expected visual representation of an image Other views of the image, say perhaps as a three-d plot, may reveal information about the image not obvious in a -D representation The mesh() command will display a -D mesh plot of the image data with a default viewing perspective The view() command allows selection of a user specified viewpoint view(-5,-70) seems to be a good choice Dr. D. J. Jackson Lecture 4-0
Alternate view of lena64.bmp figure();mesh(lena);view(-5,-70); Dr. D. J. Jackson Lecture 4- View with modified axis and colormap colormap(lmap); axis([0 7 0 7 0 55]); Dr. D. J. Jackson Lecture 4-
Dr. D. J. Jackson Lecture 4- Creating arrays Arrays and/or matrices may be entered as follows: EDU» A[ ]; Creates a x matrix A[ ; ; ]; accomplishes the same thing A Dr. D. J. Jackson Lecture 4-4 Multiplying matrices Given matrices: Performing CA*B yields: Performing DA.*B yields: (an element-by-element multiply) A B 8 6 8 6 8 6 C 9 4 9 4 9 4 D
Other matrix operations Scalar operations: addition & multiplication Powers of arrays Obtaining matrix sizes and values size(), length(), max(), min() Creating special arrays: all zeros, all ones, diagonal, etc. zeros(), ones(), linspace(), rand(), diag() Array searches and comparisons Logical operations Dr. D. J. Jackson Lecture 4-5