Skip to content

Commit

Permalink
Merge branch 'release_branch_1_5_0' into 'master'
Browse files Browse the repository at this point in the history
Release branch 1 5 0

Closes #88

See merge request 3d/PandoraBox/pandora_plugins/plugin_libsgm!120
  • Loading branch information
lecontm committed Nov 8, 2023
2 parents f24f0cf + 1e8adf5 commit b570be0
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 447 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.5.0a1 (Novembre 2023)

### Changed
- Adding check for geometric_prior option in check_conf function. [#88]
- New format for disparity in the user configuration file. [#87]
- Change read_img function to create_dataset_from_inputs. [#83]
- Update with new API of Pandora run and compute_cost_volume function. [#94]


## 1.4.0 (April 2023)

### Added
Expand Down
20 changes: 17 additions & 3 deletions pandora_plugin_libsgm/abstract_sgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ class AbstractSGM(optimization.AbstractOptimization):
_DIRECTIONS = [[0, 1], [1, 0], [1, 1], [1, -1], [0, -1], [-1, 0], [-1, -1], [-1, 1]]
_USE_CONFIDENCE = False

def __init__(self, **cfg: Union[str, int, float, bool, dict]):
def __init__(self, img: xr.Dataset, **cfg: Union[str, int, float, bool, dict]):
"""
:param img: xarray.Dataset of image with metadata
:type img: xarray.Dataset
:param cfg: optional configuration, {'P1': value, 'P2': value, 'alpha': value, 'beta': value, 'gamma': value,
'p2_method': value}
:type cfg: dict
"""
self.cfg = self.check_conf(**cfg)
self.cfg = self.check_conf(img, **cfg)
self._sgm_version = self.cfg["sgm_version"]
self._overcounting = self.cfg["overcounting"]
self._min_cost_paths = self.cfg["min_cost_paths"]
Expand All @@ -78,10 +80,14 @@ def desc(self):
Describes the optimization method
"""

def check_conf(self, **cfg: Union[str, int, float, bool, dict]) -> Dict[str, Union[str, int, float, bool, dict]]:
def check_conf(
self, img: xr.Dataset, **cfg: Union[str, int, float, bool, dict]
) -> Dict[str, Union[str, int, float, bool, dict]]:
"""
Add default values to the dictionary if there are missing elements and check if the dictionary is correct
:param img: xarray.Dataset of image with metadata
:type img: xarray.Dataset
:param cfg: optimization configuration
:type cfg: dict
:return cfg: optimization configuration updated
Expand All @@ -101,6 +107,14 @@ def check_conf(self, **cfg: Union[str, int, float, bool, dict]) -> Dict[str, Uni
if cfg["optimization_method"] == "sgm" and "geometric_prior" in cfg:
logging.error("Geometric prior not available for SGM optimization")
sys.exit(1)

if "geometric_prior" in cfg:
source = cfg["geometric_prior"]["source"]
if source in ["classif", "segm"] and not source in img.data_vars:
logging.error(
"For performing the 3SGM optimization step in the pipeline, left %s must be present.", source
)
sys.exit(1)

schema = {
"sgm_version": And(str, lambda x: is_method(x, ["c++", "python_libsgm", "python_libsgm_parall"])),
Expand Down
6 changes: 4 additions & 2 deletions pandora_plugin_libsgm/lib_3sgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ class SEGSEMSGM(abstract_sgm.AbstractSGM):
_GEOMETRIC_PRIOR = {"source": "internal"}
_AVAILABLE_GEOMETRIC_PRIOR = ["internal", "classif", "segm"]

def __init__(self, **cfg: Union[str, int, float, bool]):
def __init__(self, img: xr.Dataset, **cfg: Union[str, int, float, bool]):
"""
:param img: xarray.Dataset of image with metadata
:type img: xarray.Dataset
:param cfg: optional configuration, {}
:type cfg: dict
:return: None
"""
super().__init__(**cfg)
super().__init__(img, **cfg)
self.cfg = self.check_geometric_prior(cfg)
self._geometric_prior = self.cfg["geometric_prior"]
if self._geometric_prior["source"] == "classif": # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_requires =
numpy
rasterio
libsgm==0.4.*
pandora>=1.5.0
pandora==1.6.0a1
xarray
json-checker

Expand Down
78 changes: 42 additions & 36 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,80 +45,86 @@ def configurations_path(resource_path_root):
@pytest.fixture()
def left_cones(inputs_path):
"""Cones images."""
path = inputs_path / "left.png"
return pandora.read_img(str(path), no_data=np.nan, mask=None)
return pandora.create_dataset_from_inputs(
{"img": str(inputs_path / "left.png"), "nodata": np.nan, "mask": None, "disp": [-60, 0]}
)


@pytest.fixture()
def right_cones(inputs_path):
"""Cones images."""
path = inputs_path / "right.png"
return pandora.read_img(str(path), no_data=np.nan, mask=None)
return pandora.create_dataset_from_inputs(
{"img": str(inputs_path / "right.png"), "nodata": np.nan, "mask": None, "disp": [0, 60]}
)


@pytest.fixture()
def left_rgb(inputs_path):
"""Cones images."""
path = inputs_path / "left_rgb.tif"
return pandora.read_img(str(path), no_data=np.nan, mask=None)
return pandora.create_dataset_from_inputs(
{"img": str(inputs_path / "left_rgb.tif"), "nodata": np.nan, "mask": None, "disp": [-60, 0]}
)


@pytest.fixture()
def right_rgb(inputs_path):
"""Cones images."""
path = inputs_path / "right_rgb.tif"
return pandora.read_img(str(path), no_data=np.nan, mask=None)
return pandora.create_dataset_from_inputs(
{"img": str(inputs_path / "right_rgb.tif"), "nodata": np.nan, "mask": None}
)


@pytest.fixture()
def left_cones_classif(inputs_path):
"""Cones images with classification."""
path = inputs_path / "left.png"
classif_path = inputs_path / "left_classif.tif"
return pandora.read_img(
str(path),
no_data=np.nan,
mask=None,
classif=str(classif_path),
return pandora.create_dataset_from_inputs(
{
"img": str(inputs_path / "left.png"),
"nodata": np.nan,
"mask": None,
"classif": str(inputs_path / "left_classif.tif"),
"disp": [-60, 0],
}
)


@pytest.fixture()
def right_cones_classif(inputs_path):
"""Cones images with classification."""
path = inputs_path / "right.png"
classif_path = inputs_path / "right_classif.tif"
return pandora.read_img(
str(path),
no_data=np.nan,
mask=None,
classif=str(classif_path),
return pandora.create_dataset_from_inputs(
{
"img": str(inputs_path / "right.png"),
"nodata": np.nan,
"mask": None,
"classif": str(inputs_path / "right_classif.tif"),
}
)


@pytest.fixture()
def left_cones_segm(inputs_path):
"""Cones images with segmentation."""
path = inputs_path / "left.png"
segment_path = inputs_path / "left_classif.tif"
return pandora.read_img(
str(path),
no_data=np.nan,
mask=None,
segm=str(segment_path),
return pandora.create_dataset_from_inputs(
{
"img": str(inputs_path / "left.png"),
"nodata": np.nan,
"mask": None,
"segm": str(inputs_path / "left_classif.tif"),
"disp": [-60, 0],
}
)


@pytest.fixture()
def right_cones_segm(inputs_path):
"""Cones images with segmentation."""
path = inputs_path / "right.png"
segment_path = inputs_path / "right_classif.tif"
return pandora.read_img(
str(path),
no_data=np.nan,
mask=None,
segm=str(segment_path),
return pandora.create_dataset_from_inputs(
{
"img": str(inputs_path / "right.png"),
"nodata": np.nan,
"mask": None,
"segm": str(inputs_path / "right_classif.tif"),
}
)


Expand Down
Loading

0 comments on commit b570be0

Please sign in to comment.