matlab中两个相似图像的视差计算 [英] Disparity calculation of two similar images in matlab

查看:1585
本文介绍了matlab中两个相似图像的视差计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个图像(两个是完全相同的图像),我试图使用平方距离之和计算它们之间的差异,并重建3D空间中的视差。
我需要在计算视差之前纠正图像吗?



以下是我迄今为止为视差图计算所做的步骤整流和没有整流,但两个都返回全零视差矩阵)。

 对于左图像X中的每个像素,
获取右图像中同一行中的像素。
将右侧图像中的行分为Windows。
对于每个窗口,
使用X
计算该窗口中每个像素的差异$
选择给出最小SSD的窗口中的像素X
查找最小差异的像素所有窗口作为与X
最匹配的窗口

我是否正确运行?



如何在matlab中可视化散点图的视差的3D重建?

解决方案

保证在同一行中找到匹配(对于水平分离的相机)。如果您对图像的纠正有疑问,可以尝试通过在水平分隔的图像之间绘制水平线来比较行。如果线条打到相同的功能,你是罚款,请参阅下面的图片,不会纠正的图片。它们失真的事实意味着存在透镜失真校正以及尝试(但实际上没有正确地执行)校正。



现在,让我们来看看相同图片的含义。你的意思是从不同的角度拍摄的同一个对象的图像?注意,如果图像在字面上相同(相同的观点),则视差将为零,如在另一个答案中所指出的。视差(对于水平分离的相机)的定义是匹配特征之间的shift(在同一行中)的值。视差与深度(如果摄像机的光轴平行)相关,如视差d = f * B / z,其中z-深度,B-基线或摄像机之间的间隔和f是焦距。您可以将上面的公式转换为视差/ B = f / z,这基本上说,与相机分离相关的视差是焦距与距离有关。换句话说,水平和距离度量的比率是相等的。





如果您的图像是水平移动的相机拍摄,差异(在简单的相关算法中)循环:

 循环遍历image1 y 
循环遍历image1 x
循环遍及差异d
在相关窗口上循环y
在相关窗口上循环x

视差或D_best在所有可能的d值之间的image1和image2之间的最佳匹配窗口。最后,散点图用于3D点云,而视差可以相当可视化为热色图。如果需要可视化3D重建或简单地说3D点云计算X,Y,Z如下:
Z = f B / D,X = u z / f,Y = v * Z / f,其中u和v与wxh图像的列和行相关,如
u = col-w / 2和v = h / 2-行,即u,v形成以图像为中心的坐标系。


I have two images(both are exactly same images) and I am trying to calculate the disparity between them using sum of squared distances and reconstruct disparity in 3D space. Do I need to rectify the image before calculating disparity?

The following are the steps that I have done so far for disparity map computation(I have tried with rectification and without rectification but both are returning all zeroes disparity matrix).

For each pixel in the left image X, 
   Take the pixels in the same row in the right image.
   Separate the row in right image to windows.
   For each window,
     Calculate the disparity for each pixel in that window with X
     Select the pixel in the window which gives minimum SSD with X
   Find the pixel with minimum disparity among all windows as the best match to X

Am I doing it correctly?

How can I visualise the 3D reconstruction of the disparity as scatter plot in matlab?

解决方案

Rectification guarantees that matches are to be found in the same row (for horizontally separated cameras). If you have doubts about rectification of your images you can try to compare rows by drawing horizontal lines between horizontally separated images. If the lines hit the same features you are fine, see the picture below where images are NOT rectified. The fact that they are distorted means there was a lens distortion correction as well as attempted (but not actually performed correctly) rectification.

Now, let’s see what you meant by the same images. Did you mean the images of the same object that were taken from different viewpoints? Note that if the images are literally the same (the same viewpoints) the disparity will be zero as was noted in another answer. The definition of disparity (for horizontally separated cameras) is a value of shift (in the same row) between matching features. The disparity is related to depth (if optical axes of cameras are parallel) as disparity d=f*B/z, where z - depth, B - baseline or separation between cameras and f is a focal length. You can transform the formula above into disparity/B=f/z which basically says that disparity related to camera separation as focal length is related to distance. In other words, the ratios of horizontal and distance measures are equal.

If your images are taken with the cameras shifted horizontally the disparity (in a simple correlation algorithm) is typically calculated in 5-embedded loops:

loop over image1 y  
   loop over image1 x  
      loop over disparity d  
         loop over correlation window y  
            loop over correlation window x  

Disparity, or D_best, gives you the best matching window between image1 and image2 across all possible values of d. Finally, scatterplots are for 3D point clouds while disparity can be rather visualized as a heat color map. If you need to visualize 3D reconstruction or simply saying a 3D point cloud calculate X, Y, Z as: Z=fB/D, X=uZ/f, Y=v*Z/f, where u and v are related to column and row of wxh image as u=col-w/2 and v=h/2-row, that is u, v form an image centered coordinate system.

这篇关于matlab中两个相似图像的视差计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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