MATLAB and Octave Functions
for Computer Vision and Image Processing
School of Computer Science & Software Engineering
The University of Western Australia
Crawley, Western Autralia. 6009
|
|
I now only hold an adjunct appointment with UWA.
I am not in a position to take on new graduate students or offer
internships.
I receive so many mail messages regarding this
site that I have difficulty responding to them all.
I will endeavor to respond to mail
that directly concerns the use of individual functions.
However, please note I do not have the time to provide an on-line vision
problem solving service!
Please report any bugs and/or suggest enhancements to
Cheers,
Peter Kovesi
The complete set of these functions is available as a gzipped tar file
MatlabFns.tar.gz for Unix users.
Once you have untarred this file MATLAB users should remove the Octave
subdirectory from this package (or ensure it is not in your MATLAB
path) to avoid problems.
Note that I develop my code under Mac OS X.
Legend for MATLAB/Octave compatibility
- Runs under MATLAB and Octave.
- Only runs under MATLAB.
- Not tested under Octave (yet).
Can't find what you want here? Have a look at
Other highly recommended Computer Vision software sites
Feature detection via Phase Congruency
References:
Spatial feature detection
- canny.m Canny edge
detector incorporating modifications suggested by Fleck.
- harris.m Harris corner
detector.
- fastradial.m An
implementation of Loy and Zelinski's fast radial feature
detector.
Reference:
- Scanned images of my
photocopy of Harris and Stephens' paper 'A Combined Corner and Edge
Detector'.
Integral Images
- integralimage.m computes
integral image of an image.
- integralfilter.m
performs filtering using an integral image.
- intfilttranspose.m
transposes an integral image filter specification.
- integaverage.m
performs averaging filtering using an integral image. Computation
cost is independent of averaging filter size.
-
integgausfilt.m
This function approximates Gaussian filtering by repeatedly applying
integaverag.m . This allows smoothing at a very low computational cost
that is independent of the Gaussian size.
- solveinteg.m
This function is used by integgausfilt.m to solve for the multiple averaging
filter widths needed to approximate a Gaussian of desired standard deviation.
Reference:
- Draft note describing
high speed approximate Gaussian filtering via integral images.
Non-maxima suppression and hysteresis thresholding
- nonmaxsup.m Code for
performing non-maxima suppression for edge images.
- nonmaxsuppts.m Code
for performing non-maxima suppression and thresholding of points
generated by a feature/corner detector. It optionally returns
sub-pixel feature locations.
- hysthresh.m code for
performing hysteresis thresholding.
- smoothorient.m
applies smoothing to an orientation field which can be useful before
applying nonmaximal suppression.
- adaptivethresh.m
an implementation of Wellner's adaptive thresholding method.
Edge linking and line segment fitting
image |
edges |
labeled edges |
fitted line segments |
- edgelink.m edge
linking function that forms lists of connected edge points from a
binary edge image. (Needs findendsjunctions and cleanedgelist below).
- drawedgelist.m
plots out a set of edge lists generated by edgelink or lineseg.
- edgelist2image.m
transfers edgelist data back into a 2D image array.
- lineseg.m forms
straight line segments fitted with a specified tolerance to the lists
of connected edge points.
- maxlinedev.m is
also used by lineseg.m to calculate deviations of the edge lists from
the fitted segments.
- findendsjunctions.m
finds line junctions and endings in a line/edge image.
- cleanedgelist.m cleans up a
set of edge lists generated by edgelink or lineseg so that isolated
edges and spurs that are shorter than a minimum length are removed.
- Example of using these
functions above.
Test grating for edge detection
Test image |
Canny edge image |
Phase congruency |
Colour coded for feature type |
- step2line.m
Generates a test image where the feature type changes from a step edge
to a line feature from top to bottom, while retaining perfect phase
congruency. This test image indicates the importance of phase
congruency irrespective of the angle at which congruency occurs at
and, up to a point, irrespective of the rate at which the amplitude
spectrum decays with frequency. A gradient based edge detector
produces a double response for all features that have congruence of
phase at angles other than zero (towards the bottom of the test
image). The phase congruency detector marks features with a single
response. The colour coded image was generated by dispfeat.m
Image denoising
Reference:
Surface normals to Surfaces

