cars.core.tiling

Tiling module: contains functions related to regions and tiles management

Module Contents

Functions

grid(→ numpy.ndarray)

Generate grid of positions by splitting [xmin, xmax]x[ymin, ymax]

transform_four_layers_to_two_layers_grid(tiling_grid)

Transform a 4 layer grid: (N, M, 4) containing

transform_disp_range_grid_to_two_layers(disp_min_grid, ...)

Transform tiling disp min and max to N+1 M+1 array corresponding

generate_tiling_grid(→ numpy.ndarray)

Generate grid of positions by splitting [row_min, row_max] x

split(xmin, ymin, xmax, ymax, xsplit, ysplit)

Split a region defined by [xmin, xmax] x [ymin, ymax]

crop(region1, region2)

Crop a region by another one

pad(region, margins)

Pad region according to a margin

empty(region)

Check if a region is empty or inconsistent

union(regions)

Returns union of all regions

list_tiles(region, largest_region, tile_size[, margin])

Given a region, cut largest_region into tiles of size tile_size

roi_to_start_and_size(region, resolution)

Convert roi as array of [xmin, ymin, xmax, ymax]

snap_to_grid(xmin, ymin, xmax, ymax, resolution)

Given a roi as xmin, ymin, xmax, ymax, snap values to entire step

filter_simplices_on_the_edges(original_grid_shape, ...)

Filter simplices on the edges which allows to cut triangles out of the

terrain_grid_to_epipolar(terrain_tiling_grid, ...)

Transform terrain grid to epipolar region

region_hash_string(region)

This lambda will allow to derive a key

get_corresponding_tiles_row_col(→ Tuple[List, List, List])

This function allows to get required points cloud for each

get_paired_regions_as_geodict(→ Tuple[Dict, Dict])

Get paired regions (terrain/epipolar) as "geodictionnaries": these

cars.core.tiling.grid(xmin: float, ymin: float, xmax: float, ymax: float, xsplit: int, ysplit: int) numpy.ndarray
Generate grid of positions by splitting [xmin, xmax]x[ymin, ymax]

in splits of xsplit x ysplit size

:param xmin : xmin of the bounding box of the region to split :param ymin : ymin of the bounding box of the region to split :param xmax : xmax of the bounding box of the region to split :param ymax : ymax of the bounding box of the region to split :param xsplit: width of splits :param ysplit: height of splits

Returns

The output ndarray grid with nb_ysplits splits in first direction and nb_xsplits in second direction for 2 dimensions 0:x, 1:y

Return type

numpy array

cars.core.tiling.transform_four_layers_to_two_layers_grid(tiling_grid, terrain=False)
Transform a 4 layer grid: (N, M, 4) containing

[rowmin, rowmax, colmin, colmax] when epipolar and [xmin, xmax, ymin, ymax] with x = col and y = row into a 2 layer grid: (N+1, M+1, 2) containing x and y defined like : grid[j, i, 0] = min(xmax, xmin + i * xsplit) and grid[j, i, 1] = min(ymax, ymin + j * ysplit)

Parameters

tiling_grid (np.ndarray) – tiling grid

Returns

2D grid

Return type

np.ndarray

cars.core.tiling.transform_disp_range_grid_to_two_layers(disp_min_grid, disp_max_grid)
Transform tiling disp min and max to N+1 M+1 array corresponding

to N+1, M+1 , 2 tiling grid

Parameters
  • disp_min_grid (np ndarray) – disp min tiling

  • disp_max_grid (np ndarray) – disp max tiling

Returns

disp_min_grid, disp_max_grid

Return type

np ndarray , np ndarray

cars.core.tiling.generate_tiling_grid(row_min: float, col_min: float, row_max: float, col_max: float, row_split: int, col_split: int) numpy.ndarray
Generate grid of positions by splitting [row_min, row_max] x

[col_min, col_max] in splits of row_split x col_split size

:param row_min : row_min of the bounding box of the region to split :param col_min : col_min of the bounding box of the region to split :param row_max : row_max of the bounding box of the region to split :param col_max : col_max of the bounding box of the region to split :param row_split: height of splits :param col_split: width of splits

Returns

The output ndarray grid with nb_row_split splits in first direction and nb_col_split in second direction for 2 dimensions 0:y, 1:x [row, col, :] containing [row_min, row_max, col_min, col_max]

Return type

numpy array

cars.core.tiling.split(xmin, ymin, xmax, ymax, xsplit, ysplit)
Split a region defined by [xmin, xmax] x [ymin, ymax]

in splits of xsplit x ysplit size

:param xmin : xmin of the bounding box of the region to split :type xmin: float :param ymin : ymin of the bounding box of the region to split :type ymin: float :param xmax : xmax of the bounding box of the region to split :type xmax: float :param ymax : ymax of the bounding box of the region to split :type ymax: float :param xsplit: width of splits :type xsplit: int :param ysplit: height of splits :type ysplit: int

