Images In Matlab

If you are not already familiar with Matlab, you might be interested in ``Användarhandledning till Matlab", that can be bought at CSCs studentexpedition. You may also read through the first sections of Chapter 2 in the ``Matlab's User's Guide'', while trying out some examples on your computer. Note that Matlab has a built-in help facility based on the command help. Thus it might be possible to use the system based solely on this functionality, given the short introduction found below.

Starting up Matlab

Before you start Matlab for the first time, you should check the search paths. On CSCs Unix machines you do this with

module load /info/bildat12/module/bildat12

Then you can start Matlab by issuing matlab.

Within a few seconds a window with the Matlab logo will be shown, and moments later a window with a welcoming message and a prompt. If not, make sure that all above mentioned instructions have been properly followed. 

Loading and displaying images

Images in Matlab's binary format.

In order to load one of the binary images from the image database of this course, you may e.g. write

load canoe256

With command who you can now see the following variables defined in Matlab

Canoe zmax zmin

Here the variable Canoe includes the image. You may then display the image using the function showgrey, which has specifically been written for this lab course

showgrey(Canoe)

Images in the ASCII-based format.

To load one of the images stored in the ASCII-based text format, you may e.g. write

phone = phonecalc256;

This operation assigns the value of the image to the variable phone, and the semi-colon suppresses an output of the result of this assignment. (As noted this format require considerable more time for an image to be read.) If you wish to see the result display, use

showgrey(phone)

You may test another similar image, using a shorter notation, with

showgrey(nallo128)

As you see the contrasts are somewhat low in the lower part of the image. In the first lab we will try to use different methods to improve the images in order to highlight information that can otherwise be hard to see.

Your own images.

If you have your own images that you like to process, you may use Matlab's embedded function imread, that is able to handle a number of different image formats, including tiff and jpeg -- see help imread. You read such an image with the sequence

rawpic = imread('image.tif'); 
floatpic = double(rawpic); 
showgrey(floatpic);

Observe that you need to convert the image with the command double, before you can use the output of imread for lab related functions such as showgrey.

Conversions of image formats can be done in CSCs computer environments using a program called convert, that is able to convert image between a large range of file formats. In order to assign with formats you like to convert between you just apply the suffixes corresponding to the formats at the end of the file names, such as

module add gnome 
convert image.gif image.tiff 
convert onepage.ps onepage.tiff

You may also use the interactive program xv for image conversions and in order to grab images directly from the screen.

Clean up old images.

If you use a large number of images, there might be a risk that you hit the memory limit, below which Matlab is able to effectively function. In order to clean up old images and data structures, simply write

clear

and then control with who whether all variables have indeed been erased. You may close a Matlab window with

close

or by terminating Matlab with

exit

In the forthcoming text, a short introduction to Matlab will be given for students who are not yet familiar with the system. For an experienced user most of this information might not be of interest. However, also these users might benefit from reading the sections called ``Syntax and computational efficiency'', ``Coordinate systems'' and ``Memory usage''. In order to facilitate presentations of labs you should particularly study the guidelines in section ``Scripts''.

Feedback Nyheter