ArticleslgStudy

computer science

Block-matching algorithm

Block-matching algorithm is a computer science 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 Block-matching algorithm rather than just read about it. In short: A Block Matching Algorithm is a way of locating matching macroblocks in a sequence of digital video frames for the purposes of motion estimation. The underlying supposition behind motion estimation is that the patterns corresponding to objects and background in a frame of video sequence move within the frame to form corresponding objects on the subsequent frame.

Block-matching algorithm — main illustration
Block-matching algorithm — illustration

Key takeaways

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

Reference excerpt

A Block Matching Algorithm is a way of locating matching macroblocks in a sequence of digital video frames for the purposes of motion estimation. The underlying supposition behind motion estimation is that the patterns corresponding to objects and background in a frame of video sequence move within the frame to form corresponding objects on the subsequent frame. This can be used to discover temporal redundancy in the video sequence, increasing the effectiveness of inter-frame video compression by defining the contents of a macroblock by reference to the contents of a known macroblock which is minimally different.

A block matching algorithm involves dividing the current frame of a video into macroblocks and comparing each of the macroblocks with a corresponding block and its adjacent neighbors in a nearby frame of the video (sometimes just the previous one). A vector is created that models the movement of a macroblock from one location to another. This movement, calculated for all the macroblocks comprising a frame, constitutes the motion estimated in a frame. The search area for a good macroblock match is decided by the 'search parameter', p, where p is the number of pixels on all four sides of the corresponding macro-block in the previous frame. The search parameter is a measure of motion. The larger the value of p, larger is the potential motion and the possibility for finding a good match. A full search of all potential blocks however is a computationally expensive task. Typical inputs are a macroblock of size 16 pixels and a search area of p = 7 pixels. Block-matching and 3D filtering makes use of this approach to solve various image restoration inverse problems such as noise reduction and deblurring in both still images and digital video.

Motivation Motion estimation is the process of determining motion vectors that describe the transformation from one 2D image to another; usually from adjacent frames in a video sequence. The motion vectors may relate to the whole image (global motion estimation) or specific parts, such as rectangular blocks, arbitrary shaped patches or even per pixel. The motion vectors may be represented by a translational model or many other models that can approximate the motion of a real video camera, such as rotation and translation in all three dimensions and zoom. Applying the motion vectors to an image to predict the transformation to another image, on account of moving camera or object in the image is called motion compensation. The combination of motion estimation and motion compensation is a key part of video compression as used by MPEG 1, 2 and 4 as well as many other video codecs. Motion estimation based video compression helps in saving bits by sending encoded difference images which have inherently less entropy as opposed to sending a fully coded frame. However, the most computationally expensive and resource extensive operation in the entire compression process is motion estimation. Hence, fast and computationally inexpensive algorithms for motion estimation is a need for video compression.

Evaluation Metrics A metric for matching a macroblock with another block is based on a cost function. The most popular in terms of computational expense is: Mean difference or Mean Absolute Difference (MAD) = 1N2∑i=0n−1∑j=0n−1|Cij−Rij| Mean Squared Error (MSE) = 1N2∑i=0n−1∑j=0n−1(Cij−Rij)2 where N is the size of the macro-block, and Cij and Rij are the pixels being compared in current macroblock and reference macroblock, respectively. The motion compensated image that is created using the motion vectors and macroblocks from the reference frame is characterized by Peak signal-to-noise ratio (PSNR), PSNR=10log10(peak to peak value of original data)2MSE

Algorithms

Block Matching algorithms have been researched since mid-1980s. Many algorithms have been developed, but only some of the most basic or commonly used have been described below.

Exhaustive Search This algorithm calculates the cost function at each possible location in the search window. This leads to the best possible match of the macro-block in the reference frame with a block in another frame. The resulting motion compensated image has highest peak signal-to-noise ratio as compared to any other block matching algorithm. However this is the most computationally extensive block matching algorithm among all. A larger search window requires greater number of computations.

Optimized Hierarchical Block Matching (OHBM) The optimized hierarchical block matching (OHBM) algorithm speeds up the exhaustive search based on the optimized image pyramids.

Three Step Search It is one of the earliest fast block matching algorithms. It runs as follows:

Start with search location at center Set step size S = 4 and search parameter p = 7 Search 8 locations +/- S pixels around location (0,0) and the location (0,0) Pick among the 9 locations searched, the one with minimum cost function Set the new search origin to the above picked location Set the new step size as S = S/2 Repeat the search procedure until S = 1 The resulting location for S=1 is the one with minimum cost function and the macro block at this location is the best match. There is a reduction in computation by a factor of 9 in this algorithm. For p=7, while ES evaluates cost for 225 macro-blocks, TSS evaluates only for 25 macro blocks.

Two Dimensional Logarithmic Search TDLS is closely related to TSS however it is more accurate for estimating motion vectors for a large search window size. The algorithm can be described as follows,

Start with search location at the center Select an initial step size say, S = 8 Search for 4 locations at a distance of S from center on the X and Y axes Find the location of point with least cost function If a point other than center is the best matching point, Select this point as the new center If the best matching point is at the center, set S = S/2 Repeat steps 2 to 3 If S = 1, all 8 locations around the center at a distance S are searched Set the motion vector as the point with least cost function

New Three Step Search TSS uses a uniformly allocated checking pattern and is prone to miss small motions. NTSS is an improvement over TSS as it provides a center biased search scheme and has provisions to stop halfway to reduce the computational cost. It was one of the first widely accepted fast algorithms and frequently used for implementing earlier standards like MPEG 1 and H.261. The algorithm runs as follows:

… excerpt ends here. Continue reading the full article.

Illustrations

Block-matching algorithm illustration

Worked examples

Example 1 — a first encounter with Block-matching algorithm

Start with the simplest possible case. Write down what Block-matching algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, 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 Block-matching algorithm 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 Block-matching algorithm 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 Block-matching algorithm

In research
Block-matching algorithm appears in computer science 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 Block-matching algorithm 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
Block-matching algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Film and video technology, Video compression, so understanding it makes those chapters shorter.
In everyday life
Look for Block-matching algorithm 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 “Block-matching algorithm” →

How to study Block-matching algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Block-matching algorithm 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 Block-matching algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Block-matching algorithm in simple terms?

A Block Matching Algorithm is a way of locating matching macroblocks in a sequence of digital video frames for the purposes of motion estimation. The underlying supposition behind motion estimation is that the patterns corresponding to objects and background in a frame of video sequence move within…

Why does Block-matching algorithm matter?

Because it connects several computer science 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 Block-matching algorithm?

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 Block-matching algorithm.

Tags

  • Film and video technology
  • Video compression

Keep exploring