Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
A L L A H PowerPoint Presentation

A L L A H

124 Views Download Presentation
Download Presentation

A L L A H

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. A L L A H

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

  3. 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 –

  4. 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 :–

  5. 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:–

  6. 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

  7. 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. Matlabprograms 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

  8. 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 -

  9. 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.

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

  11. 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.

  12. Saving and printing graphics • You use the Matlabprint 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 :-

  13. 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 :–

  14. 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 –

  15. 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) :–

  16. 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:-

  17. Assignment

  18. 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 :–

  19. Creating and Dealing With Larger Arrays

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

  21. Avoiding loops

  22. Determining the size of arrays

  23. Here are some fun examples to try out :–

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

  25. Try some of these basic examples –

  26. If statements If else statements

  27. If else statements

  28. For loop

  29. Indexing Vectors

  30. Indexing Vectors contd..

  31. Indexing Vectors contd..

  32. Indexing Vectors contd..

  33. Indexing Vectors contd..

  34. MATLAB Image Processing Toolbox

  35. Introduction • Collection of functions (MATLAB files) that supports a wide range of image processing operations • Documentation www.mathworks.com

  36. 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’);

  37. Display an Image imshow(I)

  38. Check the Image in Memory • < Name, Size, Bytes, Class > whos Name Size Bytes Class ans 291x240 69840 uint8 array Grand total is 69840 elements using 69840 bytes

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

  40. Histogram Equalization (cont.)

  41. Histogram Equalization (cont.)

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

  43. 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)

  44. Morphological Opening (cont.)

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

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