PIXELBANKv9.1.0
Menu

SAD Block Matching Cost

Compute the Sum of Absolute Differences (SAD) between two image blocks.

SAD is a simple and efficient matching cost used in stereo correspondence:

SAD=∑i,j∣L(i,j)−R(i,j)∣SAD = \sum_{i,j} |L(i,j) - R(i,j)|

where LL and RR are corresponding blocks from the left and right images.

Properties of SAD:

  • Fast to compute (no multiplications)
  • Robust to small intensity differences
  • Lower values indicate better matches
  • Often used with block sizes like 5×5, 7×7, or 9×9

SAD is the simplest block matching metric. SSD (sum of squared differences) and NCC (normalized cross-correlation) are more robust alternatives.

Example:

Input:
sad([[1,2],[3,4]], [[1,2],[3,4]])
Output:
0
Reasoning:
  • Computing SAD for identical blocks: |1-1| + |2-2| + |3-3| + |4-4| = 0 + 0 + 0 + 0 = 0

  • Identical blocks have zero SAD (perfect match).

Constraints:

  • block_left: 2D array representing a patch from the left image
  • block_right: 2D array of same size from the right image
  • Return the SAD value (integer)
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.