pandora2d.refinement.optical_flow

This module contains functions associated to the optical flow method used in the refinement step.

Classes

OpticalFlow

OpticalFLow class allows to perform the subpixel cost refinement step

Module Contents

class pandora2d.refinement.optical_flow.OpticalFlow(cfg: dict = None, step: list = None, window_size: int = 5)[source]

Bases: pandora2d.refinement.refinement.AbstractRefinement

OpticalFLow class allows to perform the subpixel cost refinement step

_invalid_disp = None[source]
_ITERATIONS = 4[source]
schema[source]
_iterations[source]
_refinement_method[source]
_window_size[source]
_step[source]
classmethod check_conf(cfg: dict) dict[source]

Check the refinement configuration

Parameters:

cfg – user_config for refinement

Returns:

cfg: global configuration

property margins[source]
reshape_to_matching_cost_window(img: xarray.Dataset, cost_volumes: xarray.Dataset, coordinates: tuple[list, list], disp_row: numpy.typing.NDArray = None, disp_col: numpy.typing.NDArray = None) numpy.typing.NDArray[source]

Transform image from (nb_col, nb_row) to (window_size, window_size, nbcol*nbrow)

Parameters:
  • img – image to reshape

  • cost_volumes – cost_volumes 4D row, col, disp_col, disp_row

  • coordinates – min and max index coordinate for row and col [(first_row,last_row),(first_col,last_col)]

  • disp_row – array dim [] containing all the row shift

  • disp_col – array dim [] containing all the columns shift

Returns:

array containing reshaped image [window_size, window_size, nbcol*nbrow]

warped_img(right_reshape: numpy.typing.NDArray, delta_row: numpy.typing.NDArray, delta_col: numpy.typing.NDArray, index_to_compute: list) numpy.typing.NDArray[source]

Shifted matching_cost window with computed disparity

Parameters:
  • right_reshape – image right reshaped with dims (window_size, window_size, nbcol*nb_row)

  • delta_row – rows disparity map

  • delta_col – columns disparity map

  • index_to_compute – list containing all valid pixel for computing optical flow

Returns:

new array containing shifted matching_cost windows

lucas_kanade_core_algorithm(left_data: numpy.typing.NDArray, right_data: numpy.typing.NDArray) tuple[float, float][source]

Implement lucas & kanade algorithm core

Parameters:
  • left_data – matching_cost window for one pixel from left image

  • right_data – matching_cost window for one pixel from left image

Returns:

sub-pixel disparity computed by Lucas & Kanade optical flow

optical_flow(left_img: numpy.typing.NDArray, right_img: numpy.typing.NDArray, list_idx_to_compute: list) tuple[numpy.typing.NDArray, numpy.typing.NDArray, list][source]

Computing optical flow between left and right image

Parameters:
  • left_img – reshaped left image array

  • right_img – reshaped right image array

  • list_idx_to_compute – list of valid pixel

Returns:

computed sub-pixel disparity map

static find_nearest_column(value: int, data: numpy.typing.NDArray, direction: Literal['+', '-']) numpy.typing.NDArray[source]

Return the nearest column from initial column index coordinate in a given direction

Parameters:
  • value – initial column index

  • data – cost volume coordinates

  • direction – direction sign (must be + or -)

refinement_method(cost_volumes: xarray.Dataset, disp_map: xarray.Dataset, img_left: xarray.Dataset, img_right: xarray.Dataset) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Return the subpixel disparity maps

Parameters:
  • cost_volumes – cost_volumes 4D row, col, disp_col, disp_row

  • disp_map – pixels disparity maps

  • img_left – left image dataset

  • img_right – right image dataset

Returns:

the refined disparity maps and disparity correlation score

_invalid_out_of_grid_disparities(step: list, delta: numpy.typing.NDArray[numpy.floating], disparity: xarray.DataArray) None[source]

Replace delta values by invalid_disp value when it is outside the corresponding disparity range defined by the disparity grid.

Parameters:
  • step – [row_step, col_step]

  • delta – refined disparity map

  • disparity – pixelic disparity grids with min and max band_disp coordinates.