pandora.matching_cost.matching_cost
This module contains functions associated to the cost volume measure step.
Module Contents
Classes
Abstract Matching Cost class |
- class pandora.matching_cost.matching_cost.AbstractMatchingCost[source]
Abstract Matching Cost class
- classmethod register_subclass(short_name: str, *args)[source]
Allows to register the subclass with its short name
- Parameters:
short_name (string) – the subclass to be registered
args – allows to register one plugin that contains different methods
- instantiate_class(**cfg: str | int) None [source]
- Parameters:
cfg (dictionary) – optional configuration, {‘window_size’: int, ‘subpix’: int, ‘band’: str}
- Returns:
None
- check_conf(**cfg: Dict[str, str | int]) Dict [source]
Add default values to the dictionary if there are missing elements and check if the dictionary is correct
- Parameters:
cfg (dict) – matching cost configuration
- Return cfg:
matching cost configuration updated
- Return type:
dict
- check_band_input_mc(img_left: xarray.Dataset, img_right: xarray.Dataset) None [source]
Check coherence band parameter between inputs and matching cost step
- 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 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
- Returns:
None
- abstract compute_cost_volume(img_left: xarray.Dataset, img_right: xarray.Dataset, cost_volume: xarray.Dataset) xarray.Dataset [source]
Computes the cost volume for a pair of images
- 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
cost_volume (xr.Dataset) – an empty cost volume
- Returns:
the cost volume dataset , with the data variables:
cost_volume 3D xarray.DataArray (row, col, disp)
- Return type:
xarray.Dataset
- grid_estimation(img: xarray.Dataset, cfg: Dict[str, dict] | None, disparity_grids: Tuple[numpy.ndarray, numpy.ndarray]) xarray.Dataset [source]
Estimation of the grid xarray dataset that will store the cost volume.
- Parameters:
img (xarray.Dataset) – left Dataset image
cfg (dict) – user configuration
disparity_grids (Tuple[np.ndarray, np.ndarray]) – Tuple of disparity grids min and max
- Returns:
a grid with coordinates and a attributes list with:
indexs of columns to compute
size
sampling interval
- Return type:
xarray.Dataset
- allocate_cost_volume(image: xarray.Dataset, disparity_grids: Tuple[numpy.ndarray, numpy.ndarray], cfg: Dict = None) xarray.Dataset [source]
Create a cost_volume dataset.
- Parameters:
image (xr.Dataset) – Image to compute cost volume from
cfg (Dict) – user configuration
disparity_grids (Tuple[np.ndarray, np.ndarray]) – Tuple of disparity grids min and max
- Returns:
a empty grid
- Return type:
xr.Dataset
- static get_disparity_range(disparity_min: int, disparity_max: int, subpix: int) numpy.ndarray [source]
Build disparity range and return it.
- Parameters:
disparity_min (int) – minimum disparity
disparity_max (int) – maximum disparity
subpix – subpixel precision = (1 or 2 or 4)
- Returns:
disparity range
- Return type:
np.ndarray
- point_interval(img_left: xarray.Dataset, img_right: xarray.Dataset, disp: float) Tuple[Tuple[int, int], Tuple[int, int]] [source]
Computes the range of points over which the similarity measure will be applied
- 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
disp (float) – current disparity
- Returns:
the range of the left and right image over which the similarity measure will be applied
- Return type:
tuple
- static masks_dilatation(img_left: xarray.Dataset, img_right: xarray.Dataset, window_size: int, subp: int) Tuple[xarray.DataArray, List[xarray.DataArray]] [source]
- Return the left and right mask with the convention :
Invalid pixels are nan
No_data pixels are nan
Valid pixels are 0
Apply dilation on no_data : if a pixel contains a no_data in its aggregation window, then the central pixel becomes no_data
- 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
window_size (int) – window size of the measure
subp (int) – subpixel precision = (1 or 2 or 4)
- Returns:
the left mask and the right masks:
left mask : xarray.DataArray msk 2D(row, col)
right mask : xarray.DataArray msk 2D(row, col)
right mask shifted : xarray.DataArray msk 2D(row, shifted col by 0.5)
- Return type:
tuple (left mask, list[right mask, right mask shifted by 0.5])
- static get_min_max_from_grid(disp_min: numpy.ndarray, disp_max: numpy.ndarray) Tuple[int, int] [source]
Find the smallest disparity present in disp_min, and the highest disparity present in disp_max
- Parameters:
disp_min (np.ndarray) – minimum disparity
disp_max (np.ndarray) – maximum disparity
- Returns:
dmin_min: the smallest disparity in disp_min, dmax_max: the highest disparity in disp_max
- Return type:
Tuple(int, int)
- find_nearest_multiple_of_step(value: int) int [source]
In case value is not a multiple of step, find nearest greater value for which it is the case.
- Parameters:
value – Initial value.
- Type:
value: int
- Returns:
nearest multiple of step.
- Return type:
int
- cv_masked(img_left: xarray.Dataset, img_right: xarray.Dataset, cost_volume: xarray.Dataset, disp_min: numpy.ndarray, disp_max: numpy.ndarray) None [source]
- Masks the cost volume :
costs which are not inside their disparity range, are masked with a nan value
costs of invalid_pixels (invalidated by the input image mask), are masked with a nan value
- costs of no_data pixels, are masked with a nan value. If a valid pixel contains a no_data in its
aggregation window, then the cost of the central pixel is masked with a nan value
- 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
cost_volume (xarray.Dataset) –
the cost_volume DataSet with the data variables:
cost_volume 3D xarray.DataArray (row, col, disp)
disp_min (np.ndarray) – minimum disparity
disp_max (np.ndarray) – maximum disparity
- Returns:
None
- allocate_numpy_cost_volume(img_left: xarray.Dataset, disparity_range: numpy.ndarray | List) numpy.ndarray [source]
Allocate the numpy cost volume cv = (disp, col, row), for efficient memory management
- 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
disparity_range (np.ndarray) – disparity range
offset_row_col (int) – offset in row and col
- Returns:
the cost volume dataset , with the data variables:
cost_volume 3D xarray.DataArray (row, col, disp)
- Return type:
xarray.Dataset
- static crop_cost_volume(cost_volume: numpy.ndarray, offset: int = 0) numpy.ndarray [source]
Return a cropped view of cost_volume.
If offset, do not consider border position for cost computation. :param cost_volume: cost volume to crop :type cost_volume: np.ndarray :param offset: offset used to crop cost volume :type offset: int :return: cropped view of cost_volume. :rtype: np.ndarray