MATLAB stuff

On this page you will find some of the utilities I wrote for use under MATLAB. Most of them are useful in image processing.

NOTE for the stuff you can download directly from this page: This is free software, so I don't want to be held responsible for any mal- or disfunction. I don't gain anything from giving you this software, so don't expect any support. I'll be willing to answer questions, though, if you ask nicely.

DIPimage toolbox

The DIPimage toolbox started out in 1999 as a mayor effort to use the DIPlib library under MATLAB. It has evolved into the main image processing environment for many research groups around the world, and is extensively used in teaching as well. It is still under active development by myself and others.


segmentgui - Interactively define a threshold level to segment an image.
Requires the DIPimage toolbox.

clipgui - Interactively define two grey-value levels at which to clip an image.
Requires the DIPimage toolbox.


snakes_with_class.zip contains several files implementing snakes for DIPimage. They show how to:

Requires the DIPimage toolbox.


drawline - Draws a line through an image. The line is specified by a point and an angle. It is possible to specify the grayvalue for the line, as well as its thickness. If no thickness is specified, a 1-pixel line is drawn by selectively setting pixels. If the thickness is specified, a line with a gaussian profile is drawn; the thickness is the sigma for the gaussian.
Note this function is different to the one with the same name in the DIPimage toolbox.

Image file formats

BioradMRC.zip is a collection of four MEX-files that read an image from a file in the Biorad MRC format, which is used by Biorad microscopes:

Code in these functions is based on stuff written by Geert van Kempen.

To compile the MEX-files, type: mex readmrc.c You need to have a compiler installed, and have mex configured.

The DIPimage toolbox also contains functions to read files in the Biorad MRC format.


The library libics contains two MEX-files (in the support directory) to read and write ICS files. ICS is an image file format that supports any data type and any image dimensionality.
You need to have a compiler installed, and have mex configured.

The DIPimage toolbox contains better functions to read and write files in the ICS format.

Assorted utilities

percentile - Percentile value of input array. Another function not in the MATLAB toolbox... I copied median and modified it a bit, so it's mostly code by The MathWorks.

student_t - Returns the right-critical value of the Student distribution for a=0.025 and any number of degrees of freedom. Use this to compute the 95% confidence interval of the mean of a set of samples, as done by confidenceinterval (below).

confidenceinterval - Returns the right-critical value for the 95% confidence interval of the location of the mean of a set of samples.


prettyplot - Prettier linear plot. Works just like plot, but avoids the line and markers being on top of each other. Instead, the line joins the markers without touching them.

boxplot - Elegant box plot. Plots grouped data as a box with whiskers, indicating min, 25th percentile, median, 75th percentile, and max. Optionally plots outliers (points outside of 1.5 IQR) as dots.

adjustpdfpage - MATLAB writes figures to PDF files as a full page. This function corrects that, by setting the bounding box of the PDF file to match that of the figure window.

svg_fix_viewbox - SVG files written by the new MATLAB graphics engine have a fixed view. This function corrects that, making them stretch to the containing HTML element. Without this trick, your SVG files will not listen to any sizing commands when embedding them in a web page.

movelegend - Moves the legend of an axes to one of the positions defined in legend. legend doesn't allow to move the legend once it's created, so here you have. [This is really old, I don't know if it still works with the new graphics engine.]


np2 - Next higher power of 2. np2 is the same as nextpow2, except that it can work on arrays.

cell2str - Convert cell array into evaluable string. This one's missing in the MATLAB toolbox! Similar to mat2str. Recently extended to remove most of the constraints. It should be possible to rename this as @cell/mat2str.m!

mvfield - Rename structure field. This one's also missing in the MATLAB toolbox! Goes well together with rmfield.

clearallbut - Clear all variables except those given. I've needed such a function way too often. No more typing out all variable names! (Note that this function is now obsolete; in newer MATLABs you can do clearvars -except.)

Valid HTML 4.01! Valid CSS! © 2001-2015 Cris Luengo
Last modified June 9, 2015.