Surface Normals |
|

Surface Reconstruction |
- shapeletsurf.m
Function reconstructs an estimate of a surface from its surface
normals by correlating the surface normals with that those of a bank
of shapelet basis functions. The correlation results are summed to
produce the reconstruction. The sumation of shapelet basis functions
results in an implicit integration of the surface while enforcing
surface continuity.
Note that the reconstruction is only valid up to a scale factor
(which can be corrected for). However the reconstruction process is
very robust to noise and to missing data values. Reconstructions (up
to positive/negative shape ambiguity) are possible where there is an
ambiguity of pi in tilt values. Low quality reconstructions are also
possible with just slant, or just tilt data alone. However, if you
have full gradient information you are better off with the Frankot
Chellappa algorithm below.
- frankotchellappa.m An
implementation of Frankot and Chellappa's algorithm for constructing
an integrable surface from gradient information. If you have full
gradient information in x and y this is probably the best algorithm to
use. It is very simple, very fast and highly robust to noise. If you
have surface normal information in the form of slant and tilt, and you
have an ambiguity of pi in your tilt data, or only have slant, then
try using shapeltsurf.m above.
- grad2slanttilt.m
Converts gradient values over a surface to slant and tilt angles.
- slanttilt2grad.m
Converts slant and tilt angles over a surface to gradients.
- needleplotgrad.m
Generates a needle plot given surface gradients over a surface.
- needleplotst.m Generates a
needle plot given slant and tilt values over a surface.
- testp.m Generates a
synthetic test surface along with its surface normals for testing
shapeletsurf.
Reference:
Scalogram calculation
- scalogram.m
Function to calculate the phase and amplitude scalograms of a 1D
signal. The analysis is done using quadrature pairs of log Gabor
wavelets.
Anisotropic diffusion
- anisodiff.m Function
to perform anisotropic diffusion of an image following Perona and
Malik's algorithm. This process smoothes regions while preserving,
and enhancing, the contrast at sharp intensity gradients.
Grey scale transformation and enhancement
- extractfields.m
separates fields from a video frame, and optionally interpolates
intermediate lines.
- interpfields.m
interpolates lines on a field extracted from a video frame.
- normalise.m rescales
image values to 0-1.
- adjcontrast.m
adjusts image contrast using sigmoid function.
- adjgamma.m adjusts
image gamma.
- greytrans.m allows
you to interactively remap intensity values in a colour or greyscale
image via a mapping function defined by a series of spline points. A
feeble attempt at replicating xv's intensity mapping tool. It
is not as fast but it does operate on floating point images allowing
you to better preserve image fidelity. (Needs remapim.m).
- remapim.m is a non-interactive
version of greytrans that allows you to apply an intensity mapping to
a colour or greyscale image using a mapping function determined
experimentally with greytrans. Useful if you want to apply the same
mapping function to a sequence of images.
- histtruncate.m
truncates ends of an image histogram. Useful for enhancing images
with outlying values.
- Example of using some of
these functions above to enhance a video image. However you should
note that many surveillance systems are close to being legally blind.
See Video
Surveillance: Legally Blind? DICTA 2009 Melbourne.
Frequency domain transformations
- lowpassfilter.m constructs
low-pass Butterworth filter.
- highpassfilter.m constructs
high-pass Butterworth filter.
- highboostfilter.m constructs
high-boost Butterworth filter.
- bandpassfilter.m constructs
band-pass Butterworth filter.
- homomorphic.m
performs homomorphic filtering on an image. One of my favourite image
enhancement techniques. (needs histtruncate.m and normalise.m)
- psf.m generates a
variety of point-spread functions. This function can be useful when
manually specifying point-spread functions for Wiener filtering or
with deconvolution functions such as the Richardson-Lucy algorithm
(see the MATLAB image toolbox function deconvlucy.m).
- psf2.m is identical
to psf, it just has a different way of specifying the function shape
which may be more convenient for some applications.
- imspect.m plots
image amplitude spectrum averaged over all orientations.
- freqcomp.m
demonstrates image reconstruction from its Fourier components.
Functions supporting projective geometry
 image of beach |
 rectified beach |
