Skip to content

Commit

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

See merge request 3d/PandoraBox/pandora_plugins/plugin_mc-cnn!42
  • Loading branch information
lecontm committed Nov 10, 2023
2 parents 93deac6 + a3f1a4e commit 7faaac9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 31 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

## Unreleased

## 1.3.0a1 (November 2023)

### Added

- Add function to get band values, the numpy array. [#31]

### Changed

- New format for disparity in the user configuration file. [#33]
- Update with new API of Pandora compute_cost_volume function. [#38]

### Fixed

- Deletion of the pip install codecov of githubAction CI.
- Remove right_disp_map. [#37]

## 1.2.0 (March 2023)

Expand Down
28 changes: 21 additions & 7 deletions pandora_plugin_mc_cnn/plugin_mc_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, **cfg: Union[int, str]):
self._window_size = self.cfg["window_size"]
self._subpix = self.cfg["subpix"]
self._band = self.cfg["band"]
self._step_col = int(self.cfg["step"])

def check_config(self, **cfg: Union[int, str]) -> Dict[str, Union[int, str]]:
"""
Expand All @@ -80,13 +81,17 @@ def check_config(self, **cfg: Union[int, str]) -> Dict[str, Union[int, str]]:
cfg["model_path"] = self._MODEL_PATH
if "band" not in cfg:
cfg["band"] = self._BAND
if "step" not in cfg:
cfg["step"] = self._STEP_COL # type: ignore


schema = {
"matching_cost_method": And(str, lambda x: x == "mc_cnn"),
"window_size": And(int, lambda x: x == 11),
"subpix": And(int, lambda x: x == 1),
"model_path": And(str, lambda x: os.path.exists(x)),
"band": Or(str, lambda input: input is None),
"step": And(int, lambda y: y >= 1),
}

checker = Checker(schema)
Expand All @@ -101,31 +106,40 @@ def desc(self):
print("MC-CNN similarity measure")

def compute_cost_volume(
self, img_left: xr.Dataset, img_right: xr.Dataset, disp_min: int, disp_max: int
self, img_left: xr.Dataset, img_right: xr.Dataset, grid_disp_min: np.ndarray, grid_disp_max: np.ndarray
) -> xr.Dataset:
"""
Computes the cost volume for a pair of images
:param img_left: left Dataset image
:type img_left:
xarray.Dataset containing :
- im : 2D (row, col) xarray.DataArray
- msk : 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
:param img_right: right Dataset image
:type img_right:
xarray.Dataset containing :
- im : 2D (row, col) xarray.DataArray
- msk : 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
:param disp_min: minimum disparity
:type disp_min: int
:type disp_min: np.ndarray
:param disp_max: maximum disparity
:type disp_max: int
:type disp_max: np.ndarray
:return: the cost volume dataset
:rtype:
xarray.Dataset, with the data variables:
- cost_volume 3D xarray.DataArray (row, col, disp)
- confidence_measure 3D xarray.DataArray (row, col, indicator)
"""
# Obtain absolute min and max disparities
disp_min, disp_max = self.get_min_max_from_grid(grid_disp_min, grid_disp_max)

# check band parameter
self.check_band_input_mc(img_left, img_right)

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ setup_requires =
# Pandora plugin MC-CNN packages dependencies
install_requires =
numpy
MCCNN==1.2.0
pandora>=1.4.0
MCCNN==1.2.1
pandora==1.6.0a2
xarray
json-checker

Expand Down
8 changes: 2 additions & 6 deletions tests/test_cfg_mccnn_fast.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
"input" : {
"img_left" : "tests/image/left_img.png",
"img_right" : "tests/image/right_img.png",
"disp_min" : -60,
"disp_max" : 0
"disp_left" : [-60, 0]
},
"pipeline": {
"right_disp_map": {
"method": "accurate"
},
"matching_cost" : {
"matching_cost_method": "mc_cnn",
"subpix": 1,
Expand All @@ -30,7 +26,7 @@
"filter_size": 3
},
"validation" : {
"validation_method": "cross_checking",
"validation_method": "cross_checking_accurate",
"cross_checking_threshold": 1
}
}
Expand Down
8 changes: 2 additions & 6 deletions tests/test_cfg_mccnn_fast_default_values.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
"input" : {
"img_left" : "tests/image/left_img.png",
"img_right" : "tests/image/right_img.png",
"disp_min" : -60,
"disp_max" : 0
"disp_left" : [-60, 0]
},
"pipeline": {
"right_disp_map": {
"method": "accurate"
},
"matching_cost" : {
"matching_cost_method": "mc_cnn"
},
Expand All @@ -27,7 +23,7 @@
"filter_size": 3
},
"validation" : {
"validation_method": "cross_checking",
"validation_method": "cross_checking_accurate",
"cross_checking_threshold": 1
}
}
Expand Down
8 changes: 2 additions & 6 deletions tests/test_cfg_mccnn_fast_multiband.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
"input" : {
"img_left" : "tests/image/left_rgb.tif",
"img_right" : "tests/image/right_rgb.tif",
"disp_min" : -60,
"disp_max" : 0
"disp_left" : [-60, 0]
},
"pipeline": {
"right_disp_map": {
"method": "accurate"
},
"matching_cost" : {
"matching_cost_method": "mc_cnn",
"subpix": 1,
Expand All @@ -31,7 +27,7 @@
"filter_size": 3
},
"validation" : {
"validation_method": "cross_checking",
"validation_method": "cross_checking_accurate",
"cross_checking_threshold": 1
}
}
Expand Down
25 changes: 21 additions & 4 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import pandora
from pandora import matching_cost
from pandora_plugin_mc_cnn.plugin_mc_cnn import MCCNN, get_band_values # pylint: disable=unused-import
from pandora.img_tools import add_disparity


# pylint: disable=unsubscriptable-object
Expand Down Expand Up @@ -177,6 +178,7 @@ def test_invalidates_cost(self):
left.attrs["no_data_mask"] = 1
left.attrs["crs"] = None
left.attrs["transform"] = None
left.pipe(add_disparity, disparity=[-1, 1], window=None)

data = np.zeros((13, 13), dtype=np.float64)
data += 0.1
Expand Down Expand Up @@ -321,13 +323,20 @@ def test_invalidates_cost(self):
"model_path": "tests/weights/mc_cnn_fast_mb_weights.pt",
}
)
cv = matching_cost_.compute_cost_volume(left, right, disp_min=-1, disp_max=1)
cv = matching_cost_.compute_cost_volume(
img_left=left,
img_right=right,
grid_disp_min=left["disparity"].sel(band_disp="min"),
grid_disp_max=left["disparity"].sel(band_disp="max")
)

# Check if the calculated cost volume is equal to the ground truth (same shape and all elements equals)
np.testing.assert_allclose(cv["cost_volume"].data, cv_before_invali, rtol=1e-06)

# Masked cost volume with pandora function
matching_cost_.cv_masked(left, right, cv, -1, 1)
matching_cost_.cv_masked(
left, right, cv, left["disparity"].sel(band_disp="min"), left["disparity"].sel(band_disp="max")
)
# Check if the calculated cost volume is equal to the ground truth (same shape and all elements equals)
np.testing.assert_allclose(cv["cost_volume"].data, cv_ground_truth, rtol=1e-06)
# ------------ Test the method with a secondary mask ( reference mask contains valid pixels ) ------------
Expand All @@ -348,6 +357,7 @@ def test_invalidates_cost(self):
left.attrs["no_data_mask"] = 1
left.attrs["crs"] = None
left.attrs["transform"] = None
left.pipe(add_disparity, disparity=[-1, 1], window=None)

data = np.zeros((13, 13), dtype=np.float64)
data += 0.1
Expand Down Expand Up @@ -511,13 +521,20 @@ def test_invalidates_cost(self):
"model_path": "tests/weights/mc_cnn_fast_mb_weights.pt",
}
)
cv = matching_cost_.compute_cost_volume(left, right, disp_min=-1, disp_max=1)
cv = matching_cost_.compute_cost_volume(
img_left=left,
img_right=right,
grid_disp_min=left["disparity"].sel(band_disp="min"),
grid_disp_max=left["disparity"].sel(band_disp="max")
)

# Check if the calculated cost volume is equal to the ground truth (same shape and all elements equals)
np.testing.assert_allclose(cv["cost_volume"].data, cv_before_invali, rtol=1e-06)

# Masked cost volume with pandora function
matching_cost_.cv_masked(left, right, cv, -1, 1)
matching_cost_.cv_masked(
left, right, cv, left["disparity"].sel(band_disp="min"), left["disparity"].sel(band_disp="max")
)

# Check if the calculated cost volume is equal to the ground truth (same shape and all elements equals)
np.testing.assert_allclose(cv["cost_volume"].data, cv_ground_truth, rtol=1e-06)
Expand Down

0 comments on commit 7faaac9

Please sign in to comment.