UWA logo

School of Computer Science
& Software Engineering
Computer Vision 233.412


How To...


How to transfer files to and from CS machines via floppy disc

Under Linux a floppy disc (or CD) has to be mounted before you can access its contents. Note that files are written to the floppy in Windows VFAT format so you can read your floppy on a Windows machine.

How to print out matrix values to a desired number of decimal places

It is surprising that there is no convenient fine control of output format in MATLAB. Here is a function matprint.m that allows you to print out values to a desired number of decimal places using C style formatting commands.


How to set colours, line widths and font sizes of graphics objects in MATLAB

Every thing that you draw on the screen is, in fact, a graphics object that you can manipulate and change after it is drawn. Each of the graphics drawing functions returns a handle, or reference, to the graphics object. For example:
>> h = text(0.5, 0.5, 'hello');   % Print 'hello' at position [0.5 0.5]
Now get the attributes of the graphics object
>> get(h)
        Color = [0 0 0]
        EraseMode = normal
        Editing = off
        Extent = [0.496222 0.474522 0.0579345 0.0477707]
        FontAngle = normal
        FontName = Helvetica
        FontSize = [10]
        FontUnits = points
        FontWeight = normal
        HorizontalAlignment = left
        Position = [0.5 0.5 0]
        Rotation = [0]
        String = hello
        Units = data
        Interpreter = tex
        VerticalAlignment = middle
         ... + other stuff 

>> 
You can then change any of these attributes using the set function specifying the attribute name (as a string) followed by the new attribute value. To change the text written above to a red colour and font size of 16 we would use the following command
>> set(h,'Color',[1 0 0],'FontSize',16);
More conveniently you can do the drawing and setting of attributes in the one command, here are some examples
>> text(0.5, 0.5, 'hello','Color',[1 0 0],'FontSize',16); line([0 1],[0 1])        
>> line([0 1],[0 1],'LineWidth',2)        
Do a 'help' on get and set for more information

How to use MATLAB's line and plot commands

The line and plot commands both take as arguments separate arrays of the x and y coordinates that you wish to draw. Thus if you wish to draw a series of line segments through the points
[x1 y1], [x2 y2], [x3 y3] 
you would use the command
>> line([x1 x2 x3], [y1 y2 y3])
Note how you have to separate out the x and y coordinates into separate arrays.

Both line and plot draw into the current figure window. By default this will be the last figure that you used. You can specify a specific figure window using the figure command, for example

>> figure(3)                      % Make figure(3) 'active'.
>> line([x1 x2 x3], [y1 y2 y3])   % Draw a line in figure 3.

The plot command clears the figure before drawing, the line command does not. You can prevent plot from clearing a figure using the command

>> hold on

How to make a test image containing a circular object

Look at the code in circularstruct.m. This function is for generating circular structuring elements for morphological operations.


Set MATLABPATH so that you can access your MATLAB functions from any directory

You can define a system variable called 'MATLABPATH' which is a list of directory (folder) names, separated by colons, in which MATLAB will always search to find your MATLAB function files.

For example if you have MATLAB '.m' files in subdirectories IT412 and IT412/lab2 you would edit your '.zshrc' file (found in your home directory) and append a line as follows:

export MATLABPATH=$HOME/IT412:$HOME/IT412/lab2
(HOME is a predefined system variable that specifies your home directory)

You will need to log out and log in again, or run the command

 
% source .zshrc
within the terminal window that you want to use MATLAB for your definition of MATLABPATH to take effect. Now you will be able to run your MATLAB functions from any directory


Avoid MATLAB's very slow Java GUI interface

While MATLAB is fairly fast the GUI interface to MATLAB is written in Java and runs very slowly.

To avoid the GUI interface invoke MATLAB as follows:

 % matlab -nojvm     (do not run it in background ie don't use an & at the end)
This starts MATLAB up without the Java Virtual Machine interface. MATLAB will start up very quickly and just give you a command window. You will find its response much, much more 'snappy'.

To create and edit command files you will have to use a separate text editor such as emacs, vi, vim or pico.


Use MATLAB efficiently with emacs

MathWorks have written a MATLAB configuration file for emacs. When you edit a MATLAB file in emacs you will have all the keywords highlighted, formatting enabled, and even the spellchecking will only check your comments!

Download the following two files to your top home directory

If you use emacs to edit your files, and hence have no need for MATLAB's editor, invoke MATLAB as follows:

 % matlab -nojvm     (do not run it in background ie don't use an & at the end)
This starts MATLAB up without the Java Virtual Machine interface. MATLAB will start up very quickly and just give you a command window. You will find its response much, much more 'snappy'.

Set up symbolic links to the image directories

I suggest that you set up sybolic links from your area to the image directories. This will give you direct access to any new images that are placed in these directories and save having multiple copies of images all over the place. The commands

     prompt% ln -s /cslinux/examples/it412/Images   Images
     prompt% ln -s /cslinux/examples/it412/ClassOf2002   ClassOf2002
will create two symbolic links Images and ClassOf2002 in your area that will take you directly to these directories.