Returns

A list of splits represented by arrays of 4 elements [xmin, ymin, xmax, ymax]

Return type

list of 4 float

cars.core.tiling.crop(region1, region2)

Crop a region by another one

Parameters
  • region1 (list of four float) – The region to crop as an array [xmin, ymin, xmax, ymax]

  • region2 (list of four float) – The region used for cropping as an array [xmin, ymin, xmax, ymax]

Returns

The cropped regiona as an array [xmin, ymin, xmax, ymax]. If region1 is outside region2, might result in inconsistent region

Return type

list of four float

cars.core.tiling.pad(region, margins)

Pad region according to a margin

Parameters
  • region (list of four floats) – The region to pad

  • margins (list of four floats) – Margin to add

Returns

padded region

Return type

list of four float

cars.core.tiling.empty(region)

Check if a region is empty or inconsistent

Parameters

region (list of four float) – region as an array [xmin, ymin, xmax, ymax]

Returns

True if the region is considered empty (no pixels inside), False otherwise

Return type

bool

cars.core.tiling.union(regions)

Returns union of all regions

Parameters

regions (list of list of four float) – list of region as an array [xmin, ymin, xmax, ymax]

Returns

xmin, ymin, xmax, ymax

Return type

list of 4 float

cars.core.tiling.list_tiles(region, largest_region, tile_size, margin=1)

Given a region, cut largest_region into tiles of size tile_size and return tiles that intersect region within margin pixels.

Parameters
  • region (list of four float) – The region to list intersecting tiles

  • largest_region (list of four float) – The region to split

  • tile_size (int) – Width of tiles for splitting (squared tiles)

  • margin (int) – Also include margin neighboring tiles

Returns

A list of tiles as dicts containing idx and idy

Return type

list of dict

cars.core.tiling.roi_to_start_and_size(region, resolution)

Convert roi as array of [xmin, ymin, xmax, ymax] to xmin, ymin, xsize, ysize given a resolution

Beware that a negative spacing is considered for y axis, and thus returned ystart is in fact ymax

Parameters
  • region (list of four float) – The region to convert

  • resolution (float) – The resolution to use to determine sizes

Returns

xstart, ystart, xsize, ysize tuple

Return type

list of two float + two int

cars.core.tiling.snap_to_grid(xmin, ymin, xmax, ymax, resolution)

Given a roi as xmin, ymin, xmax, ymax, snap values to entire step of resolution

Parameters
  • xmin (float) – xmin of the roi

  • ymin (float) – ymin of the roi

  • xmax (float) – xmax of the roi

  • ymax (float) – ymax of the roi

  • resolution (float) – size of cells for snapping

Returns

xmin, ymin, xmax, ymax snapped tuple

Return type

list of four float

cars.core.tiling.filter_simplices_on_the_edges(original_grid_shape: Tuple, tri: scipy.spatial.Delaunay, simplices: numpy.ndarray)

Filter simplices on the edges which allows to cut triangles out of the concave Delaunay triangulation.

Parameters
  • original_grid_shape – shape of the original grid (almost regular) used to create delaunay triangulation

  • tri – Delaunay triangulation

  • simplices – Selected simplices to filter: set -1 if selected simplex is on the edges

cars.core.tiling.terrain_grid_to_epipolar(terrain_tiling_grid, epipolar_tiling_grid, epipolar_grid_min, epipolar_grid_max, epsg)

Transform terrain grid to epipolar region

cars.core.tiling.region_hash_string(region: Tuple)

This lambda will allow to derive a key to index region in the previous dictionary

Parameters

region – region to hash

cars.core.tiling.get_corresponding_tiles_row_col(terrain_tiling_grid: numpy.ndarray, row: int, col: int, list_points_clouds: list, list_epipolar_points_min: list, list_epipolar_points_max: list) Tuple[List, List, List]

This function allows to get required points cloud for each terrain region.

Parameters
  • terrain_tiling_grid – terrain grid positions

  • row – row

  • col – column epipolar input tiles where keys are image pairs index and values are epipolar_points_min, epipolar_points_max, largest_epipolar_region, opt_epipolar_tile_size

Returns

Terrain regions Corresponding tiles selected from delayed_point_clouds with associated id Terrain regions “rank” allowing to sorting tiles for dask processing

cars.core.tiling.get_paired_regions_as_geodict(terrain_regions: List, epipolar_regions: List) Tuple[Dict, Dict]

Get paired regions (terrain/epipolar) as “geodictionnaries”: these objects can be dumped into geojson files to be visualized.

Parameters
  • terrain_regions – terrain region respecting cars tiling

  • epipolar_regions – corresponding epipolar regions

Returns

Terrain dictionary and Epipolar dictionary containing respectively Terrain tiles in terrain projection and Epipolar tiles in epipolar projection