Skip to content

Commit

Permalink
Merge branch '331-disparity-in-dataset' into 'release_branch_1_6_0'
Browse files Browse the repository at this point in the history
Resolve "check_dataset : Stockage des disparités dans le dataset"

See merge request 3d/PandoraBox/pandora!295
  • Loading branch information
lecontm committed Oct 18, 2023
2 parents e17e8c0 + 7172397 commit 250ffeb
Show file tree
Hide file tree
Showing 33 changed files with 1,098 additions and 610 deletions.
17 changes: 12 additions & 5 deletions docs/source/userguide/as_an_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,28 @@ Example of a monoband image dataset

::

Dimensions: (col: 450, row: 375)
Dimensions: (col: 450, row: 375)
Coordinates:
* col (col) int64 0 1 2 3 4 5 6 7 8 ... 442 443 444 445 446 447 448 449
* row (row) int64 0 1 2 3 4 5 6 7 8 ... 367 368 369 370 371 372 373 374
* col (col) int64 0 1 2 3 4 5 6 7 8 ... 442 443 444 445 446 447 448 449
* row (row) int64 0 1 2 3 4 5 6 7 8 ... 367 368 369 370 371 372 373 374
* band_disp (band_disp) <U3 'min' 'max'
Data variables:
im (row, col) float32 88.0 85.0 84.0 83.0 ... 176.0 180.0 165.0 172.0
msk (row, col) int16 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
im (row, col) float32 88.0 85.0 84.0 83.0 ... 176.0 180.0 165.0 172.0
msk (row, col) int16 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0
disparity (band_disp, row, col) int16 -60.0 -60.0 -60.0 -60.0 -60.0 -60.0 ... -60.0 -60.0 -60.0 -60.0 -60.0
Attributes:
no_data_img: 0
crs: None
transform: | 1.00, 0.00, 0.00|\n| 0.00, 1.00, 0.00|\n| 0.00, 0.00, 1.00|
valid_pixels: 0
no_data_mask: 1
disparity_source <disparity in config file>

Two data variables are created in this dataset:

* *im*: contains input image data
* *msk*: contains input mask data + no_data of input image
* *disparity*: contains input disparity data with two bands (min and max)

Example of a multiband image dataset

Expand All @@ -113,13 +117,16 @@ Example of a multiband image dataset
* band_im (band_im) <U1 'r' 'g'
* row (row) int64 0 1 2 3 4
* col (col) int64 0 1 2 3 4 5
* band_disp (band_disp) <U3 'min' 'max'
Data variables:
im (band_im, row, col) float64 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
disparity (band_disp, row, col) int16 -60.0 -60.0 -60.0 -60.0 -60.0 -60.0 ... -60.0 -60.0 -60.0 -60.0 -60.0
Attributes:
valid_pixels: 0
no_data_mask: 1
crs: None
transform: | 1.00, 0.00, 0.00|\n| 0.00, 1.00, 0.00|\n| 0.00, 0.00, 1.00|
disparity_source <disparity in config file>


