pandora.aggregation.cbca

This module contains functions associated to the Cross Based Cost Aggregation (cbca) method.

Module Contents

Classes

CrossBasedCostAggregation

CrossBasedCostAggregation class, allows to perform the aggregation step

Functions

cbca_step_1(→ numpy.ndarray)

Giving the matching cost for one disparity, build a horizontal integral image storing the cumulative row sum,

cbca_step_2(→ Tuple[numpy.ndarray, numpy.ndarray])

Giving the horizontal integral image, computed the horizontal matching cost for one disparity,

cbca_step_3(→ numpy.ndarray)

Giving the horizontal matching cost, build a vertical integral image for one disparity,

cbca_step_4(→ Tuple[numpy.ndarray, numpy.ndarray])

Giving the vertical integral image, build the fully aggregated matching cost for one disparity,

cross_support(→ numpy.ndarray)

Compute the cross support for an image: find the 4 arms.

class pandora.aggregation.cbca.CrossBasedCostAggregation(**cfg: dict)[source]

Bases: pandora.aggregation.aggregation.AbstractAggregation

CrossBasedCostAggregation class, allows to perform the aggregation step

_CBCA_INTENSITY = 30.0[source]
_CBCA_DISTANCE = 5[source]
check_conf(**cfg: str | float | int) Dict[str, str | float | int][source]

Add default values to the dictionary if there are missing elements and check if the dictionary is correct

Parameters:

cfg (dict) – aggregation configuration

Return cfg:

aggregation configuration updated

Return type:

dict

desc()[source]

Describes the aggregation method

cost_volume_aggregation(img_left: xarray.Dataset, img_right: xarray.Dataset, cv: xarray.Dataset, **cfg: str | int) None[source]

Aggregated the cost volume with Cross-Based Cost Aggregation, using the pipeline define in Zhang, K., Lu, J., & Lafruit, G. (2009). Cross-based local stereo matching using orthogonal integral images. IEEE transactions on circuits and systems for video technology, 19(7), 1073-1079.

Parameters:
  • img_left (xarray.Dataset) –

    left Dataset image containing :

    • im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32

    • disparity (optional): 3D (disp, row, col) xarray.DataArray float32

    • msk (optional): 2D (row, col) xarray.DataArray int16

    • classif (optional): 3D (band_classif, row, col) xarray.DataArray int16

    • segm (optional): 2D (row, col) xarray.DataArray int16

  • img_right (xarray.Dataset) –

    right Dataset image containing :

    • im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32

    • disparity (optional): 3D (disp, row, col) xarray.DataArray float32

    • msk (optional): 2D (row, col) xarray.DataArray int16

    • classif (optional): 3D (band_classif, row, col) xarray.DataArray int16

    • segm (optional): 2D (row, col) xarray.DataArray int16

  • cv (xarray.Dataset) –

    cost volume dataset with the data variables:

    • cost_volume 3D xarray.DataArray (row, col, disp)

    • confidence_measure 3D xarray.DataArray (row, col, indicator)

  • cfg (dict) – images configuration containing the mask convention : valid_pixels, no_data

Returns:

None

computes_cross_supports(img_left: xarray.Dataset, img_right: xarray.Dataset, cv: xarray.Dataset) Tuple[numpy.ndarray, List[numpy.ndarray]][source]

Prepare images and compute the cross support region of the left and right images. A 3x3 median filter is applied to the images before calculating the cross support region.

Parameters:
  • img_left (xarray.Dataset) –

    left Dataset image containing :

    • im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32

    • disparity (optional): 3D (disp, row, col) xarray.DataArray float32

    • msk (optional): 2D (row, col) xarray.DataArray int16

    • classif (optional): 3D (band_classif, row, col) xarray.DataArray int16

    • segm (optional): 2D (row, col) xarray.DataArray int16

  • img_right (xarray.Dataset) –

    right Dataset image containing :

    • im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32

    • disparity (optional): 3D (disp, row, col) xarray.DataArray float32

    • msk (optional): 2D (row, col) xarray.DataArray int16

    • classif (optional): 3D (band_classif, row, col) xarray.DataArray int16

    • segm (optional): 2D (row, col) xarray.DataArray int16

  • cv (xarray.Dataset) –

    cost volume dataset with the data variables:

    • cost_volume 3D xarray.DataArray (row, col, disp)

    • confidence_measure 3D xarray.DataArray (row, col, indicator)

Returns:

the left and right cross support region

Return type:

