A case study

In the following exercise you are going to optimize a Matlab code. The code is extremely inefficient and it is possible to speed it up quite substantially. The speedup you will get depends on your proficiency in using Matlab. The version of Matlab and what computer you are using are important factors as well. A speedup by a factor of 10-50  is reasonable.

The code is doing some simple image processing and I want you to speed it up by writing better basic Matlab code. You should not try to replace code by faster builtin image toolbox routines (there is a Matlab-version of edges, for example).

In a real code one should always try to use the fastest algorithm of course, but this assignment is an exercise in code optimization and not in algorithm development.

You need the following three m-files :   run.m    average.m    edges.m

run is the main-routine and you run the code by typing run . Start by reading through it. You should optimize average and edges (not run, so it should be possible to call the functions in the same way as before the optimization took place)

The following image (a jpg-file) is necessary as well. This image, which is a standard test image in image compression, has an amusing background. I heard it the first time, many years ago, when attending a lecture on fractal image compression. Here are a few links (of quite a few): Lena1, another link Lena2 (I doubt that her present last name is Soderberg, the Swedish Söderberg is more likely).

To save files (using Netscape or Mozilla): press, and hold down, the right-most mouse button on the file and choose Save Link Target As...

The code is rather horrible, when viewed in a Matlab perspective. It would not be too bad if we had used a compiled language (although, the code have been optimized in that case as well). It would have been easy to make the Matlab code even slower (by using if-statements in the main-loop to handle borders and corners in average, for example).


Back