视差图块匹配 [英] Disparity Map Block Matching

查看:121
本文介绍了视差图块匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写使用块匹配的视差匹配算法,但是我不确定如何在辅助图像中找到相应的像素值.

I am writing a disparity matching algorithm using block matching, but I am not sure how to find the corresponding pixel values in the secondary image.

给定一个方形的窗口,有什么技术可以找到相应的像素?我需要使用特征匹配算法还是有一种更简单的方法,例如将像素值求和并确定它们是否在某个阈值之内,或者将像素值转换为大于或小于该值的二进制字符串?中心像素?

Given a square window of some size, what techniques exist to find the corresponding pixels? Do I need to use feature matching algorithms or is there a simpler method, such as summing the pixel values and determining whether they are within some threshold, or perhaps converting the pixel values to binary strings where the values are either greater than or less than the center pixel?

推荐答案

我将假设您正在谈论立体声差异,在这种情况下,您可能希望使用简单的克里斯·麦考密克阅读本教程.在这里了解更多之前.

I'm going to assume you're talking about Stereo Disparity, in which case you will likely want to use a simple Sum of Absolute Differences (read that wiki article before you continue here). You should also read this tutorial by Chris McCormick before you read more here.

旁注: SAD不是唯一的方法,但它确实很常见,应该可以解决您的问题.

side note: SAD is not the only method, but it's really common and should solve your problem.

您已经有了正确的想法.制作窗口,移动窗口,求和像素,求最小值.因此,我会给您我认为可能会有所帮助的内容:

You already have the right idea. Make windows, move windows, sum pixels, find minimums. So I'll give you what I think might help:

开始:

如果您有彩色图像,首先需要将它们转换为黑白图像.在python中,您可以按像素使用一个简单的函数,其中x是包含RGB的像素.

If you have color images, first you will want to convert them to black and white. In python you might use a simple function like this per pixel, where x is a pixel that contains RGB.

def rgb_to_bw(x):
    return int(x[0]*0.299 + x[1]*0.587 + x[2]*0.114)

您将希望它是黑白的,以使SAD易于计算机操作.如果您想知道为什么不从中丢失大量信息,您可能会对学习拜耳过滤器是.拜耳滤镜(通常为RGGB)也说明了像素的红色,绿色和蓝色部分的乘法比.

You will want this to be black and white to make the SAD easier to computer. If you're wondering why you don't loose significant information from this, you might be interested in learning what a Bayer Filter is. The Bayer Filter, which is typically RGGB, also explains the multiplication ratios of the Red, Green, and Blue portions of the pixel.

计算SAD:

您已经提到您有一个大小合适的窗口,这正是您想要做的.假设此窗口的大小为n x n.您还将在左侧图像WL中有一些窗口,而在右侧图像WR中也有一些窗口.这样做的目的是找到SAD最小的一对.

You already mentioned that you have a window of some size, which is exactly what you want to do. Let's say this window is n x n in size. You would also have some window in your left image WL and some window in your right image WR. The idea is to find the pair that has the smallest SAD.

因此,对于窗口(x,y)中某个位置的每个左窗口像素pl,您将获得右窗口像素pr的差的绝对值,该绝对值也位于(x,y).您还需要一些运行值,这是这些绝对差异的总和.用sudo代码:

So, for each left window pixel pl at some location in the window (x,y) you would the absolute value of difference of the right window pixel pr also located at (x,y). you would also want some running value, which is the sum of these absolute differences. In sudo code:

SAD = 0
from x = 0 to n:
   from y = 0 to n:
       SAD = SAD + absolute_value|pl - pr|

在为这对窗口WLWR计算SAD之后,您将要滑动" WR到新位置并计算另一个SAD.您想找到SAD最小的WLWR对-您可以将其视为最相似的窗口.换句话说,具有最小SAD的WLWR是匹配的".当您具有当前WL的最小SAD时,将滑动" WL并重复.

After you calculate the SAD for this pair of windows, WL and WR you will want to "slide" WR to a new location and calculate another SAD. You want to find the pair of WL and WR with the smallest SAD - which you can think of as being the most similar windows. In other words, the WL and WR with the smallest SAD are "matched". When you have the minimum SAD for the current WL you will "slide" WL and repeat.

视差由匹配的WLWR之间的距离计算.为了可视化,您可以将该距离缩放到0-255之间,并将其输出到另一张图像.我在下面发布了3张图片,向您展示了这一点.

Disparity is calculated by the distance between the matched WL and WR. For visualization, you can scale this distance to be between 0-255 and output that to another image. I posted 3 images below to show you this.

典型结果:

左图: 正确的图像: 计算的视差(从左图开始):

Left Image: Right Image: Calculated Disparity (from the left image):

您可以在此处获取测试图像: http://vision.middlebury.edu/stereo/data/scenes2003/

you can get test images here: http://vision.middlebury.edu/stereo/data/scenes2003/

这篇关于视差图块匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