Disparity Map Block Matching

房东的猫 提交于 2019-12-23 05:29:36

问题


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?


回答1:


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.

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:

To start:

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)

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.

Calculating the 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.

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|

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.

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.

Typical Results:

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

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



来源:https://stackoverflow.com/questions/49524329/disparity-map-block-matching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!