Stereo#

kornia.metrics.mean_absolute_disparity_error(input, target, valid_mask=None, reduction='mean')[source]#

Compute the mean absolute error (MAE) between two disparity maps.

Given predicted and ground truth disparity maps \(D\) and \(D^{gt}\) with valid pixels \(\mathcal{V}\), the metric is:

\[\text{MAE}(D, D^{gt}) = \frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}} |D_{p} - D^{gt}_{p}|\]
Parameters:
  • input (Tensor) – the predicted disparity map with arbitrary shape \((*)\).

  • target (Tensor) – the ground truth disparity map with the same shape as input.

  • valid_mask (Optional[Tensor], optional) – optional mask broadcastable to the shape of input, where nonzero (True) values mark the pixels to evaluate. Non-boolean masks are converted to boolean. If None, all pixels are evaluated. Default: None

  • reduction (str, optional) – specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'mean': the error is averaged over the valid pixels, 'sum': the error is summed over the valid pixels, 'none': no reduction will be applied and the per-pixel error map is returned, with masked-out positions set to zero. Default: "mean"

Return type:

Tensor

Returns:

the computed metric as a scalar, or the per-pixel error map if reduction='none'.

Note

If valid_mask selects no pixels, 'mean' reduction returns nan.

Examples

>>> input = torch.tensor([[0.0, 1.0], [2.0, 3.0]])
>>> target = torch.tensor([[0.0, 1.0], [2.0, 4.0]])
>>> mean_absolute_disparity_error(input, target)
tensor(0.2500)
>>> valid_mask = torch.tensor([[True, True], [True, False]])
>>> mean_absolute_disparity_error(input, target, valid_mask)
tensor(0.)
Reference:

D. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo correspondence algorithms. IJCV 2002. https://vision.middlebury.edu/stereo/taxonomy-IJCV.pdf

kornia.metrics.root_mean_squared_disparity_error(input, target, valid_mask=None, reduction='mean')[source]#

Compute the root mean squared error (RMSE) between two disparity maps.

Given predicted and ground truth disparity maps \(D\) and \(D^{gt}\) with valid pixels \(\mathcal{V}\), the metric is:

\[\text{RMSE}(D, D^{gt}) = \sqrt{\frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}} (D_{p} - D^{gt}_{p})^{2}}\]
Parameters:
  • input (Tensor) – the predicted disparity map with arbitrary shape \((*)\).

  • target (Tensor) – the ground truth disparity map with the same shape as input.

  • valid_mask (Optional[Tensor], optional) – optional mask broadcastable to the shape of input, where nonzero (True) values mark the pixels to evaluate. Non-boolean masks are converted to boolean. If None, all pixels are evaluated. Default: None

  • reduction (str, optional) – specifies the reduction to apply to the squared error before the square root: 'none' | 'mean' | 'sum'. 'mean': the squared error is averaged over the valid pixels, 'sum': the squared error is summed over the valid pixels, 'none': no reduction will be applied and the per-pixel absolute error map is returned, with masked-out positions set to zero. Default: "mean"

Return type:

Tensor

Returns:

the computed metric as a scalar, or the per-pixel error map if reduction='none'.

Note

If valid_mask selects no pixels, 'mean' reduction returns nan.

Examples

>>> input = torch.zeros(2, 2)
>>> target = torch.tensor([[0.0, 0.0], [0.0, 1.0]])
>>> root_mean_squared_disparity_error(input, target)
tensor(0.5000)
Reference:

D. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo correspondence algorithms. IJCV 2002. https://vision.middlebury.edu/stereo/taxonomy-IJCV.pdf

kornia.metrics.mean_bad_pixel_error(input, target, threshold=3.0, valid_mask=None, reduction='mean')[source]#

Compute the bad pixel ratio between two disparity maps.

A pixel is considered bad when its absolute disparity error is strictly greater than threshold. Given predicted and ground truth disparity maps \(D\) and \(D^{gt}\) with valid pixels \(\mathcal{V}\), the metric is:

\[\text{Bad}_{\tau}(D, D^{gt}) = \frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}} [|D_{p} - D^{gt}_{p}| > \tau]\]

This corresponds to the bad-pixel percentage reported by the Middlebury and KITTI stereo benchmarks, expressed as a fraction in \([0, 1]\) instead of a percentage.

Parameters:
  • input (Tensor) – the predicted disparity map with arbitrary shape \((*)\).

  • target (Tensor) – the ground truth disparity map with the same shape as input.

  • threshold (float, optional) – the disparity error above which a pixel is considered bad. Default: 3.0

  • valid_mask (Optional[Tensor], optional) – optional mask broadcastable to the shape of input, where nonzero (True) values mark the pixels to evaluate. Non-boolean masks are converted to boolean. If None, all pixels are evaluated. Default: None

  • reduction (str, optional) – specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'mean': the fraction of bad pixels among the valid pixels, 'sum': the number of bad pixels among the valid pixels, 'none': no reduction will be applied and the per-pixel bad-pixel map is returned, with masked-out positions set to zero. Default: "mean"

Return type:

Tensor

Returns:

the computed metric as a scalar, or the per-pixel bad-pixel map if reduction='none'.

Note

If valid_mask selects no pixels, 'mean' reduction returns nan.

Examples

>>> input = torch.zeros(2, 2)
>>> target = torch.tensor([[0.0, 1.0], [2.0, 4.0]])
>>> mean_bad_pixel_error(input, target, threshold=1.5)
tensor(0.5000)
Reference:

D. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo correspondence algorithms. IJCV 2002. https://vision.middlebury.edu/stereo/taxonomy-IJCV.pdf