cars.applications.dense_matching.dense_matching_tools

This module is responsible for the dense matching algorithms: - thus it creates a disparity map from a pair of images

Module Contents

Functions

get_margins(disp_min, disp_max, corr_cfg)

Get margins for the dense matching steps

get_masks_from_pandora(→ Dict[str, numpy.ndarray])

Get masks dictionary from the disparity map in output of pandora.

add_color(output_dataset[, color, color_mask])

"

create_disp_dataset(→ xarray.Dataset)

Create the disparity dataset.

add_ambiguity(output_dataset, disp, ref_roi)

"

compute_mask_to_use_in_pandora(→ numpy.ndarray)

Compute the mask to use in Pandora.

compute_disparity(→ Dict[str, xarray.Dataset])

This function will compute disparity.

optimal_tile_size_pandora_plugin_libsgm(→ int)

Compute optimal tile size according to estimated memory usage

estimate_color_from_disparity(→ xarray.Dataset)

Estimate color image of reference from the disparity map and the secondary

cars.applications.dense_matching.dense_matching_tools.get_margins(disp_min, disp_max, corr_cfg)

Get margins for the dense matching steps

Parameters
  • disp_min (int) – Minimum disparity

  • disp_max (int) – Maximum disparity

  • corr_cfg (dict) – Correlator configuration

Returns

margins of the matching algorithm used

cars.applications.dense_matching.dense_matching_tools.get_masks_from_pandora(disp: xarray.Dataset, compute_disparity_masks: bool) Dict[str, numpy.ndarray]

Get masks dictionary from the disparity map in output of pandora.

Parameters
  • disp – disparity map (pandora output)

  • compute_disparity_masks – compute_disparity_masks activation status

Returns

masks dictionary

cars.applications.dense_matching.dense_matching_tools.add_color(output_dataset: xarray.Dataset, color: numpy.ndarray = None, color_mask: numpy.ndarray = None)

” Add color and color mask to dataset

Parameters
  • output_dataset – output dataset

  • color – color array

  • color_mask – color mask array

cars.applications.dense_matching.dense_matching_tools.create_disp_dataset(disp: xarray.Dataset, ref_dataset: xarray.Dataset, compute_disparity_masks: bool = False) xarray.Dataset

Create the disparity dataset.

Parameters
  • disp – disparity map (result of pandora)

  • ref_dataset – reference dataset for the considered disparity map

  • compute_disparity_masks – compute_disparity_masks activation status

Returns

disparity dataset as used in cars

cars.applications.dense_matching.dense_matching_tools.add_ambiguity(output_dataset: xarray.Dataset, disp: xarray.Dataset, ref_roi: List[int])

” Add ambiguity to dataset

Parameters
  • output_dataset – output dataset

  • disp – disp xarray

cars.applications.dense_matching.dense_matching_tools.compute_mask_to_use_in_pandora(dataset: xarray.Dataset, msk_key: str, classes_to_ignore: List[int], out_msk_dtype: numpy.dtype = np.int16) numpy.ndarray

Compute the mask to use in Pandora. Valid pixels will be set to the value of the ‘valid_pixels’ field of the correlation configuration file. No data pixels will be set to the value of the ‘no_data’ field of the correlation configuration file. Nonvalid pixels will be set to a value automatically determined to be different from the ‘valid_pixels’ and the ‘no_data’ fields of the correlation configuration file.

Parameters
  • dataset – dataset containing the multi-classes mask from which the mask to used in Pandora will be computed

  • msk_key – key to use to access the multi-classes mask in the dataset

  • classes_to_ignore

  • out_msk_dtype – numpy dtype of the returned mask

Returns

the mask to use in Pandora

cars.applications.dense_matching.dense_matching_tools.compute_disparity(left_dataset, right_dataset, corr_cfg, disp_min=None, disp_max=None, mask1_ignored_by_corr=None, mask2_ignored_by_corr=None, use_sec_disp=True, compute_disparity_masks=False) Dict[str, xarray.Dataset]

This function will compute disparity.

Parameters
  • left_dataset (xarray.Dataset) – Dataset containing left image and mask

  • right_dataset (xarray.Dataset) – Dataset containing right image and mask

  • corr_cfg (dict) – Correlator configuration

  • disp_min (int) – Minimum disparity (if None, value is taken from left dataset)

  • disp_max (int) – Maximum disparity (if None, value is taken from left dataset)

  • mask1_ignored_by_corr (List[int]) – mask values used to ignore by correlation

  • mask2_ignored_by_corr (List[int]) – mask values used to ignore by correlation

  • use_sec_disp (bool) – Boolean activating the use of the secondary disparity map

  • compute_disparity_masks (Boolean) – Activation of compute_disparity_masks mode

Returns

Dictionary of disparity dataset. Keys are (if it is computed by Pandora):

  • ’ref’ for the left to right disparity map

  • ’sec’ for the right to left disparity map

cars.applications.dense_matching.dense_matching_tools.optimal_tile_size_pandora_plugin_libsgm(disp_min: int, disp_max: int, min_tile_size: int, max_tile_size: int, max_ram_per_worker: int, tile_size_rounding: int = 50, margin: int = 0) int

Compute optimal tile size according to estimated memory usage (pandora_plugin_libsgm) Returned optimal tile size will be at least equal to tile_size_rounding.

Parameters
  • disp_min – Minimum disparity to explore

  • disp_max – Maximum disparity to explore

  • min_tile_size – Minimal tile size

  • max_tile_size – Maximal tile size

  • max_ram_per_worker – amount of RAM allocated per worker

  • tile_size_rounding – Optimal tile size will be aligned to multiples of tile_size_rounding

  • margin – margin to remove to the computed tile size (as a percent of the computed tile size)

Returns

Optimal tile size according to benchmarked memory usage

cars.applications.dense_matching.dense_matching_tools.estimate_color_from_disparity(disp_ref_to_sec: xarray.Dataset, sec_ds: xarray.Dataset) xarray.Dataset

Estimate color image of reference from the disparity map and the secondary color image.

Parameters
  • disp_ref_to_sec – disparity map

  • sec_ds – secondary image dataset

Returns

interpolated reference color image dataset