- homography1d.m
computes the 2x2 1D homography of 3 or more points along a line.
- homography2d.m
computes the 3x3 2D homography of 4 or more points in a plane. This
code follows the normalised direct linear transformation algorithm
given by Hartley and Zisserman.
- fundmatrix.m
computes the fundamental matrix from 8 or more matching points in a
stereo pair of images using the normalised 8 point algorithm.
- affinefundmatrix.m computes the
affine fundamental matrix from 4 or more matching points in a stereo
pair of images.
- fundfromcameras.m computes fundamental matrix
given two camera projection matrices.
- normalise2dpts.m translates and
normalises a set of 2D homogeneous points so that their centroid is at
the origin and their mean distance from the origin is sqrt(2). This
is used to improve the conditioning of any equations used to solve
homographies, fundamental matrices etc.
- hnormalise.m
normalises an array of homogeneous coordinates so that their scale
parameter is 1. Points at infinity are unchanged.
- imTrans.m applies a homogeneous
transform to an image.
- digiplane.m allows
you to digitise and transform points within a planar region in an
image.
- equalAngleConstraint.m Affine
transform constraints given two equal angles.
- knownAngleConstraint.m Affine
transform constraints given a known angle.
- lengthRatioConstraint Affine
transform constraints given a length ratio.
- circleintersect.m Finds
intersection of two circles. Use this function to solve for affine
transformation constraints.
- circle.m Draws a
circle.
- hcross.m Homogeneous
cross product, result normalised to s = 1.
- hline.m Plot 2D lines
defined in homogeneous coordinates.
- homoTrans 2D homogeneous
transformation of points/lines.
- plotPoint.m Plots
point with specified mark and optional text label.
- If you are using these functions above you should look at
Andrew
Zisserman's
MATLAB Functions for Multiple View Geometry
Also, you must
listen to The Fundamental
Matrix Song by Daniel Wedge.
Matching
- matchbycorrelation.m generates
putative matches between previously detected feature points in two
images by looking for points that are maximally correlated with each
other within windows surrounding each point. Only points that
correlate most strongly with each other in both directions are
returned. This is a simple-minded N2 comparison.
- matchbymonogenicphase.m is
similar to matchbycorrelation, but instead matches on oriented phase
values rather than greyscale values. This matcher performs rather
well relative to normalised greyscale correlation. Typically there
are more putative matches found and fewer outliers. There is a
greater computational cost in the pre-filtering stage but potentially
the matching stage is much faster as each pixel is effectively encoded
with only 3 bits. (Though this potential speed is not realized in this
implementation). See testfund
below to see an example of the use of this function.
Model fitting and Robust estimation
- ransac.m a general purpose
implementation of the RANSAC algorithm.
- ransacfithomography.m
robustly fits a homography to a set of putatively matched image points.
- ransacfitfundmatrix.m robustly
fits a fundamental matrix to a set of putatively matched image points.
This function uses an 8 point fundamental matrix solution.
- ransacfitfundmatrix7.m robustly
fits a fundamental matrix to a set of putatively matched image points.
This function requires Andrew Zisserman's 7 point fundamental matrix code
available from:
MATLAB Functions for Multiple View Geometry
- ransacfitaffinefund.m robustly
fits an affine fundamental matrix to a set of putatively matched image
points.
- ransacfitplane.m
robustly fits a plane to 3D data points.
- ransacfitline.m
robustly fits a line to 3D data points.
- iscolinear.m tests if
3 points are colinear, used by ransacfitplane and ransacfithomography.
- fitline.m least squares
fit of a line to 2D data points.
- fitline3d.m least squares
fit of a line to 3D data points. Contributed by Felix Duvallet.
- fitplane.m least squares
fit of a plane to 3D data points.
- testfitplane
example of using ransacfitplane.m
- testfitline
example of using ransacfitline.m
- testfund
example of using ransacfitfundmatrix.m
- testhomog
example of using ransacfithoography.m
- randomsample a basic
replacement for randsample to be used with ransac.m
should you not have the statistics toolbox, or are using Octave.
- Example of using these
functions above to find the fundamental matrix.
Fingerprint enhancement
- ridgesegment.m identifies
ridge-like regions of a fingerprint image. It also normalises the
intensity values of the image.
- ridgeorient.m estimates the
local orientation of ridges in a fingerprint.
- plotridgeorient.m plots
ridge orientations calculated by ridgeorient.
- ridgefreq.m estimates the
local ridge frequency across a fingerprint image.
- freqest.m estimates the ridge
frequency within a small block of an image. This is used by
ridgefreq.
- ridgefilter.m enhances
a fingerprint image using oriented filters.
- Example of using these functions above.
Interesting images

