Skip to content

Commit

Permalink
Merge branch '210-rename_dichotomy' into 'release'
Browse files Browse the repository at this point in the history
refact: rename dichotomy in dichotomy_python

See merge request 3d/PandoraBox/pandora2d!167
  • Loading branch information
lecontm committed Oct 26, 2024
2 parents 20237a3 + 9934b99 commit 347e73b
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 91 deletions.
2 changes: 1 addition & 1 deletion data_samples/json_conf_files/a_dichotomy_pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"invalid_disparity": "NaN"
},
"refinement": {
"refinement_method": "dichotomy",
"refinement_method": "dichotomy_python",
"iterations": 2,
"filter": { "method": "bicubic"}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/source/exploring_the_field/refining_disparity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ The purpose of this step is to refine the disparity identified in the previous s
So, the refinement step involves transforming a pixel disparity map into a sub-pixel disparity map.


Two methods are available in pandora2d:
Three methods are available in pandora2d:

- Interpolation
- Optical flow
- Dichotomy
- Dichotomy (python version)

.. warning::
The optical flow method is still in an experimental phase.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/userguide/step_by_step/refinement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Configuration and parameters
- Refinement method
- string
-
- "dichotomy"
- "dichotomy_python"
- Yes
* - *iterations*
- Number of iterations
Expand Down
6 changes: 3 additions & 3 deletions notebooks/usage_dichotomy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"source": [
"user_cfg_with_refinement = deepcopy(user_cfg)\n",
"user_cfg_with_refinement[\"pipeline\"][\"refinement\"] = {\n",
" \"refinement_method\": \"dichotomy\",\n",
" \"refinement_method\": \"dichotomy_python\",\n",
" \"iterations\": 1,\n",
" \"filter\": {\"method\": \"bicubic\"},\n",
"}"
Expand All @@ -307,7 +307,7 @@
"source": [
"user_cfg_with_two_refinements = deepcopy(user_cfg)\n",
"user_cfg_with_two_refinements[\"pipeline\"][\"refinement\"] = {\n",
" \"refinement_method\": \"dichotomy\",\n",
" \"refinement_method\": \"dichotomy_python\",\n",
" \"iterations\": 2,\n",
" \"filter\": {\"method\": \"bicubic\"},\n",
"}"
Expand Down Expand Up @@ -570,7 +570,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions pandora2d/refinement/dichotomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Module for Dichotomy refinement method.
Module for Dichotomy refinement method (python version).
"""

import logging
Expand All @@ -34,13 +34,13 @@
COST_SELECTION_METHOD_MAPPING = {"min": np.nanargmin, "max": np.nanargmax}


@refinement.AbstractRefinement.register_subclass("dichotomy")
class Dichotomy(refinement.AbstractRefinement):
"""Subpixel refinement method by dichotomy."""
@refinement.AbstractRefinement.register_subclass("dichotomy_python")
class DichotomyPython(refinement.AbstractRefinement):
"""Subpixel refinement method by dichotomy (python version)."""

NB_MAX_ITER = 9
schema = {
"refinement_method": And(str, lambda x: x in ["dichotomy"]),
"refinement_method": And(str, lambda x: x in ["dichotomy_python"]),
"iterations": And(int, lambda it: it > 0),
"filter": And(dict, lambda x: x["method"] in AbstractFilter.interpolation_filter_methods_avail),
}
Expand Down
26 changes: 13 additions & 13 deletions tests/functional_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ Selecting the best similarity score, for the moment there is only the WTA method
## Refinement
Accurate the disparity to smooth outliers. The algorithms tested here are:

+-----------+-----------------------+
| Algorithm | Description |
+-----------+-----------------------+
| fo | Optical flow |
+-----------+-----------------------+
| dichotomy | Reseach by dichotomy |
+-----------+-----------------------+
| bicubic | Bicubic interpolation |
+-----------+-----------------------+
| sinc | Sinux cardinal |
+-----------+-----------------------+
| spline | Spline |
+-----------+-----------------------+
+-----------+-----------------------------------------+
| Algorithm | Description |
+-----------+-----------------------------------------+
| fo | Optical flow |
+-----------+-----------------------------------------+
| dichotomy_python | Reseach by dichotomy with python |
+-----------+-----------------------------------------+
| bicubic | Bicubic interpolation |
+-----------+-----------------------------------------+
| sinc | Sinux cardinal |
+-----------+-----------------------------------------+
| spline | Spline |
+-----------+-----------------------------------------+

## Validation
A criterion that gives the user additional confidence in the result. The algorithms tested here are:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def correct_pipeline_with_dichotomy():
"pipeline": {
"matching_cost": {"matching_cost_method": "zncc", "window_size": 5},
"disparity": {"disparity_method": "wta", "invalid_disparity": -99},
"refinement": {"refinement_method": "dichotomy", "iterations": 2, "filter": {"method": "bicubic"}},
"refinement": {"refinement_method": "dichotomy_python", "iterations": 2, "filter": {"method": "bicubic"}},
}
}
12 changes: 6 additions & 6 deletions tests/functional_tests/matching_cost/test_disparity_margins.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def config(self, subpix, refinement_config, matching_cost_method):
[
pytest.param(
1,
{"refinement_method": "dichotomy", "iterations": 1, "filter": {"method": "bicubic"}},
{"refinement_method": "dichotomy_python", "iterations": 1, "filter": {"method": "bicubic"}},
(10, 10, 8, 6),
[0, 1, 2, 3, 4, 5],
[-3, -2, -1, 0, 1, 2, 3, 4],
id="Subpix=1 and refinement_method=dichotomy",
id="Subpix=1 and refinement_method=dichotomy_python",
),
pytest.param(
1,
Expand All @@ -124,11 +124,11 @@ def config(self, subpix, refinement_config, matching_cost_method):
),
pytest.param(
2,
{"refinement_method": "dichotomy", "iterations": 1, "filter": {"method": "bicubic"}},
{"refinement_method": "dichotomy_python", "iterations": 1, "filter": {"method": "bicubic"}},
(10, 10, 15, 11),
[0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5],
[-3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4],
id="Subpix=2 and refinement_method=dichotomy",
id="Subpix=2 and refinement_method=dichotomy_python",
),
pytest.param(
2,
Expand All @@ -152,11 +152,11 @@ def config(self, subpix, refinement_config, matching_cost_method):
),
pytest.param(
4,
{"refinement_method": "dichotomy", "iterations": 1, "filter": {"method": "bicubic"}},
{"refinement_method": "dichotomy_python", "iterations": 1, "filter": {"method": "bicubic"}},
(10, 10, 29, 21),
np.arange(0, 5.25, 0.25),
np.arange(-3, 4.25, 0.25),
id="Subpix=4 and refinement_method=dichotomy",
id="Subpix=4 and refinement_method=dichotomy_python",
),
pytest.param(
4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@pytest.fixture()
def make_cfg_for_dichotomy( # pylint: disable=too-many-arguments
def make_cfg_for_dichotomy_python( # pylint: disable=too-many-arguments
left_img_path,
right_img_path,
method,
Expand Down Expand Up @@ -75,7 +75,7 @@ def make_cfg_for_dichotomy( # pylint: disable=too-many-arguments
"invalid_disparity": -9999,
},
"refinement": {
"refinement_method": "dichotomy",
"refinement_method": "dichotomy_python",
"iterations": iterations,
"filter": {"method": method},
},
Expand All @@ -92,7 +92,7 @@ def make_cfg_for_dichotomy( # pylint: disable=too-many-arguments
@pytest.mark.parametrize("roi", [{"col": {"first": 100, "last": 120}, "row": {"first": 100, "last": 120}}])
@pytest.mark.parametrize("col_disparity", [{"init": 0, "range": 1}])
@pytest.mark.parametrize("row_disparity", [{"init": 0, "range": 3}])
def test_dichotomy_execution(make_cfg_for_dichotomy):
def test_dichotomy_execution(make_cfg_for_dichotomy_python):
"""
Description : Test that execution of Pandora2d with a dichotomy refinement does not fail.
Data :
Expand All @@ -104,7 +104,7 @@ def test_dichotomy_execution(make_cfg_for_dichotomy):
"""
pandora2d_machine = Pandora2DMachine()

cfg = check_conf(make_cfg_for_dichotomy, pandora2d_machine)
cfg = check_conf(make_cfg_for_dichotomy_python, pandora2d_machine)

cfg["ROI"]["margins"] = pandora2d_machine.margins_img.global_margins.astuple()
roi = get_roi_processing(cfg["ROI"], cfg["input"]["col_disparity"], cfg["input"]["row_disparity"])
Expand All @@ -131,7 +131,7 @@ def test_dichotomy_execution(make_cfg_for_dichotomy):
# this type of disparity will also need to be tested here.
@pytest.mark.parametrize("col_disparity", [{"init": -1, "range": 1}])
@pytest.mark.parametrize("row_disparity", [{"init": 0, "range": 1}])
def test_extrema_disparities_not_processed(make_cfg_for_dichotomy):
def test_extrema_disparities_not_processed(make_cfg_for_dichotomy_python):
"""
Description : Test that execution of Pandora2d with a dichotomy refinement does not
take into account points for which best cost value is found at the edge of the disparity range.
Expand All @@ -141,7 +141,7 @@ def test_extrema_disparities_not_processed(make_cfg_for_dichotomy):
"""
pandora2d_machine = pandora2d.state_machine.Pandora2DMachine()

cfg = check_conf(make_cfg_for_dichotomy, pandora2d_machine)
cfg = check_conf(make_cfg_for_dichotomy_python, pandora2d_machine)

cfg["ROI"]["margins"] = pandora2d_machine.margins_img.global_margins.astuple()
roi = get_roi_processing(cfg["ROI"], cfg["input"]["col_disparity"], cfg["input"]["row_disparity"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ def cfg_dichotomy(self, shift_path, subpix, filter_method):
"spline_order": 3,
}, # we use spline_order=3 to get better results when subpix is different from 1
"disparity": {"disparity_method": "wta", "invalid_disparity": np.nan},
"refinement": {"refinement_method": "dichotomy", "iterations": 9, "filter": {"method": filter_method}},
"refinement": {
"refinement_method": "dichotomy_python",
"iterations": 9,
"filter": {"method": filter_method},
},
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/resource_tests/test_pandora2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def dichotomy_pipeline(self, matching_cost_method, subpix, iterations, filter_me
"matching_cost": {"matching_cost_method": matching_cost_method, "subpix": subpix},
"disparity": {"disparity_method": "wta", "invalid_disparity": -99},
"refinement": {
"refinement_method": "dichotomy",
"refinement_method": "dichotomy_python",
"iterations": iterations,
"filter": {"method": filter_method},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_pandora2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_run_prepare(left_img_path, right_img_path) -> None:
[
pytest.param({"refinement_method": "interpolation"}, Margins(3, 3, 3, 3), id="interpolation"),
pytest.param(
{"refinement_method": "dichotomy", "iterations": 3, "filter": {"method": "bicubic"}},
{"refinement_method": "dichotomy_python", "iterations": 3, "filter": {"method": "bicubic"}},
Margins(1, 1, 2, 2),
id="dichotomy with bicubic filter",
),
Expand Down
Loading

0 comments on commit 347e73b

Please sign in to comment.