BlockMatching¶
执行块匹配以估计两个图像之间的像素方向差异。
描述¶
这个应用程序允许执行块匹配,以估计极线几何中的一对图像的像素方向视差。
这个应用程序是立体视觉管道的一部分。可在计算核极线网格后使用(带 StereoRectificationGridGenerator ),并将每个输入图像重新采样为对极几何图形(带有 GridBasedImageResampling )。
该应用程序在本地搜索参考图像和次要图像之间的位移。基于一对局部邻域窗口来评估每个像素的对应关系。计算的位移可以是一维(沿线)或二维。参数允许设置要搜索的最小和最大视差(水平和垂直方向)。赢家通吃的方法被用来选择最佳匹配。实施了不同的指标来评估两个本地窗口之间的匹配:
- SSD:距离平方和
- NCC:归一化互相关
- Lp:Lp伪模
一旦找到最佳整数视差,就可以使用各种算法(三角内插、抛物线内插、二次搜索)执行亚像素视差估计的可选步骤。作为后处理,有一个可选的步骤,即对视差进行中值滤波。可以选择应该调查其视差的像素的输入掩码(与左和右输入图像相关)。此外,可以选择使用两个标准来禁用某些像素的视差调查:无数据值和局部方差阈值。这使得人们可以通过避免调查本来就不可靠的差异来加快计算速度。出于效率原因,如果需要最佳度量值的图像,则将其连接到输出图像(然后输出图像将具有三个带:水平视差、垂直视差和度量值)。人们可以在之后拆分这些图像。
这个应用程序有几个输出图像,并支持“多写”。不是独立地计算和写入每个图像,而是以同步的方式为每个输出写入流图像块。输出图像将逐条计算,使用可用的RAM计算条带大小,并且可以使用流扩展文件名(类型、模式和值)指定用户定义的流模式。请注意,可以使用多写扩展文件名选项禁用多写,在这种情况下,将逐个写入输出图像。请注意,MPI编写器不支持多重写入。
参数¶
输入和输出数据¶
这组参数允许设置输入和输出图像。
Left input image -io.inleft image
Mandatory
The left input image (reference).
It should have the same size and same physical space as the right input. This image can be generated by GridBasedImageResampling
Right input image -io.inright image
Mandatory
The right input (secondary).
It should have the same size and same physical space as the left input. This image can be generated by GridBasedImageResampling
The output disparity map -io.out image [dtype]
Mandatory
An image containing the estimated disparities as well as the metric values if the option is used. If no metric is output and no sub-pixel interpolation is done, pixel type canbe a signed integer. In the other cases, floating point pixel is advised.
The output mask corresponding to all criterions -io.outmask image [dtype]
An output mask image corresponding to all citerions (see masking parameters). Only required if variance threshold or nodata criterions are set. Output pixel type is unsigned 8bit by default.
Flag to output optimal metric values as well -io.outmetric bool
Default value: false
If enabled, the output image will have a third component with metric optimal values
图像掩蔽参数¶
这组参数允许确定掩蔽参数,以防止对左侧图像的某些像素进行视差估计
Mask to discard left pixels -mask.inleft image
This parameter allows providing a custom mask for the left image. Block matching will be only perform on pixels inside the mask (non-zero values).
Mask to discard right pixels -mask.inright image
This parameter allows providing a custom mask for the right image. Block matching will be perform only on pixels inside the mask (non-zero values).
Discard pixels with no-data value -mask.nodata float
Default value: 0
This parameter allows discarding pixels whose value is equal to the user-defined no-data value.
Discard pixels with low local variance -mask.variancet float
Default value: 100
This parameter allows discarding pixels whose local variance is too small (the size of the neighborhood is given by the radius parameter)
块匹配参数¶
这组参数允许调整块匹配行为
Block-matching metric -bm.metric [ssd|ncc|lp]
Default value: ssd
Metric to evaluate matching between two local windows.
- Sum of Squared Distances
Sum of squared distances between pixels value in the metric window - Normalized Cross-Correlation
Normalized Cross-Correlation between the left and right windows - Lp pseudo-norm
Lp pseudo-norm between the left and right windows.
Lp伪范数期权¶
p value -bm.metric.lp.p float
Default value: 1
Value of the p parameter in Lp pseudo-norm (must be positive).
Radius of blocks -bm.radius int
Default value: 3
The radius (in pixels) of blocks in Block-Matching
Minimum horizontal disparity -bm.minhd int
Mandatory
Minimum horizontal disparity to explore (can be negative)
Maximum horizontal disparity -bm.maxhd int
Mandatory
Maximum horizontal disparity to explore (can be negative)
Minimum vertical disparity -bm.minvd int
Mandatory
Minimum vertical disparity to explore (can be negative)
Maximum vertical disparity -bm.maxvd int
Mandatory
Maximum vertical disparity to explore (can be negative)
Sub-pixel interpolation -bm.subpixel [none|parabolic|triangular|dichotomy]
Default value: none
Estimate disparities with sub-pixel precision
- None
No sub-pixel search - Parabolic fit
The metric values closest to the best match are used in order to fit a parabola to the local extremum of the metric surface. The peak position of this parabola is output. - Triangular fit
The metric values closest to the best match are used in order to fit a triangular peak to the local extremum of the metric surface. The peak position of this triangle is output. - Dichotomy search
An iterative dichotomic search is performed to find the best sub-pixel position. The window in the right image is resampled at sub-pixel positions to estimate the match.
Computation step -bm.step int
Default value: 1
Location step between computed disparities. Disparities will be computed every 'step' pixels in the left image (step for both rows and columns). For instance, a value of 1 corresponds to the classic dense disparity map.To enforce consistency with its spacing, output disparity map values are divided by the step value.
X start index -bm.startx int
Default value: 0
X start index of the subsampled grid (wrt the input image grid). See parameter bm.step
Y start index -bm.starty int
Default value: 0
Y start index of the subsampled grid (wrt the input image grid). See parameter bm.step
视差图的中值滤波¶
使用中值滤波来获得平滑的视差图
Radius -bm.medianfilter.radius int
Radius (in pixels) for median filter
Incoherence threshold -bm.medianfilter.incoherence float
Incoherence threshold between original and filtered disparity
Initial disparities -bm.initdisp [none|uniform|maps]
Default value: none
- None
No initial disparity used - Uniform initial disparity
Use an uniform initial disparity estimate - Initial disparity maps
Use initial disparity maps to define the exploration area. This area in the right image is centered on the current position shifted by the initial disparity estimate, and has a given exploration radius in horizontal and vertical directions.
统一初始视差选项¶
Horizontal initial disparity -bm.initdisp.uniform.hdisp int
Default value: 0
Value of the uniform horizontal disparity initial estimate (in pixels)
Vertical initial disparity -bm.initdisp.uniform.vdisp int
Default value: 0
Value of the uniform vertical disparity initial estimate (in pixels)
Horizontal exploration radius -bm.initdisp.uniform.hrad int
Default value: 0
Horizontal exploration radius around the initial disparity estimate (in pixels)
Vertical exploration radius -bm.initdisp.uniform.vrad int
Default value: 0
Vertical exploration radius around the initial disparity estimate (in pixels)
初始视差图选项¶
Horizontal initial disparity map -bm.initdisp.maps.hmap image
Mandatory
Map of the initial horizontal disparities
Vertical initial disparity map -bm.initdisp.maps.vmap image
Mandatory
Map of the initial vertical disparities
Horizontal exploration radius -bm.initdisp.maps.hrad int
Default value: 0
Horizontal exploration radius around the initial disparity estimate (in pixels)
Vertical exploration radius -bm.initdisp.maps.vrad int
Default value: 0
Vertical exploration radius around the initial disparity estimate (in pixels)
Available RAM (MB) -ram int
Default value: 256
Available memory for processing (in MB).
实例¶
从命令行执行以下操作:
otbcli_BlockMatching -io.inleft StereoFixed.png -io.inright StereoMoving.png -bm.minhd -10 -bm.maxhd 10 -mask.variancet 10 -io.out MyDisparity.tif
来自Python的评论:
import otbApplication
app = otbApplication.Registry.CreateApplication("BlockMatching")
app.SetParameterString("io.inleft", "StereoFixed.png")
app.SetParameterString("io.inright", "StereoMoving.png")
app.SetParameterInt("bm.minhd", -10)
app.SetParameterInt("bm.maxhd", 10)
app.SetParameterFloat("mask.variancet", 10)
app.SetParameterString("io.out", "MyDisparity.tif")
app.ExecuteAndWriteOutput()