pandora2d.img_tools
This module contains functions associated to raster images.
Classes
NamedTuple to store left and right datasets. |
Functions
|
Read image and return the corresponding xarray.DataSet |
|
Do various check against disparities properties. |
|
Check that disparity keys are not missing from input_config. |
|
Check that disparity a dictionary with keys "init" and range" |
|
Add disparity to dataset |
Transforms input disparity dicts with constant init into min/max disparity grids |
|
|
Return a Dataset that contains the shifted right images |
|
Generate the values of margins |
|
Return a roi which takes disparities into account. |
|
Remove ROI margins before saving output dataset |
|
Return a list that contains the shifted right images in row |
|
Return a list that contains the shifted right images in col |
|
Return an array that contains the shifted right images |
|
Return an array that contains the shifted right images in rows and columns |
|
Return initial disparity. |
|
Returns [min, max] disparity |
|
If no_data is NaN or Inf, return -9999. |
Module Contents
- class pandora2d.img_tools.Datasets[source]
Bases:
NamedTupleNamedTuple to store left and right datasets.
- pandora2d.img_tools.create_datasets_from_inputs(input_config: dict, roi: dict = None, estimation_cfg: dict = None, attributes: dict = None) Datasets[source]
Read image and return the corresponding xarray.DataSet
- Parameters:
input_config – configuration used to create dataset.
roi –
dictionary with a roi
”col”: {“first”: <value - int>, “last”: <value - int>}, “row”: {“first”: <value - int>, “last”: <value - int>}, “margins”: [<value - int>, <value - int>, <value - int>, <value - int>]
with margins : left, up, right, down
estimation_cfg – dictionary containing estimation configuration
attributes – dictionary with attribute parameters
- Returns:
Datasets NamedTuple with two attributes left and right each containing a xarray.DataSet containing the variables :
im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
col_disparity: 3D (disp, row, col) xarray.DataArray float32
row_disparity: 3D (disp, row, col) xarray.DataArray float32
- pandora2d.img_tools.check_disparities(input_config: dict) None[source]
Do various check against disparities properties.
- Parameters:
input_config – configuration used to create dataset.
- Raises:
SystemExit – If any check fails.
- pandora2d.img_tools.check_disparity_presence(input_config: dict) None[source]
Check that disparity keys are not missing from input_config.
- Parameters:
input_config – configuration used to create dataset.
- Raises:
SystemExit – if one or both keys are missing
- pandora2d.img_tools.check_disparity_types(disparity: Any) None[source]
Check that disparity a dictionary with keys “init” and range” where “init” is either:
an integer
a path to a grid with integer values
- Parameters:
disparity – disparity to check
- Raises:
SystemExit – if it does not meet requirements
- pandora2d.img_tools.add_disparity_grid(dataset: xarray.Dataset, col_disparity: dict, row_disparity: dict, attributes: dict = None, right: bool = False) xarray.Dataset[source]
Add disparity to dataset
- Parameters:
dataset – xarray dataset
col_disparity – Disparity interval for columns
row_disparity – Disparity interval for rows
attributes – dictionary with attribute parameters
right – indicates whether the disparity grid is added to the right dataset
- Returns:
dataset : updated dataset
- pandora2d.img_tools.get_min_max_disp_from_dicts(dataset: xarray.Dataset, disparity: dict, origin: pandora2d.types.Origin, step: pandora2d.types.Step, user_invalid_disp: int | float, right: bool = False) tuple[numpy.typing.NDArray, list, float | None][source]
Transforms input disparity dicts with constant init into min/max disparity grids
- Parameters:
dataset – xarray dataset
disparity – input disparity
origin – origin of the grid
step – step that separates two points in the disparity grid
user_invalid_disp – user invalid disparity value
right – indicates whether the disparity grid is added to the right dataset
- Returns:
3D numpy array containing min/max disparity grids and list with disparity source
- pandora2d.img_tools.shift_disp_row_img(img_right: xarray.Dataset, dec_row: int) xarray.Dataset[source]
Return a Dataset that contains the shifted right images
- Parameters:
img_right – right Dataset image containing : - im : 2D (row, col) xarray.Datasat
dec_row – the value of shifting for dispy
- Returns:
img_right_shift: Dataset containing the shifted image
- pandora2d.img_tools.get_margins_values(init_value: int | numpy.ndarray, range_value: int, margins: list) tuple[int, int][source]
Generate the values of margins
- Parameters:
init_value – init value for disparity interval
range_value – range value for disparity interval
margins – necessary value for margins
- Returns:
Margins value
- pandora2d.img_tools.get_roi_processing(roi: dict, col_disparity: dict, row_disparity: dict) dict[source]
Return a roi which takes disparities into account. Update cfg roi with new margins.
- Parameters:
roi –
roi in config file
”col”: {“first”: <value - int>, “last”: <value - int>}, “row”: {“first”: <value - int>, “last”: <value - int>}, “margins”: [<value - int>, <value - int>, <value - int>, <value - int>] with margins : left, up, right, down
col_disparity – init and range for disparities in columns.
row_disparity – init and range for disparities in rows.
- pandora2d.img_tools.remove_roi_margins(dataset: xarray.Dataset, cfg: dict)[source]
Remove ROI margins before saving output dataset
- Parameters:
dataset – dataset containing disparity row and col maps
cfg – output configuration of the pandora2d machine
- pandora2d.img_tools.row_zoom_img(img: numpy.ndarray, ny: int, subpix: int, coords: xarray.Coordinates, ind: int, no_data: float | int, order: int = 1) xarray.Dataset[source]
Return a list that contains the shifted right images in row
This method is temporary, the user can then choose the filter for this function
- Parameters:
img – image to shift
ny – row number in data
subpix – subpixel precision = (1 or pair number)
coords – coordinates for output datasets
ind – index of range(subpix)
no_data – no_data value in img
order – The order of the spline interpolation, default is 1. The order has to be in the range 0-5.
- Returns:
an array that contains the shifted right images in row
- pandora2d.img_tools.col_zoom_img(img: numpy.ndarray, nx: int, subpix: int, coords: xarray.Coordinates, ind: int, no_data: float | int, order: int = 1) xarray.Dataset[source]
Return a list that contains the shifted right images in col
This method is temporary, the user can then choose the filter for this function
- Parameters:
img – image to shift
nx – col number in data
subpix – subpixel precision = (1 or pair number)
coords – coordinates for output datasets
ind – index of range(subpix)
no_data – no_data value in img
order – The order of the spline interpolation, default is 1. The order has to be in the range 0-5.
- Returns:
an array that contains the shifted right images in col
- pandora2d.img_tools.shift_subpix_img(img_right: xarray.Dataset, subpix: int, row: bool = True, order: int = 1) list[xarray.Dataset][source]
Return an array that contains the shifted right images
- Parameters:
img_right – Dataset image containing the image im : 2D (row, col) xarray.Dataset
subpix – subpixel precision = (1 or pair number)
row – row to shift (otherwise column)
order – The order of the spline interpolation, default is 1. The order has to be in the range 0-5.
- Returns:
an array that contains the shifted right images
- pandora2d.img_tools.shift_subpix_img_2d(img_right: xarray.Dataset, subpix: int, order: int = 1) list[xarray.Dataset][source]
Return an array that contains the shifted right images in rows and columns
- Parameters:
img_right – Dataset image containing the image im : 2D (row, col) xarray.Dataset
subpix – subpixel precision = (1 or pair number)
column – column to shift (otherwise row)
order – The order of the spline interpolation, default is 1. The order has to be in the range 0-5.
- Returns:
an array that contains the shifted right images
- pandora2d.img_tools.get_initial_disparity(disparity: dict) numpy.typing.NDArray | int[source]
Return initial disparity.
When initial disparity is read from a file, nodata and infinite values are replaced by NaNs.
- Parameters:
disparity – init and range for disparities in columns.
- Returns:
initial disparity