Skip to content

Commit

Permalink
Merge branch '70-dichotomie-ajout-des-marges' into 'release'
Browse files Browse the repository at this point in the history
feat: add dichotomy module in refinement package

See merge request 3d/PandoraBox/pandora2d!72
  • Loading branch information
lecontm committed Feb 9, 2024
2 parents 4e2739e + 5e9cde1 commit aff8399
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pandora2d/refinement/dichotomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import xarray as xr

from json_checker import And

from pandora.margins import Margins
from . import refinement


Expand Down Expand Up @@ -60,6 +62,10 @@ def check_conf(cls, cfg: Dict) -> Dict:
cfg["iterations"] = cls.NB_MAX_ITER
return cfg

@property
def margins(self):
return Margins(2, 2, 2, 2)

def refinement_method(self, cost_volumes: xr.Dataset, pixel_maps: xr.Dataset) -> None:
"""
Return the subpixel disparity maps
Expand Down
13 changes: 13 additions & 0 deletions tests/test_dichotomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytest
import json_checker

from pandora.margins import Margins
from pytest_mock import MockerFixture

from pandora2d import refinement
Expand Down Expand Up @@ -122,3 +123,15 @@ def test_refinement_method(config, caplog, mocker: MockerFixture):
dichotomy_instance.refinement_method(mocker.ANY, mocker.ANY)

assert "refinement_method of Dichotomy not yet implemented" in caplog.messages


def test_margins():
"""
Test margins of Dichotomy.
"""

config = {"refinement_method": "dichotomy", "iterations": 2, "filter": "sinc"}

dichotomy_instance = refinement.dichotomy.Dichotomy(config)

assert dichotomy_instance.margins == Margins(2, 2, 2, 2)
25 changes: 21 additions & 4 deletions tests/test_pandora2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,32 @@ def test_run_prepare() -> None:
pandora2d_machine.disp_max_row, np.full((img_left.sizes["row"], img_left.sizes["col"]), 2)
)

@staticmethod
def test_global_margins() -> None:
@pytest.mark.parametrize(
["refinement_config", "expected"],
[
pytest.param({"refinement_method": "interpolation"}, Margins(3, 3, 3, 3), id="interpolation"),
pytest.param(
{"refinement_method": "dichotomy", "iterations": 3, "filter": "sinc"},
Margins(2, 2, 2, 2),
id="dichotomy with sinc filter",
),
],
)
def test_global_margins(self, refinement_config, expected) -> None:
"""
Test computed global margins is as expected.
"""

pipeline_cfg = {
"pipeline": {
"matching_cost": {"matching_cost_method": "zncc", "window_size": 5},
"disparity": {"disparity_method": "wta", "invalid_disparity": -99},
"refinement": refinement_config,
},
}

pandora2d_machine = state_machine.Pandora2DMachine()

pipeline_cfg = copy.deepcopy(common.correct_pipeline)
pandora2d_machine.check_conf(pipeline_cfg)

assert pandora2d_machine.margins.global_margins == Margins(3, 3, 3, 3)
assert pandora2d_machine.margins.global_margins == expected

0 comments on commit aff8399

Please sign in to comment.