.. note::
Expand Down
2 changes: 1 addition & 1 deletion notebooks/advanced_examples/cost_profile_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"metadata": {},
"outputs": [],
"source": [
"pandora_machine.run_prepare(user_cfg, img_left, img_right, disp_min, disp_max)"
"pandora_machine.run_prepare(user_cfg, img_left, img_right)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions notebooks/introduction_and_basic_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
"metadata": {},
"outputs": [],
"source": [
"left_disparity, right_disparity = pandora.run(pandora_machine, img_left, img_right, disp_min, disp_max, user_cfg)"
"left_disparity, right_disparity = pandora.run(pandora_machine, img_left, img_right, user_cfg)"
]
},
{
Expand Down Expand Up @@ -678,7 +678,7 @@
"metadata": {},
"outputs": [],
"source": [
"pandora_machine.run_prepare(user_cfg, img_left, img_right, disp_min, disp_max)"
"pandora_machine.run_prepare(user_cfg, img_left, img_right)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/statistical_and_visual_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
"metadata": {},
"outputs": [],
"source": [
"left_disp_zncc, right_disp_zncc = pandora.run(pandora_machine, img_left, img_right, disp_min, disp_max, user_cfg_zncc)"
"left_disp_zncc, right_disp_zncc = pandora.run(pandora_machine, img_left, img_right, user_cfg_zncc)"
]
},
{
Expand Down Expand Up @@ -537,7 +537,7 @@
"metadata": {},
"outputs": [],
"source": [
"pandora_machine.run_prepare(user_cfg_census, img_left, img_right, disp_min, disp_max)"
"pandora_machine.run_prepare(user_cfg_census, img_left, img_right)"
]
},
{
Expand Down Expand Up @@ -822,7 +822,7 @@
"metadata": {},
"outputs": [],
"source": [
"pandora_machine.run_prepare(user_cfg_census, img_left, img_right, disp_min, disp_max)"
"pandora_machine.run_prepare(user_cfg_census, img_left, img_right)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/usage_with_multiscale.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
"metadata": {},
"outputs": [],
"source": [
"pandora_machine.run_prepare(user_cfg, img_left, img_right, disp_min, disp_max, scale_factor, num_scales)"
"pandora_machine.run_prepare(user_cfg, img_left, img_right, scale_factor, num_scales)"
]
},
{
Expand All @@ -503,7 +503,7 @@
"metadata": {},
"outputs": [],
"source": [
"left_disparity, right_disparity = pandora.run(pandora_machine, img_left, img_right, disp_min, disp_max, user_cfg)"
"left_disparity, right_disparity = pandora.run(pandora_machine, img_left, img_right, user_cfg)"
]
},
{
Expand Down Expand Up @@ -703,7 +703,7 @@
"metadata": {},
"outputs": [],
"source": [
"pandora_machine.run_prepare(user_cfg, img_left, img_right, disp_min, disp_max, scale_factor, num_scales)"
"pandora_machine.run_prepare(user_cfg, img_left, img_right, scale_factor, num_scales)"
]
},
{
Expand Down
66 changes: 22 additions & 44 deletions pandora/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pkg_resources import iter_entry_points

from . import common
from .img_tools import create_dataset_from_inputs, read_disp
from .img_tools import create_dataset_from_inputs
from .check_configuration import check_conf, read_config_file, read_multiscale_params
from .state_machine import PandoraMachine

Expand All @@ -44,11 +44,7 @@ def run(
pandora_machine: PandoraMachine,
img_left: xr.Dataset,
img_right: xr.Dataset,
disp_min: Union[np.ndarray, int],
disp_max: Union[np.ndarray, int],
cfg: Dict[str, dict],
disp_min_right: Union[None, np.ndarray] = None,
disp_max_right: Union[None, np.ndarray] = None,
) -> Tuple[xr.Dataset, xr.Dataset]:
"""
Run the pandora pipeline
Expand All @@ -57,24 +53,22 @@ def run(
:type pandora_machine: PandoraMachine
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_right: xarray.Dataset
:param disp_min: minimal disparity
:type disp_min: int or np.ndarray
:param disp_max: maximal disparity
:type disp_max: int or np.ndarray
:param cfg: pipeline configuration
:type cfg: Dict[str, dict]
:param disp_min_right: minimal disparity of the right image
:type disp_min_right: np.ndarray or None
:param disp_max_right: maximal disparity of the right image
:type disp_max_right: np.ndarray or None
:return: Two xarray.Dataset :
Expand All @@ -83,13 +77,17 @@ def run(
- confidence_measure : the confidence measure in the geometry of the left image 3D DataArray \
(row, col, indicator)
- validity_mask : the validity mask in the geometry of the left image 2D DataArray (row, col)
- classif_mask : information about a classification
- segm_mask : information about a segmentation
- right : the right dataset. If there is no validation step, the right Dataset will be empty.If a \
validation step is configured, the dataset will contain the variables :
- disparity_map : the disparity map in the geometry of the right image 2D DataArray (row, col)
- confidence_measure : the confidence measure in the geometry of the left image 3D DataArray \
(row, col, indicator)
- validity_mask : the validity mask in the geometry of the left image 2D DataArray (row, col)
- classif_mask : information about a classification
- segm_mask : information about a segmentation
:rtype: tuple (xarray.Dataset, xarray.Dataset)
"""
Expand All @@ -98,21 +96,11 @@ def run(
num_scales, scale_factor = read_multiscale_params(cfg)

# Prepare the machine before running, including the image pyramid creation
pandora_machine.run_prepare(
cfg,
img_left,
img_right,
disp_min,
disp_max,
scale_factor,
num_scales,
disp_min_right,
disp_max_right,
)
pandora_machine.run_prepare(cfg, img_left, img_right, scale_factor, num_scales)

# For each scale we run the whole pipeline, the scales will be executed from coarse to fine,
# and the machine will store the necessary parameters for the following scale
for scale in range(pandora_machine.num_scales): # pylint:disable=unused-variable
for _ in range(pandora_machine.num_scales):
# Trigger the machine step by step
for elem in list(cfg["pipeline"]):
pandora_machine.run(elem, cfg)
Expand Down Expand Up @@ -179,24 +167,14 @@ def main(cfg_path: PathLike | str, output: str, verbose: bool) -> None:
# Read images and masks
input_config = common.split_inputs(cfg["input"])
img_left = create_dataset_from_inputs(input_config=input_config["left"])
# If input_config["right"]["disp"] is None then "disp_right_min" = - "disp_left_max"
# and "disp_right_max" = - "disp_left_min"
if input_config["right"]["disp"] is None and not isinstance(input_config["left"]["disp"], str):
input_config["right"]["disp"] = [-input_config["left"]["disp"][1], -input_config["left"]["disp"][0]]
img_right = create_dataset_from_inputs(input_config=input_config["right"])

# Read range of disparities
disp_min, disp_max = read_disp(cfg["input"]["disp_left"])
disp_right = cfg["input"]["disp_right"]
disp_min_right, disp_max_right = (None, None) if disp_right is None else read_disp(disp_right)

# Run the Pandora pipeline
left, right = run(
pandora_machine,
img_left,
img_right,
disp_min,
disp_max,
cfg,
disp_min_right, # type: ignore
disp_max_right, # type: ignore
)
left, right = run(pandora_machine, img_left, img_right, cfg)

# Save the left and right DataArray in tiff files
common.save_results(left, right, output)
Expand Down
15 changes: 10 additions & 5 deletions pandora/aggregation/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ def cost_volume_aggregation(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
:type img_left: xarray.Dataset
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_right: xarray.Dataset
:param cv: the cost volume dataset with the data variables:
Expand Down
28 changes: 20 additions & 8 deletions pandora/aggregation/cbca.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,19 @@ def cost_volume_aggregation(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_right: xarray.Dataset
:param cv: cost volume dataset with the data variables:
Expand Down Expand Up @@ -196,13 +202,19 @@ def computes_cross_supports(
:param img_left: left Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_left: xarray.Dataset
:param img_right: right Dataset image containing :
- im : 2D (row, col) or 3D (band_im, row, col) xarray.DataArray
- msk (optional): 2D (row, col) xarray.DataArray
- im: 2D (row, col) or 3D (band_im, row, col) xarray.DataArray float32
- disparity (optional): 3D (disp, row, col) xarray.DataArray float32
- msk (optional): 2D (row, col) xarray.DataArray int16
- classif (optional): 3D (band_classif, row, col) xarray.DataArray int16
- segm (optional): 2D (row, col) xarray.DataArray int16
:type img_right: xarray.Dataset
:param cv: cost volume dataset with the data variables:
Expand Down
Loading

0 comments on commit 250ffeb

Please sign in to comment.