Main Content

disparity

(不建议)立体声图像之间的差异图

disparityis not recommended. UsedisparityBM或者差异反而。For more information, see兼容性考虑

Description

example

差异图= disparity(I1,I2)returns the disparity map,差异图,对于一对立体图像,I1I2

差异图= disparity(I1,I2,姓名,Value)provides additional control for the disparity algorithm by using one or more姓名,Valuepair arguments.

Examples

collapse all

Load the images and convert them to grayscale.

I1 = imread('scene_left.png');i2 = imread('scene_right.png');

显示立体声盲。使用红色圆形立体声眼镜在3-D中查看图像。

图Imshow(立体声词(I1,I2));标题(“立体声图像的红色圆形复合视图”);

Figure contains an axes object. The axes object with title Red-cyan composite view of the stereo images contains an object of type image.

计算差异图。

DisparityRange = [-6 10];disparitymap =差异(rgb2gray(i1),rgb2gray(i2),'BlockSize',...15,,'DisparityRange',disparityRange);

Display the disparity map. For better visualization, use the disparity range as the display range for imshow.

figure imshow(disparityMap,disparityRange); title(“差异图”);Colormap(GCA,JET)配色杆

Figure contains an axes object. The axes object with title Disparity Map contains an object of type image.

Input Arguments

collapse all

Input image referenced asI1corresponding to camera 1, specified in 2-D grayscale. The stereo images,I1I2,必须纠正,以使相应的点位于同一行上。您可以使用rectifyStereoImagesfunction.

您可以通过设置类的类别来提高功能的速度I1I2UINT8, and the number of columns to be divisible by 4. Input imagesI1I2必须是真实的,有限的,也必须是非sparse。他们必须是同一班。

Data Types:UINT8|uint16|int16|单身的|double

Input image referenced asI2对应于2-D灰度指定的相机2。必须纠正输入图像,以使相应的点位于同一行上。您可以通过设置类的类别来提高功能的速度I1I2UINT8, and the number of columns to be divisible by 4. Input imagesI1I2必须是真实的,有限的,也必须是非sparse。他们必须是同一班。

Data Types:UINT8|uint16|int16|单身的|double

姓名-Value Arguments

将可选的参数对name1 = value1,...,namen = valuen, where姓名is the argument name and价值is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:'方法',“阻止匹配”,指定'方法'property be set to“阻止匹配”

差异估计算法,指定为逗号分隔对,由'Method' and either“阻止匹配”或者'SemiGlobal'。The disparity function implements the basic Block Matching[1]和半全球块匹配[3]算法。在里面“阻止匹配”方法,该函数通过比较图像中每个像素块的绝对差异(SAD)的总和来计算差异。在里面'SemiGlobal'matching method, the function additionally forces similar disparity on neighboring blocks. This additional constraint results in a more complete disparity estimate than in the“阻止匹配”method.

The algorithms perform these steps:

  1. Compute a measure of contrast of the image by using the Sobel filter.

  2. 计算每个像素的差异I1

  3. Mark elements of the disparity map,差异图,不是可靠地计算出来的。功能使用 -realmax('single') to mark these elements.

差异范围,指定为逗号分隔对,由'DisparityRange' and a two-element vector. The two-element vector must be in the format [MinDisparity,maxdisparity]。Both elements must be an integer and can be negative.MinDisparitymaxdisparitymust be in the range [-image width,image width]。和...之间的不同maxdisparityMinDisparitymust be divisible by16DisparityRange必须是真实的,有限的,也必须是非sparse。如果相机曾经采用I1was to the right of the camera used to takeI2, thenMinDisparity必须是负面的。

差异范围取决于两个摄像机与摄像机与感兴趣对象之间的距离之间的距离。增加DisparityRange当摄像机远part or the objects are close to the cameras. To determine a reasonable disparity for your configuration, display the stereo anaglyph of the input images in theImage Viewerapp and use the Distance tool to measure distances between pairs of corresponding points. Modify themaxdisparity对应于测量。

方块大小, specified as the comma-separated pair consisting of '阻止' and an odd integer in the range [5,255]. This value sets the width for the square block size. The function uses the square block of pixels for comparisons betweenI1I2阻止必须是真实的,有限的,也必须是非sparse。

