Sum of absolute differences

本文详细介绍了Sum of Absolute Differences (SAD)算法在数字图像处理领域的应用,包括其原理、计算过程及在目标识别、立体图像差异映射和视频压缩中的用途。通过实例展示了如何利用SAD算法识别搜索图像中与模板图像最相似的部分,并对比了与其他相似度度量指标的优劣。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In digital image processing, the sum of absolute differences (SAD) is an algorithm for measuring the similarity between image blocks. It works by taking the absolute difference between each pixel in the original block and the corresponding pixel in the block being used for comparison. These differences are summed to create a simple metric of block similarity, the L1 norm of the difference image or Manhattan distance between two image blocks.

The sum of absolute differences may be used for a variety of purposes, such as object recognition, the generation of disparity maps for stereo images, and motion estimation for video compression.

 

 

Example[edit]

This example uses the sum of absolute differences to identify which part of a search image is most similar to a template image. In this example, the template image is 3 by 3 pixels in size, while the search image is 3 by 5 pixels in size. Each pixel is represented by a single integer from 0 to 9.

Template    Search image
 2 5 5       2 7 5 8 6
 4 0 7       1 7 4 2 7
 7 5 9       8 4 6 8 5

There are exactly three unique locations within the search image where the template may fit: the left side of the image, the center of the image, and the right side of the image. To calculate the SAD values, the absolute value of the difference between each corresponding pair of pixels is used: the difference between 2 and 2 is 0, 4 and 1 is 3, 7 and 8 is 1, and so forth.

Calculating the values of the absolute differences for each pixel, for the three possible template locations, gives the following:

Left    Center   Right
0 2 0   5 0 3    3 3 1
3 7 3   3 4 5    0 2 0
1 1 3   3 1 1    1 3 4

For each of these three image patches, the 9 absolute differences are added together, giving SAD values of 20, 25, and 17, respectively. From these SAD values, it could be asserted that the right side of the search image is the most similar to the template image, because it has the lowest sum of absolute differences as compared to the other two locations.

Comparison to other metrics[edit]

Object recognition[edit]

The sum of absolute differences provides a simple way to automate the searching for objects inside an image, but may be unreliable due to the effects of contextual factors such as changes in lighting, color, viewing direction, size, or shape. The SAD may be used in conjunction with other object recognition methods, such as edge detection, to improve the reliability of results.

Video compression[edit]

SAD is an extremely fast metric due to its simplicity; it is effectively the simplest possible metric that takes into account every pixel in a block. Therefore it is very effective for a wide motion search of many different blocks. SAD is also easily parallelizable since it analyzes each pixel separately, making it easily implementable with such instructions as MMX and SSE2. For example, SSE has packed sum of absolute differences instruction (PSADBW) specifically for this purpose. Once candidate blocks are found, the final refinement of the motion estimation process is often done with other slower but more accurate metrics, which better take into account human perception. These include the sum of absolute transformed differences (SATD), the sum of squared differences (SSD), and rate-distortion optimization.

转载于:https://www.cnblogs.com/ecdgcs/p/4202803.html

链接:https://ac.nowcoder.com/acm/contest/108304/F 来源:牛客网 You’re given an integer sequence 𝑎 1 , 𝑎 2 , … , 𝑎 𝑛 a 1 ​ ,a 2 ​ ,…,a n ​ of length 𝑛 n. You can perform an operation no more than 𝑛 n times: choose an integer 𝑣 v, and update each number: 𝑎 𝑖 a i ​ to ∣ 𝑎 𝑖 − 𝑣 ∣ ∣a i ​ −v∣. 给你一个长度为 𝑛 n 的整数序列 𝑎 1 , 𝑎 2 , … , 𝑎 𝑛 a 1 ​ ,a 2 ​ ,…,a n ​ 。你可以对序列进行至多 𝑛 n 次操作:每次选择一个整数 𝑣 v ,并将序列中的每个数 𝑎 𝑖 a i ​ 更新为 ∣ 𝑎 𝑖 − 𝑣 ∣ ∣a i ​ −v∣ 。 Find the minimum possible sum of absolute differences between all distinct pairs of elements in the sequence after performing some operations. That is, minimize &sum; 1 ≤ 𝑖 < 𝑗 ≤ 𝑛 ∣ 𝑎 𝑖 − 𝑎 𝑗 ∣ 1≤i<j≤n &sum; ​ ∣a i ​ −a j ​ ∣. 在进行若干次操作后,使序列中所有不同元素对之间的绝对差之和最小。即最小化 &sum; 1 ≤ 𝑖 < 𝑗 ≤ 𝑛 ∣ 𝑎 𝑖 − 𝑎 𝑗 ∣ 1≤i<j≤n &sum; ​ ∣a i ​ −a j ​ ∣ 。 Since the answer may be large, output this minimum sum modulo 998244353 998244353. 由于答案可能很大,输出这个最小和对 998244353 998244353 取模的结果。 输入描述: The first line contains a single integer 𝑛 n ( 1 ≤ 𝑛 ≤ 2 × 1 0 5 1≤n≤2×10 5 ). 第一行包含一个整数 𝑛 n ( 1 ≤ 𝑛 ≤ 2 × 1 0 5 1≤n≤2×10 5 )。 The second line contains 𝑛 n integers 𝑎 1 , 𝑎 2 , … , 𝑎 𝑛 a 1 ​ ,a 2 ​ ,…,a n ​ ( 0 ≤ 𝑎 𝑖 ≤ 1 0 9 0≤a i ​ ≤10 9 ). 第二行包含 𝑛 n 个整数 𝑎 1 , 𝑎 2 , … , 𝑎 𝑛 a 1 ​ ,a 2 ​ ,…,a n ​ ( 0 ≤ 𝑎 𝑖 ≤ 1 0 9 0≤a i ​ ≤10 9 )。 输出描述: Output a single integer, the minimum possible sum &sum; 1 ≤ 𝑖 < 𝑗 ≤ 𝑛 ∣ 𝑎 𝑖 − 𝑎 𝑗 ∣ 1≤i<j≤n &sum; ​ ∣a i ​ −a j ​ ∣ modulo 998244353 998244353. 输出一个整数,该整数为 &sum; 1 ≤ 𝑖 < 𝑗 ≤ 𝑛 ∣ 𝑎 𝑖 − 𝑎 𝑗 ∣ 1≤i<j≤n &sum; ​ ∣a i ​ −a j ​ ∣ 取 998244353 998244353 模的最小可能和。 示例1 输入 复制 3 5 10 15 输出 复制 2 示例2 输入 复制 5 0 0 0 0 1 输出 复制 4c++解决
最新发布
08-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值