Block Matching

Estimate motion between images or video frames

  • Library:
  • Computer Vision Toolbox / Analysis & Enhancement

Description

The Block Matching block estimates motion between two images or two video frames by comparing blocks of pixels. The block matches the block of pixels between frames by moving the block of pixels over a search region.

Ports

Input

expand all

Image or video frame, specified as a scalar, vector, or matrix. If the Estimate motion between parameter is set to Two images, the name of this port changes to I1.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Image or video frame, specified as a scalar, vector, or matrix.

Dependencies

To enable this port, set the Estimate motion between parameter to Two images.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Output

expand all

Velocity magnitudes, returned as a scalar, vector, or matrix.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Velocity components in complex form, returned as a scalar, vector, or matrix.

Dependencies

To expose this port, set the Velocity output parameter to Horizontal and vertical components in complex form.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | fixed point

Parameters

expand all

Main Tab

Specify whether to estimate the motion between two images or two video frames. Select Two images to estimate the motion between two images. Select Current frame and N-th frame back to estimate the motion between two video frames that are N frames apart.

Dependencies

Set this parameter to Current frame and N-th frame back to expose the N parameter.

Specify a scalar value that represents the number of frames between the reference frame and the current frame.

Dependencies

To enable this parameter, set the Estimate motion between parameter to Current frame and N-th frame back.

Specify how the block locates the block of pixels in the current frame and the next frame that best matches the block of pixels.

  • Exhaustive — The block selects the location of the block of pixels in the next frame by moving the block over the search region one pixel at a time. This process is computationally expensive.

  • Three-step — The block searches for the block of pixels in the next frame that best matches the block of pixels in the current frame by using a steadily decreasing step size. The block begins with a step size approximately equal to half the maximum search range. In each step, the block compares the central point of the search region to eight search points located on the boundaries of the region and moves the central point to the search point whose values is the closest to that of the central point. The block then reduces the step size by half, and begins the process again. This option is less computationally expensive, though it might not find the optimal solution.

Specify how the block measures the similarity of the block of pixels in the current frame to the block of pixels in the next frame.

If you select Mean square error (MSE), the block estimates the displacement of the center pixel of the block as the (d1,d2) values that minimize this MSE equation:

MSE(d1,d2)=1N1×N2(n1,n2),B[s(n1,n2,k)s(n1+d1,n2+d2,k+1)]2

In the previous equation, B is an N1×N2 block of pixels, and s(x,y,k) denotes a pixel location at (x,y) in frame k.

If you select Mean absolute difference (MAD), the Block Matching block estimates the displacement of the center pixel of the block as the (d1,d2) values that minimize this MAD equation:

MAD(d1,d2)=1N1×N2(n1,n2),B|s(n1,n2,k)s(n1+d1,n2+d2,k+1)|

Specify the size of the block of pixels.

Specify the overlap (in pixels) of two subdivisions of the input image.

Specify the maximum number of pixels any center pixel in a block of pixels might move from image to image or frame to frame. The block uses this value to determine the size of the search region.

Specify the output. If you select Magnitude-squared, the block outputs an optical flow matrix where each element is in the form u2+v2. If you select Horizontal and vertical components in complex form, the block outputs an optical flow matrix where each element is in the form u+jv. The real part of each value is the horizontal velocity component and the imaginary part of each value is the vertical velocity component.

Data Types Tab

For details on the fixed-point block parameters, see Specify Fixed-Point Attributes for Blocks.

Block Characteristics

Data Types

double | fixed point | integer | single

Multidimensional Signals

no

Variable-Size Signals

no

Algorithms

expand all

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a