ArticleslgStudy

mathematics

Semi-global matching

Semi-global matching is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Semi-global matching rather than just read about it. In short: Semi-global matching (SGM) is a computer vision algorithm for the estimation of a dense disparity map from a rectified stereo image pair, introduced in 2005 by Heiko Hirschmüller while working at the German Aerospace Center. Given its predictable run time, its favourable trade-off between quality of the results and computing time, and its suitability for fast parallel implementation in ASIC or FPGA, it has encounter…

Semi-global matching — main illustration
Semi-global matching — illustration

Key takeaways

  • Semi-global matching belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Semi-global matching to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Semi-global matching from memory before moving on to harder problems.

Reference excerpt

Semi-global matching (SGM) is a computer vision algorithm for the estimation of a dense disparity map from a rectified stereo image pair, introduced in 2005 by Heiko Hirschmüller while working at the German Aerospace Center. Given its predictable run time, its favourable trade-off between quality of the results and computing time, and its suitability for fast parallel implementation in ASIC or FPGA, it has encountered wide adoption in real-time stereo vision applications such as robotics and advanced driver assistance systems.

Problem Pixelwise stereo matching allows to perform real-time calculation of disparity maps by measuring the similarity of each pixel in one stereo image to each pixel within a subset in the other stereo image. Given a rectified stereo image pair, for a pixel with coordinates (x,y) the set of pixels in the other image is usually selected as {(x̂,y)|x̂≥x,x̂≤x+D}, where D is a maximum allowed disparity shift. A simple search for the best matching pixel produces many spurious matches, and this problem can be mitigated with the addition of a regularisation term that penalises jumps in disparity between adjacent pixels, with a cost function in the form

E(𝒅)=∑pD(p,dp)+∑p,q∈𝒩R(p,dp,q,dq) where D(p,dp) is the pixel-wise dissimilarity cost at pixel p with disparity dp, and R(p,dp,q,dq) is the regularisation cost between pixels p and q with disparities dp and dq respectively, for all pairs of neighbouring pixels 𝒩. Such constraint can be efficiently enforced on a per-scanline basis by using dynamic programming (e.g. the Viterbi algorithm), but such limitation can still introduce streaking artefacts in the depth map, because little or no regularisation is performed across scanlines. A possible solution is to perform global optimisation in 2D, which is however an NP-complete problem in the general case. For some families of cost functions (e.g. submodular functions) a solution with strong optimality properties can be found in polynomial time using graph cut optimization, however such global methods are generally too expensive for real-time processing.

Algorithm

The idea behind SGM is to perform line optimisation along multiple directions and computing an aggregated cost S(p,d) by summing the costs to reach pixel p with disparity d from each direction. The number of directions affects the run time of the algorithm, and while 16 directions usually ensure good quality, a lower number can be used to achieve faster execution. A typical 8-direction implementation of the algorithm can compute the cost in two passes, a forward pass accumulating the cost from the left, top-left, top, and top-right, and a backward pass accumulating the cost from right, bottom-right, bottom, and bottom-left. A single-pass algorithm can be implemented with only five directions. The cost is composed by a matching term D(p,d) and a binary regularisation term R(dp,dq). The former can be in principle any local image dissimilarity measure, and commonly used functions are absolute or squared intensity difference (usually summed over a window around the pixel, and after applying a high-pass filter to the images to gain some illumination invariance), Birchfield–Tomasi dissimilarity, Hamming distance of the census transform, Pearson correlation (normalized cross-correlation). Even mutual information can be approximated as a sum over the pixels, and thus used as a local similarity metric. The regularisation term has the form

R(dp,dq)={0dp=dqP1|dp−dq|=1P2|dp−dq|>1 where P1 and P2 are two constant parameters, with P1<P2. The three-way comparison allows to assign a smaller penalty for unitary changes in disparity, thus allowing smooth transitions corresponding e.g. to slanted surfaces, and penalising larger jumps while preserving discontinuities due to the constant penalty term. To further preserve discontinuities, the gradient of the intensity can be used to adapt the penalty term, because discontinuities in depth usually correspond to a discontinuity in image intensity I, by setting

P2=max⁡{P1,P̂2|I(p)−I(q)|} for each pair of pixels p and q. The accumulated cost S(p,d)=∑rLr(p,d) is the sum of all costs Lr(p,d) to reach pixel p with disparity d along direction r. Each term can be expressed recursively as

Lr(p,d)=D(p,d)+min⁡{Lr(p−r,d),Lr(p−r,d−1)+P1,Lr(p−r,d+1)+P1,miniLr(p−r,i)+P2}−minkLr(p−r,k) where the minimum cost at the previous pixel minkLr(p−r,k) is subtracted for numerical stability, since it is constant for all values of disparity at the current pixel and therefore it does not affect the optimisation. The value of disparity at each pixel is given by d∗(p)=argmindS(p,d), and sub-pixel accuracy can be achieved by fitting a curve in d∗(p) and its neighbouring costs and taking the minimum along the curve. Since the two images in the stereo pair are not treated symmetrically in the calculations, a consistency check can be performed by computing the disparity a second time in the opposite direction, swapping the role of the left and right image, and invalidating the result for the pixels where the result differs between the two calculations. Further post-processing techniques for the refinement of the disparity image include morphological filtering to remove outliers, intensity consistency checks to refine textureless regions, and interpolation to fill in pixels invalidated by consistency checks. The cost volume C(p,d) for all values of p=(x,y) and d can be precomputed and in an implementation of the full algorithm, using D possible disparity shifts and R directions, each pixel is subsequently visited R times, therefore the computational complexity of the algorithm for an image of size W×H is O(WHD).

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Semi-global matching

Start with the simplest possible case. Write down what Semi-global matching claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Semi-global matching before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Semi-global matching ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Semi-global matching

In research
Semi-global matching appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Semi-global matching in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Semi-global matching is common in secondary-school and first-year university syllabi. It links to neighbouring topics Geometry in computer vision, so understanding it makes those chapters shorter.
In everyday life
Look for Semi-global matching outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Semi-global matching” →

How to study Semi-global matching in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Semi-global matching means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Semi-global matching out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Semi-global matching in simple terms?

Semi-global matching (SGM) is a computer vision algorithm for the estimation of a dense disparity map from a rectified stereo image pair, introduced in 2005 by Heiko Hirschmüller while working at the German Aerospace Center. Given its predictable run time, its favourable trade-off between quality o…

Why does Semi-global matching matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Semi-global matching?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Semi-global matching.

Tags

  • Geometry in computer vision

Keep exploring