Tuples(left cross support region, List(right cross support region))

pandora.aggregation.cbca.cbca_step_1(cv: numpy.ndarray) numpy.ndarray[source]

Giving the matching cost for one disparity, build a horizontal integral image storing the cumulative row sum, S_h(row, col) = S_h(row-1, col) + cv(row, col)

Parameters:

cv (2D np.array (row, col) dtype = np.float32) – cost volume for the current disparity

Returns:

the horizontal integral image, step 1

Return type:

2D np.array (row, col + 1) dtype = np.float32

pandora.aggregation.cbca.cbca_step_2(step1: numpy.ndarray, cross_left: numpy.ndarray, cross_right: numpy.ndarray, range_col: numpy.ndarray, range_col_right: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray][source]

Giving the horizontal integral image, computed the horizontal matching cost for one disparity, E_h(row, col) = S_h(row + right_arm_length, col) - S_h(row - left_arm_length -1, col)

Parameters:
  • step1 (2D np.array (row, col + 1) dtype = np.float32) – horizontal integral image, from the cbca_step1, with an extra column that contains 0

  • cross_left (3D np.array (row, col, [left, right, top, bot]) dtype=np.int16) – cross support of the left image

  • cross_right (3D np.array (row, col, [left, right, tpo, bot]) dtype=np.int16) – cross support of the right image

  • range_col (1D np.array) – left column for the current disparity (i.e : np.arrange(nb columns), where the correspondent in the right image is reachable)

  • range_col_right (1D np.array) – right column for the current disparity (i.e : np.arrange(nb columns) - disparity, where column - disparity >= 0 and <= nb columns)

Returns:

the horizontal matching cost for the current disparity, and the number of support pixels used for the step 2

Return type:

tuple (2D np.array (row, col) dtype = np.float32, 2D np.array (row, col) dtype = np.float32)

pandora.aggregation.cbca.cbca_step_3(step2: numpy.ndarray) numpy.ndarray[source]

Giving the horizontal matching cost, build a vertical integral image for one disparity, S_v = S_v(row, col - 1) + E_h(row, col)

Parameters:

step2 (3D xarray.DataArray (row, col, disp)) – horizontal matching cost, from the cbca_step2

Returns:

the vertical integral image for the current disparity

Return type:

2D np.array (row + 1, col) dtype = np.float32

pandora.aggregation.cbca.cbca_step_4(step3: numpy.ndarray, sum2: numpy.ndarray, cross_left: numpy.ndarray, cross_right: numpy.ndarray, range_col: numpy.ndarray, range_col_right: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray][source]

Giving the vertical integral image, build the fully aggregated matching cost for one disparity, E = S_v(row, col + bottom_arm_length) - S_v(row, col - top_arm_length - 1)

Parameters:
  • step3 (2D np.array (row + 1, col) dtype = np.float32) – vertical integral image, from the cbca_step3, with an extra row that contains 0

  • sum2 (2D np.array (row, col) dtype = np.float32) – the number of support pixels used for the step 2

  • cross_left (3D np.array (row, col, [left, right, top, bot]) dtype=np.int16) – cross support of the left image

  • cross_right (3D np.array (row, col, [left, right, tpo, bot]) dtype=np.int16) – cross support of the right image

  • range_col (1D np.array) – left column for the current disparity (i.e : np.arrange(nb columns), where the correspondent in the right image is reachable)

  • range_col_right (1D np.array) – right column for the current disparity (i.e : np.arrange(nb columns) - disparity, where column - disparity >= 0 and <= nb columns)

Returns:

the fully aggregated matching cost, and the total number of support pixels used for the aggregation

Return type:

tuple(2D np.array (row , col) dtype = np.float32, 2D np.array (row , col) dtype = np.float32)

pandora.aggregation.cbca.cross_support(image: numpy.ndarray, len_arms: int, intensity: float) numpy.ndarray[source]

Compute the cross support for an image: find the 4 arms. Enforces a minimum support region of 3×3 if pixels are valid. The cross support of invalid pixels (pixels that are np.inf) is 0 for the 4 arms.

Parameters:
  • image (2D np.array (row , col) dtype = np.float32) – image

  • len_arms – maximal length arms

  • len_arms – int16

  • intensity – maximal intensity

  • intensity – float 32

Returns:

a 3D np.array ( row, col, [left, right, top, bot] ), with the four arms lengths computes for each pixel

Return type:

3D np.array ( row, col, [left, right, top, bot] ), dtype=np.int16