Skip to content

Commit

Permalink
Merge branch '96-fix-interpolation-error-message' into 'release'
Browse files Browse the repository at this point in the history
Resolve "Fix error message when interpolation with disparity range <5"

See merge request 3d/PandoraBox/pandora2d!77
  • Loading branch information
lecontm committed Mar 21, 2024
2 parents 4b9d987 + 80de601 commit 5783695
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/source/userguide/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Input section is composed of the following keys:
-
- If the estimation step is not present

.. warning::
If interpolation is used as refinement method, row_disparity and col_disparity ranges must have a size greater than or equal to 5.


Left and Right properties are composed of the following keys:

.. list-table:: Left and Right properties
Expand Down
3 changes: 3 additions & 0 deletions docs/source/userguide/step_by_step/refinement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ It consists on 3 different steps:
* The cost map of each pixel is interpolated using scipy to obtain a continuous function.
* Then, the interpolated functions are minimized using scipy to obtain the refined disparities.

.. warning::
When using the interpolation method, row and column disparity ranges must have a size greater than or equal to 5.

Optical_flow method
-------------------
.. warning::
Expand Down
32 changes: 31 additions & 1 deletion pandora2d/check_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
This module contains functions allowing to check the configuration given to Pandora pipeline.
"""

from __future__ import annotations

from typing import Dict

import numpy as np
Expand Down Expand Up @@ -86,7 +88,7 @@ def check_input_section(user_cfg: Dict[str, dict], estimation_config: dict = Non
check_disparities_from_input(cfg["input"]["row_disparity"], None)
else:
# add wrong disparity for checking only
cfg = update_conf(default_configuration_disp, user_cfg)
cfg = update_conf(default_configuration_disp, cfg)

# check schema
configuration_schema = {"input": input_configuration_schema}
Expand Down Expand Up @@ -183,6 +185,14 @@ def check_conf(user_cfg: Dict, pandora2d_machine: Pandora2DMachine) -> dict:
if "matching_cost" in cfg_pipeline["pipeline"]:
check_right_nodata_condition(cfg_input, cfg_pipeline)

# The refinement step with interpolation method is not allowed with disparity ranges of size lower than 5
if (
"refinement" in cfg_pipeline["pipeline"]
and cfg_pipeline["pipeline"]["refinement"]["refinement_method"] == "interpolation"
):
check_disparity_range_size(cfg_input["input"]["col_disparity"], "Column")
check_disparity_range_size(cfg_input["input"]["row_disparity"], "Row")

cfg = concat_conf([cfg_input, cfg_roi, cfg_pipeline])

return cfg
Expand All @@ -205,6 +215,26 @@ def check_right_nodata_condition(cfg_input: Dict, cfg_pipeline: Dict) -> None:
)


def check_disparity_range_size(disparity: list[int] | str, title: str) -> None:
"""
Check that disparity ranges with a size < 5 are not allowed for interpolation refinement method.
:param disparity: disparity range
:type disparity: list[int] | str
:param cfg_pipeline: pipeline section of configuration
:type cfg_pipeline: Dict
"""

if isinstance(disparity, list):
if (abs(disparity[1] - disparity[0]) + 1) < 5:
raise ValueError(
title + " disparity range with a size < 5 are not allowed with interpolation refinement method"
)

if isinstance(disparity, str):
raise TypeError("Grid disparities are not yet handled by Pandora2D")


def check_roi_coherence(roi_cfg: dict) -> None:
"""
Check that the first ROI coords are lower than the last.
Expand Down
55 changes: 55 additions & 0 deletions tests/unit_tests/test_check_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Test configuration
"""


import pytest
import transitions
import numpy as np
Expand Down Expand Up @@ -260,3 +261,57 @@ def test_zncc_fails_with(self, pandora2d_machine, configuration):
"""Right nodata must can not be float or nan with zncc matching_cost_method."""
with pytest.raises((ValueError, DictCheckerError)):
check_configuration.check_conf(configuration, pandora2d_machine)


class TestCheckDisparityRangeSize:
"""Test check_disparity_range_size method."""

@pytest.mark.parametrize(
["disparity", "title", "string_match"],
[
pytest.param(
[-1, 1],
"Column",
"Column disparity range with a size < 5 are not allowed with interpolation refinement method",
id="Column disparity range < 5",
),
pytest.param(
[-3, -1],
"Row",
"Row disparity range with a size < 5 are not allowed with interpolation refinement method",
id="Row disparity range < 5",
),
],
)
def test_fails_with_disparity_ranges_lower_5(self, disparity, title, string_match):
"""Disparity range size must be greater than or equal to 5 when interpolation is used as refinement method"""
with pytest.raises(ValueError, match=string_match):
check_configuration.check_disparity_range_size(disparity, title)

@pytest.mark.parametrize(
["disparity", "title", "string_match"],
[
pytest.param(
"disparity_grid_test",
"Column",
"Grid disparities are not yet handled by Pandora2D",
id="Grid disparity",
),
],
)
def test_fails_with_grid_disparity(self, disparity, title, string_match):
"""Disparity grid is not handled yet by Pandora2D"""
with pytest.raises(TypeError, match=string_match):
check_configuration.check_disparity_range_size(disparity, title)

@pytest.mark.parametrize(
["disparity", "title"],
[
pytest.param([-2, 2], "Col", id="Column disparity range greater than or equal to 5"),
pytest.param([1, 5], "Row", id="Row disparity range greater than or equal to 5"),
],
)
def test_passes_with_disparity_ranges_equal_5(self, disparity, title):
"""Disparity range size is correct"""

check_configuration.check_disparity_range_size(disparity, title)

0 comments on commit 5783695

Please sign in to comment.