Main Content

Structure from Motion

R2026b
Reconstruct 3-D scene structure from multiple views using incremental structure from motion, NeRF, and MapAnything models

Structure from motion (SfM) is the process of estimating the 3-D structure of a scene from a set of 2-D images taken from different viewpoints. Computer Vision Toolbox™ provides an end-to-end SfM pipeline, including feature detection, matching, camera pose estimation, triangulation, and bundle adjustment. These capabilities are essential for applications such as 3-D mapping, photogrammetry, and autonomous navigation.

The toolbox provides a ready-to-run SfM pipeline through the sfm object. Create an sfm object with your images and camera intrinsics and use its object functions to run the full reconstruction pipeline:

Use the poses, pointCloud, and plot functions to retrieve and visualize the results.

For a step-by-step comprehensive walkthrough of an incremental structure-from-motion pipeline, see the Structure from Motion from Multiple Views example. For information on how to use the sparse 3-D point cloud of a scene and generate a dense 3-D mesh, see the Dense 3-D Reconstruction of Asteroid Surface from Image Sequence example.

For dense reconstruction and novel view synthesis, the toolbox supports Neural Radiance Fields (NeRF). Use the trainNerfacto function to train a NeRF model on your collection of images and generate novel views. You can then use the point cloud to generate a 3-D mesh using the pc2surfacemesh (Point Cloud Toolbox) function.

The toolbox supports 3-D scene reconstruction from multi-view images using the MapAnything model. Use the mapanything object to create a pretrained MapAnything model and then use the reconstruct function to perform 3-D scene reconstruction and estimate the camera poses, intrinsic parameters, depth maps, and point clouds for the images.

Functions

expand all

Run SfM Reconstruction pipeline

sfmPerform structure‑from‑motion (SfM) using single camera (Since R2026b)
connectImagePairsConnect and build view graph of visually similar images for SfM (Since R2026b)
verifyImagePairsRefine SfM view graph using geometric epipolar constraints (Since R2026b)
triangulateInitialViewsTriangulate initial views for SfM 3-D reconstruction (Since R2026b)
reconstructReconstruct 3-D scene using structure-from-motion (SfM) by incrementally processing all camera views after initialization (Since R2026b)

SfM Reconstruction Results and Visualization

posesAbsolute camera poses estimated from structure-from-motion (SfM) 3-D reconstruction (Since R2026b)
pointCloudSparse 3-D scene point cloud reconstructed using structure-from-motion (SfM) (Since R2026b)
plotVisualize 3-D point cloud and camera trajectory from structure-from-motion (SfM) reconstruction (Since R2026b)

Verify SfM Pipeline State

isConnectedDetermine if image views are connected to form view graph for structure-from-motion (SfM) (Since R2026b)
isVerifiedDetermine if image view graph connections have been geometrically verified for structure-from-motion (SfM) (Since R2026b)
isInitializedDetermine if 3-D reconstruction has been initialized for structure-from-motion (SfM) (Since R2026b)
nerfactoDense reconstruction and novel view synthesis using Nerfacto Neural Radiance Field (NeRF) model (Since R2026a)
trainNerfactoCreate and train Nerfacto Neural Radiance Field (NeRF) model (Since R2026a)
mapanythingCreate pretrained MapAnything model for 3-D scene reconstruction from images (Since R2026b)
reconstructReconstruct 3-D scene using MapAnything model (Since R2026b)
releaseGPUMemoryRelease GPU memory allocated to MapAnything model (Since R2026b)

Detect Features

detectSIFTFeaturesDetect scale invariant feature transform (SIFT) features
detectORBFeaturesDetect ORB keypoints
detectBRISKFeaturesDetect BRISK features
detectFASTFeaturesDetect corners using FAST algorithm
detectHarrisFeaturesDetect corners using Harris–Stephens algorithm
detectMinEigenFeaturesDetect corners using minimum eigenvalue algorithm
detectMSERFeaturesDetect MSER features
detectSURFFeaturesDetect SURF features
detectKAZEFeaturesDetect KAZE features

Match Features

extractFeaturesExtract interest point descriptors
matchFeaturesFind matching features
matchFeaturesInRadiusFind matching features within specified radius
vision.PointTrackerTrack points in video using Kanade-Lucas-Tomasi (KLT) algorithm

Estimate Camera Poses

estimateEssentialMatrixEstimate essential matrix from corresponding points in a pair of images
estimateFundamentalMatrixEstimate fundamental matrix from corresponding points in stereo images
estworldposeEstimate camera pose from 3-D to 2-D point correspondences (Since R2022b)
estrelposeCalculate relative rotation and translation between camera poses (Since R2022b)

Triangulate Image Points

pointTrackObject for storing matching points from multiple views
findTracksFind matched points across multiple views
triangulate3-D locations of undistorted matching points in stereo images
triangulateMultiview3-D locations of world points matched across multiple images

Optimize Camera Poses and 3-D Points

bundleAdjustmentAdjust collection of 3-D points and camera poses
bundleAdjustmentMotionAdjust collection of 3-D points and camera poses using motion-only bundle adjustment
bundleAdjustmentStructureRefine 3-D points using structure-only bundle adjustment

Store Image and 3-D Data

imageviewsetManage data for structure-from-motion, visual odometry, and visual SLAM
worldpointsetManage 3-D to 2-D point correspondences
cameraIntrinsicsObject for storing intrinsic camera parameters
rigidtform3d3-D rigid geometric transformation (Since R2022b)
affinetform3d3-D affine geometric transformation (Since R2022b)

Visualize Results

stereoAnaglyphCreate red-cyan anaglyph from stereo pair of images
pcshowPlot 3-D point cloud
pcviewerVisualize and inspect large 3-D point clouds (Since R2023a)
pcplayerVisualize streaming 3-D point cloud data
plotCameraPlot camera in 3-D coordinates
pointCloudSparse 3-D scene point cloud reconstructed using structure-from-motion (SfM) (Since R2026b)
showMatchedFeaturesDisplay corresponding feature points
compareTrajectoriesCompare estimated trajectory against ground truth (Since R2024b)
trajectoryErrorMetricsStore accuracy metrics for trajectories (Since R2024b)
rotmat2vec3dConvert 3-D rotation matrix to rotation vector (Since R2022b)
rotvec2mat3dConvert 3-D rotation vector to rotation matrix (Since R2022b)
quaternionCreate quaternion array (Since R2023b)

Topics

Basics

Incremental Structure from Motion

Featured Examples