- noiseonf.m generates noise
images with specified amplitude spectra. One can create pleasing
cloud pattern images this way.
- cloud9.m creates a movie
sequence of noise images with specified amplitude spectra. Very
relaxing.
- derespolar.m Generates
deresolved images in polar coordinates.
- polartrans.m Generates a polar
transformation of an image. A linear or logarithmic radius
transformation can be specified.
- circsine.m
Generates a test image consisting of a circular sine wave grating.
ASCII Image Generation
- matscii.m Function to
generate ASCII images from grey scale images. A bit retro but may have
applications for interesting text messages on your mobile phone!
Homogeneous Transforms
- plotframe.m plots a
coordinate frame specified by a homogeneous transform.
- trans.m homogeneous
tranlation matrix.
- rotx.m homogeneous matrix
for rotation about x-axis.
- roty.m homogeneous matrix
for rotation about y-axis.
- rotz.m homogeneous matrix
for rotation about z-axis.
- homotrans.m
homogeneous transformation of points/lines
- invht.m optimized
inverse of homogeneous transformation matrix
- inveuler.m solves for
euler angles given a homogeneous transform.
- invrpy.m solves for
roll, pitch, yaw angles given a homogeneous transform.
- dhtrans.m calculates
the 4x4 homogeneous Denavit Hartenberg matrix given link parameters of
joint angle, length, joint offset, and twist.
Quaternions
Angle-Axis Descriptors
Image Display, Image Writing and Miscellaneous
- show.m This function displays
an image, automatically setting the colour map to grey if it is a 2D
image, or leaving it as colour otherwise, and setting the axes to be
'equal'. The image is also displayed as 'TrueSize', that is, pixels
on the screen match pixels in the image. Finally a title
corresponding to the image variable name is added.
- showfft.m displays the
amplitude spectrum of an fft.
- showlogfft.m displays
the log amplitude spectrum of an fft.
- showsurf.m This function wraps up the
commands I usually use to display a surface. The surface is
displayed using SURFL with interpolated shading, in my favourite
colormap of 'copper', with rotate3d on, and axis vis3d set.
- imwritesc.m This function
combines image rescaling and writing into the one function. If the
image type is double image values are rescaled to the range
0-1 so that no overflow occurs when writing 8-bit intensity values.
The image format to use is determined by MATLAB from the file ending.
If the image type is of uint8 no rescaling is performed.
- matprint.m This function
prints out a matrix using a specified C style format string. Often
you find that MATLAB's default number formats are not what you want.
It is surprising that there is no convenient fine control of output
format. I hope this function helps.
- removenan Replaces NaN
values in a matrix with a specified default value. Useful when you
want to prevent NaNs from contaminating and destroying some operation
on an array, for example, an FFT.
- fillnan Replaces NaN
values in a matrix with the value in the closest non-Nan pixel.
- digipts.m Function to
digitise points in an image. This function uses the cross-hair cursor
provided by GINPUT. I find this is much more useable than the cursor
used by IMPIXEL. In addition each location digitised is marked with a
red '+'.
- implace.m Function to place
an image at a specified location within a larger image.
- superquad.m generates
parametric surfaces of superquadratics.
- supertorus.m generates
parametric surfaces of a supertorus.
- cubicroots.m computes
the real roots of a cubic.
- rgb2lab.m RGB to L*a*b* colour conversion.