EE437: Matlab
 Home  Contact Me  Schedule  Courses  Links

Imaging Lab:

NOTE: Some of this information has been outdated since the upgrade to Matlab 5! I�ll revise it someday...

  • First time only:  Once you have logged into the SGI, create your initial MATLAB startup file by typing the following exactly as shown into a terminal window:

cp ~doering/startup.m .

  • Startup file:  The startup.m file is a text file which contains commands that you want to execute every time you start MATLAB. The file you copied in the previous step contains commands to add course-specific directories to your MATLAB search path.  You can add your own commands to the startup file simply by editing your startup.m file as needed.
     
  • Instructor-provided m-files:  Some of the standard m-files (Matlab files) that I have written and use in class are available to you on the SGI.  These include:
       - PROFILES: dynamically display row/column profile plots
       - ROAM: dynamically display a zoomed subimage
       - ISHOW: display an 8-bit graylevel image with a colorbar
       - IHIST: display the histogram of an 8-bit graylevel image
       - IMAX: report the maximum pixel value in the image
       - IMIN: report the minimum pixel value in the image
       - PGMREAD: read a PGM-format image from a file
       - PGMWRITE: write a PGM-format image to a file

    Type 'help function_name' at the MATLAB prompt to get more details.

Working with Images:

  • Image Processing Toolbox:  The Image Processing Toolbox contains many functions for working with image data. Type 'help images' to see a brief description of the available functions, then type 'help fnc' (where 'fnc' is the function name of interest) to get the details.
     
  • Loading a GIF-format image file:  Use GIFREAD(string), where 'string' is a string variable (delimeted by apostrophes) containing the file name. GIFREAD returns the image data and a colormap.  For example, the command

    [x,map]=gifread('image.gif');

    loads 2-D image data into the variable 'x', and an n-by-3 matrix into the variable 'map' which lists an RGB (red/green/blue) tuple for each index value in the image data.  For example, all pixels with value 5 in the variable 'x' are associated with the RGB tuple stored in 'map(5,:)'.  If the image is a graylevel image, then 'x' is the image data you want, and the 'map' variable is superfluous.  If the image contains color information, then you need to convert the image to a grayscale image before continuing (see next item).
     
  • Converting from an indexed color image to grayscale image: Assuming you have just done a GIFREAD() to load an indexed image 'x' and a colormap 'map', do this:

    y=ind2gray(x,map);
     
  • Displaying an image:  IMSHOW(x,map) will do the job nicely.
     
  • Displaying images on a 1-to-1 pixel mapping:  Use TRUESIZE.  IMSHOW scales the image size to fit nicely on the screen.  Sometimes this leads to odd effects in the display, at which times you would like to be able to exactly map the image onto the pixel array of your display device.

Helpful Tips:

  • Working with .m files:  Any .m files that you create must reside in MATLAB's search path. Type path to see the list of directories in the search path; type path(path,'C:\mydir') to append the directory "mydir" ("my directory") to the list of directories MATLAB will search (if you are in Unix, use a Unix-style path name).  Now, any .m files you make in "mydir" will be found when you enter the base filename at the MATLAB prompt.  Caution: Simply entering  path('C:\mydir') replaces the existing path with your own, making MATLAB unable to locate its own functions.
     
  • Creating .m files in Windows95:  If you use the Notepad editor in Windows95 to create and edit Matlab scripts, click here to find out how to disable the automatic appendage of the '.txt' extension.  I recommend the Programmer's File Editor (PFE) as an editor more suited to working with .m files.
     
  • MATLAB tutorials: Look here for a basic introduction.
     
  • MATLAB on-line reference: Look right here.
     
  • MATLAB website: The MathWorks (makers of MATLAB) maintains a comprehensive site, including user-contributed .m files.
[Home] [Contact Me] [Schedule] [Courses] [Links]
Picture
ECE RHIT