Skip to content

ChristianOrr/semi-global-matching-numpy

Repository files navigation

Semi-Global Matching Numpy

Introduction

This is a reimplementation of the Semi-Global Matching algorithm using numpy. Both a python script and jupyter notebook is provided implementing SGM. The notebook provides visualizations and explanations for each step in the process.

SGM Brief Description

SGM is a popular classic depth estimation algorithm, known for having good accuracy and speed. Newer stereo depth estimation models like madnet-deep-stereo-with-keras have much higher accuracy, but need to be trained first and require more compute during inference. This makes SGM and excellent option for resource constrained situations.

History of Semi-Global Matching

The Semi-Global Matching algorithm was first introduced by Heiko Hirschmuller in his 2005 paper "Stereo Processing by Semi-Global Matching and Mutual Information". This work built upon earlier stereo matching techniques and introduced a novel approach to reduce the computational complexity while maintaining good accuracy.

The SGM algorithm is an extension of global matching methods that use dynamic programming. It differs from traditional global methods by considering paths in multiple directions (typically 8 directions) rather than just horizontal or vertical paths, which helps to better handle occlusions and textureless regions.

Key contributions of the SGM approach include:

  • Efficient cost aggregation using multi-directional path searching
  • Reduced computational complexity compared to full global methods
  • Improved handling of discontinuities in disparity maps
  • Good balance between accuracy and speed

The algorithm has since become a standard baseline for stereo matching evaluation and is widely used in both academic research and practical applications, particularly in robotics and computer vision systems where real-time performance is crucial.

Requirements

All you need to run the SGM algorithm are a pair of rectified stereo images. Stereo pair examples from the Middlebury dataset are provided for you (cones, figures and teddy). If you would like to review the algorithms accuracy you need groundtruth disparities.

If you would like to use your own stereo images and your stereo camera doesn't provide rectified stereo pairs, then you can calibrate your stereo camera using the methods shown in this repo: stereo-camera-calibration.

If you would like to try more advanced deep learning stereo depth estimation techinques check out madnet-deep-stereo-with-keras.

The python packages needed are shown in the requirements.txt.

SGM Transformation Process

The SGM algorithm follows the following process to achieve the depth estimation prediction. Head over to the sgm_numpy_notebook if you would like to see how its done in code.

  1. The SGM process starts with a pair of rectified stereo images. left_right_colour
  2. The stereo pair is converted to grayscale. left_right_grey
  3. A Gaussian blur filter is applied to smooth the images. left_right_blur
  4. The census transform is then applied to the images. left_right_census
  5. The Hamming distance is applied to the census values to calculate the cost volume. left_right_cost_volume
  6. A cost aggregation technique is applied to remove the noise from the cost volume. left_right_cost_agg
  7. A median blur filter is applied to remove the streaking. left_right_disp
  8. Optional: The disparity can then be converted to colour to see the depth better. Red indicates closer and blue further away. left_right_depth_map

References

About

Reimplementation of Semi-Global Matching depth estimation technique with Numpy.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors