Written and maintained by CASRAI Editorial Board
Published
On this page
Speeded-Up Robust Features (SURF) in MATLAB are found with detectSURFFeatures, described with extractFeatures and paired between two images with matchFeatures. All three functions come from the Computer Vision Toolbox. This page gives the whole detect, extract, match and display workflow in one place, with the documented defaults and what each parameter does when you change it. Function behaviour below is taken from the MathWorks reference pages read on 2026-11-07.
Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.
What SURF is used for in research
SURF is a scale- and rotation-invariant interest point detector and descriptor. The ETH Zurich project page describes it as “a performant scale- and rotation-invariant interest point detector and descriptor”, and attributes its speed to integral images, a Hessian-matrix-based detector and a simplified, distribution-based descriptor. The original reference is Bay, Ess, Tuytelaars and Van Gool, “SURF: Speeded Up Robust Features”, presented at ECCV 2006; cite it when you report results that depend on the method.
In practice, researchers use a SURF workflow to find the same physical structure in two images that differ in scale, rotation or viewpoint: registering microscopy or remote-sensing frames, aligning repeated scans, or tracking a feature across a sequence. A reproducible write-up should record the toolbox release, every non-default parameter and the images used; see reproducibility infrastructure for code sharing and the definition of computational reproducibility.
Install or access (official source only)
The functions require Computer Vision Toolbox, which is a MathWorks add-on to MATLAB. Licensing and add-on installation are handled through MathWorks (the Add-On Explorer or your institution’s licence administrator); this page does not cover pricing. If you are new to the environment, what MATLAB is used for gives the background, and the official reference pages are listed under Sources below.
Step-by-step: detect, describe, match and display
This sequence uses only functions documented on the MathWorks pages. The second image is created by rotating and enlarging the first, so you can run it without any data files.
- Load a grayscale image.
detectSURFFeaturesaccepts a real, non-sparse 2-D grayscale or binary image of type single, double, int16, uint8, uint16 or logical. A colour image must be converted first, for example withrgb2gray. - Detect SURF points with
points = detectSURFFeatures(I), or with options:detectSURFFeatures(I,'MetricThreshold',100). The result is aSURFPointsobject. - Extract descriptors with
[features,validPoints] = extractFeatures(I,points). WithSURFPointsinput the method is chosen automatically (“Auto”) and SURF descriptors are computed. - Match descriptors between two images with
indexPairs = matchFeatures(features1,features2). - Display the matches with
showMatchedFeatures.
I1 = imread('cameraman.tif');
I2 = imresize(imrotate(I1,-20),1.2);
points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);
[features1,validPoints1] = extractFeatures(I1,points1);
[features2,validPoints2] = extractFeatures(I2,points2);
indexPairs = matchFeatures(features1,features2);
matched1 = validPoints1(indexPairs(:,1));
matched2 = validPoints2(indexPairs(:,2));
showMatchedFeatures(I1,I2,matched1,matched2,'montage');
The documentation’s own single-image example is I = imread('cameraman.tif'); points = detectSURFFeatures(I); imshow(I); hold on; plot(points.selectStrongest(10));, which overlays the ten strongest blobs.
Parameters that change the result
Defaults and ranges below are from the MathWorks reference pages for detectSURFFeatures, extractFeatures and matchFeatures.
| Function | Parameter | Default | Effect |
|---|---|---|---|
| detectSURFFeatures | MetricThreshold | 1000.0 (non-negative) | Lower values return more blobs; raise it to keep only strong ones. |
| detectSURFFeatures | NumOctaves | 3 (integer ≥ 1; 1-4 recommended) | More octaves find larger blobs. A 50-by-50 image should use 2 or fewer. |
| detectSURFFeatures | NumScaleLevels | 4 (integer ≥ 3; 3-6 recommended) | Number of scale levels computed per octave. |
| detectSURFFeatures | ROI | Whole image, [1 1 size(I,2) size(I,1)] | Rectangle [x y width height] restricting detection to a region. |
| extractFeatures | FeatureSize | 64 (or 128; SURF and KAZE only) | 128 is more accurate but slows matching. |
| matchFeatures | MaxRatio | 0.6 | Ratio test threshold applied to the match. |
| matchFeatures | MatchThreshold | 1.0 for non-binary features (10.0 for binary) | Distance limit for accepting a match. |
| matchFeatures | Method | Exhaustive | “Approximate” is the alternative for large feature sets. |
| matchFeatures | Metric | SSD | SAD is the alternative; binary features use Hamming distance. |
| matchFeatures | Unique | false | true performs a forward-backward match. |
Output and how to read it
points(SURFPoints). TheLocationproperty holds the coordinates.selectStrongest(n)returns the n strongest points.featuresandvalidPoints. For SURF,featuresis an M-by-N matrix with one descriptor per row (N is 64 or 128).validPointsare the points that received a descriptor; points too close to the image edge are dropped, sovalidPointscan be shorter thanpoints. For SURF, theOrientationofvalidPointsis set (in radians).indexPairs. A P-by-2 matrix: column 1 indexesfeatures1, column 2 indexesfeatures2. IndexvalidPointswith these columns, not the originalpoints, because the rows offeaturescorrespond tovalidPoints.matchmetric. The optional second output ofmatchFeaturesis a P-by-1 vector of distances between matched features; 0 is a perfect match, and for SSD the range is [0, 4].- The display.
showMatchedFeaturesoverlays the two images as a red-cyan composite by default (falsecolor); the'montage'option shows the two images side by side.
Troubleshooting
Too few points are detected
Lower MetricThreshold (the documentation example drops it from the default 1000 to 100). On small images reduce NumOctaves as recommended above.
Too many weak points
Raise MetricThreshold, restrict the search with ROI, or keep a fixed number with points.selectStrongest(n).
The function rejects my image
The input must be a real, non-sparse 2-D grayscale or binary image. Convert RGB data with rgb2gray and avoid complex or sparse arrays.
Fewer valid points than detected points
This is expected: extractFeatures discards points too near the image edge, and returns only the survivors in validPoints.
Many wrong matches
Set 'Unique',true to require forward-backward agreement, or tighten MaxRatio or MatchThreshold. Using 128-element descriptors ('FeatureSize',128) is documented as more accurate at the cost of slower matching.
Code generation
The documentation states that MATLAB Coder and GPU Coder are supported, but arrays of point objects are not; pass points.Location (an M-by-2 matrix) instead.
Free alternatives
SURF in MATLAB needs a toolbox licence. The table lists open-source implementations whose source declarations were read on 2026-11-07; check the licence and any patent position yourself before using a method in a product.
| Method | Where it lives | Documented note |
|---|---|---|
| SURF | OpenCV contrib repository, module xfeatures2d (group “xfeatures2d_nonfree”) |
Parameters: hessianThreshold, nOctaves, nOctaveLayers, extended (128-element descriptors), upright (skip orientation). The README lists it under “non-free 2D feature algorithms”. |
| SIFT | OpenCV main repository, features2d |
Declared as cv::SIFT. |
| ORB | OpenCV main repository, features2d |
Declared as cv::ORB; described as an oriented BRIEF detector and descriptor extractor. |
| KAZE / AKAZE | OpenCV main repository, features2d |
Declared as cv::KAZE and cv::AKAZE. |
| BRISK | OpenCV main repository, features2d |
Declared as cv::BRISK. |
Inside MATLAB, extractFeatures also lists SIFT, BRISK, FREAK, ORB, KAZE and Block as Method options, so a different descriptor can be swapped into the same workflow. For other MATLAB tasks, see matrices in MATLAB.
FAQ
What do I need to run speeded-up robust features in MATLAB?
Computer Vision Toolbox, which provides detectSURFFeatures, extractFeatures and matchFeatures, plus a grayscale (or binary) 2-D image.
What does detectSURFFeatures return?
A SURFPoints object; read coordinates from its Location property and select the strongest points with selectStrongest.
How do I get more or fewer SURF points?
Change MetricThreshold: lower returns more blobs, higher returns fewer. The default is 1000.0.
Should I use 64 or 128 descriptor elements?
64 is the default. 128 ('FeatureSize',128) is documented as more accurate but slower to match.
Does SURF work on colour images?
Not directly; convert to grayscale first (for example with rgb2gray).
Sources (official documentation, read 2026-11-07)
- MathWorks, detectSURFFeatures
- MathWorks, extractFeatures
- MathWorks, matchFeatures
- MathWorks, showMatchedFeatures
- ETH Zurich, SURF: Speeded Up Robust Features project page; original paper: Bay, Ess, Tuytelaars, Van Gool, ECCV 2006
- OpenCV, opencv_contrib xfeatures2d and features2d.hpp