对比阈值范围,指定为逗号分隔对,由'ContrastThreshold' and a scalar value in the range (0,1]. The contrast threshold defines an acceptable range of contrast values. Increasing this parameter results in fewer pixels being marked as unreliable.ContrastThreshold必须是真实的,有限的,也必须是非sparse。

Minimum value of uniqueness, specified as the comma-separated pair consisting of '唯一思想' and a nonnegative integer. Increasing this parameter results in the function marking more pixels unreliable. When the uniqueness value for a pixel is low, the disparity computed for it is less reliable. Setting the threshold to0disables uniqueness thresholding.唯一思想必须是真实的,有限的,也必须是非sparse。

该函数将唯一性定义为最佳差异估计的比率和较小的最佳差异估计。例如:

K成为最好的估计差异,让V成为相应的SAD(绝对差)值。
ConsiderVas the smallest SAD value over the whole disparity range, andvas the smallest SAD value over the whole disparity range, excludingK,K-1,和K+1.
Ifv<V*((1+0.01*唯一思想),然后该函数将像素的差异标记为不可靠。

Maximum distance for left-to-right image checking between two points, specified as the comma-separated pair consisting of 'DistanceThreshold' and a nonnegative integer. Increasing this parameter results in fewer pixels being marked as unreliable. Conversely, when you decrease the value of the distance threshold, you increase the reliability of the disparity map. You can set this parameter to an empty matrix[]至disable it.DistanceThreshold必须是真实的,有限的,也必须是非sparse。

距离阈值指定一个点之间的最大距离I1I2。The function finds the distance and marks the pixel in the following way:

p1be a point in imageI1
Step 1: The function searches for pointp1图像中最好的比赛I2(left-to-right check) and finds pointp2
Step 2: The function searches forp2图像中最好的比赛I1(左转检查)并找到点p3
If the search returns a distance betweenp1p3greater thanDistanceThreshold,该功能标志着该点的差异p1as unreliable.

最小纹理阈值,指定为逗号分隔对,由'质地Threshold' and a scalar value in the range [0, 1). The texture threshold defines the minimum texture value for a pixel to be reliable. The lower the texture for a block of pixels, the less reliable the computed disparity is for the pixels. Increasing this parameter results in more pixels being marked as unreliable. You can set this parameter to0至disable it. This parameter applies only when you setMethod“阻止匹配”

The texture of a pixel is defined as the sum of the saturated contrast computed over the阻止-by-阻止周围像素的窗口。函数认为届e disparity computed for the pixel unreliable and marks it, when the texture falls below the value defined by:

质地<X*质地Threshold*阻止2

X表示输入图像类别支持的最大值,万博1manbetxI1I2

质地Threshold必须是真实的,有限的,也必须是非sparse。

输出参数

collapse all

一对立体声图像的差异图,返回为M-by-N2-D灰度图像。The function returns the disparity map with the same size as the input images,I1I2。输出的每个元素指定图像引用中相应像素的差异为I1。The returned disparity values are rounded to 1 16 Th Pixel。

该函数分为三个步骤计算差异图:

  1. Compute a measure of contrast of the image by using the Sobel filter.

  2. 通过使用块匹配和绝对差异的总和(SAD)来计算每个像素的差异。

  3. 可选地,标记包含不可靠的视差值的像素。该函数将像素设置为 - 由 - 返回的值realmax('单身的').

Tips

如果您的结果差异图看起来很吵,请尝试修改DisparityRange。差异范围取决于两个摄像机与摄像机与感兴趣对象之间的距离之间的距离。增加DisparityRange当摄像机远part or the objects are close to the cameras. To determine a reasonable disparity for your configuration, display the stereo anaglyph of the input images in theImage Viewerapp and use the Distance tool to measure distances between pairs of corresponding points. Modify themaxdisparity对应于测量。

References

[1] Konolige, K.,小型视觉系统:硬件和实施, Proceedings of the 8th International Symposium in Robotic Research, pages 203-212, 1997.

[2] Bradski,G。和A. Kaehler,Learning OpenCV : Computer Vision with the OpenCV Library, O'Reilly, Sebastopol, CA, 2008.

[3] Hirschmuller,H.,通过半全球匹配和相互信息进行准确有效的立体声处理, International Conference on Computer Vision and Pattern Recognition, 2005.

扩展功能

Version History

Introduced in R2011b

expand all

不建议从R2019A开始