cars.core.tiling ================ .. py:module:: cars.core.tiling .. autoapi-nested-parse:: Tiling module: contains functions related to regions and tiles management Functions --------- .. autoapisummary:: cars.core.tiling.grid cars.core.tiling.transform_four_layers_to_two_layers_grid cars.core.tiling.transform_disp_range_grid_to_two_layers cars.core.tiling.generate_tiling_grid cars.core.tiling.compute_local_disp_range_from_grids cars.core.tiling.split cars.core.tiling.crop cars.core.tiling.pad cars.core.tiling.empty cars.core.tiling.union cars.core.tiling.list_tiles cars.core.tiling.roi_to_start_and_size cars.core.tiling.snap_to_grid cars.core.tiling.filter_simplices_on_the_edges cars.core.tiling.terrain_grid_to_epipolar cars.core.tiling.region_hash_string cars.core.tiling.get_corresponding_tiles_row_col cars.core.tiling.get_paired_regions_as_geodict Module Contents --------------- .. py:function:: 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 :return: The output ndarray grid with nb_ysplits splits in first direction and nb_xsplits in second direction for 2 dimensions 0:x, 1:y :rtype: numpy array .. py:function:: 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) :param tiling_grid: tiling grid :type tiling_grid: np.ndarray :return: 2D grid :rtype: np.ndarray .. py:function:: 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 :param disp_min_grid: disp min tiling :type disp_min_grid: np ndarray :param disp_max_grid: disp max tiling :type disp_max_grid: np ndarray :return: disp_min_grid, disp_max_grid :rtype: np ndarray , np ndarray .. py:function:: 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 :return: 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] :rtype: numpy array .. py:function:: compute_local_disp_range_from_grids(row_min, row_max, col_min, col_max, disp_min_grid_arr, disp_max_grid_arr, step_row, step_col, row_range, col_range) Compute local disparity min and max from disparity grids for a tile ROI. :param row_min: row min :param row_max: row max :param col_min: col min :param col_max: col max :param disp_min_grid_arr: disparity minimum grid :param disp_max_grid_arr: disparity maximum grid :param step_row: disparity grid row step :param step_col: disparity grid col step :param row_range: disparity grid row coordinates :param col_range: disparity grid col coordinates :return: rounded local disparity min and max :rtype: tuple(int, int) .. py:function:: 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 :return: A list of splits represented by arrays of 4 elements [xmin, ymin, xmax, ymax] :rtype: list of 4 float .. py:function:: crop(region1, region2) Crop a region by another one :param region1: The region to crop as an array [xmin, ymin, xmax, ymax] :type region1: list of four float :param region2: The region used for cropping as an array [xmin, ymin, xmax, ymax] :type region2: list of four float :return: The cropped regiona as an array [xmin, ymin, xmax, ymax]. If region1 is outside region2, might result in inconsistent region :rtype: list of four float .. py:function:: pad(region, margins) Pad region according to a margin :param region: The region to pad :type region: list of four floats :param margins: Margin to add :type margins: list of four floats :return: padded region :rtype: list of four float .. py:function:: empty(region) Check if a region is empty or inconsistent :param region: region as an array [xmin, ymin, xmax, ymax] :type region: list of four float :return: True if the region is considered empty (no pixels inside), False otherwise :rtype: bool .. py:function:: union(regions) Returns union of all regions :param regions: list of region as an array [xmin, ymin, xmax, ymax] :type regions: list of list of four float :return: xmin, ymin, xmax, ymax :rtype: list of 4 float .. py:function:: 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. :param region: The region to list intersecting tiles :type region: list of four float :param largest_region: The region to split :type largest_region: list of four float :param tile_size: Width of tiles for splitting (squared tiles) :type tile_size: int :param margin: Also include margin neighboring tiles :type margin: int :return: A list of tiles as dicts containing idx and idy :rtype: list of dict .. py:function:: 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 :param region: The region to convert :type region: list of four float :param resolution: The resolution to use to determine sizes :type resolution: float :return: xstart, ystart, xsize, ysize tuple :rtype: list of two float + two int .. py:function:: snap_to_grid(xmin, ymin, xmax, ymax, resolution) Given a roi as xmin, ymin, xmax, ymax, snap values to entire step of resolution :param xmin: xmin of the roi :type xmin: float :param ymin: ymin of the roi :type ymin: float :param xmax: xmax of the roi :type xmax: float :param ymax: ymax of the roi :type ymax: float :param resolution: size of cells for snapping :type resolution: float :return: xmin, ymin, xmax, ymax snapped tuple :rtype: list of four float .. py:function:: 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. :param original_grid_shape: shape of the original grid (almost regular) used to create delaunay triangulation :param tri: Delaunay triangulation :param simplices: Selected simplices to filter: set -1 if selected simplex is on the edges .. py:function:: terrain_grid_to_epipolar(terrain_tiling_grid, epipolar_tiling_grid, epipolar_grid_min, epipolar_grid_max, epsg) Transform terrain grid to epipolar region .. py:function:: region_hash_string(region: Tuple) This lambda will allow to derive a key to index region in the previous dictionary :param region: region to hash .. py:function:: get_corresponding_tiles_row_col(terrain_tiling_grid: numpy.ndarray, row: int, col: int, list_point_clouds: list, list_epipolar_points_min: list, list_epipolar_points_max: list) -> Tuple[List, List, List] This function allows to get required point cloud for each terrain region. :param terrain_tiling_grid: terrain grid positions :param row: row :param 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 :return: Terrain regions Corresponding tiles selected from delayed_point_clouds with associated id Terrain regions "rank" allowing to sorting tiles for dask processing .. py:function:: 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. :param terrain_regions: terrain region respecting cars tiling :param epipolar_regions: corresponding epipolar regions :return: Terrain dictionary and Epipolar dictionary containing respectively Terrain tiles in terrain projection and Epipolar tiles in epipolar projection