-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '231-performance-tests-mi' into 'release'
Resolve "IM: Test de performance" See merge request 3d/PandoraBox/pandora2d!195
- Loading branch information
Showing
83 changed files
with
273 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) 2025 Centre National d'Etudes Spatiales (CNES). | ||
# | ||
# This file is part of PANDORA2D | ||
# | ||
# https://github.com/CNES/Pandora2D | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright (c) 2025 Centre National d'Etudes Spatiales (CNES). | ||
# | ||
# This file is part of PANDORA2D | ||
# | ||
# https://github.com/CNES/Pandora2D | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
"""Module with global performance test fixtures and methods.""" | ||
|
||
# Make pylint happy with fixtures: | ||
# pylint: disable=redefined-outer-name | ||
|
||
from typing import Tuple | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
import numpy as np | ||
|
||
from numpy.typing import NDArray | ||
|
||
|
||
@pytest.fixture() | ||
def remove_edges(): | ||
""" | ||
Remove medicis disparity maps edges | ||
""" | ||
|
||
def inner( | ||
medicis_map: NDArray[np.floating], pandora2d_map: NDArray[np.floating] | ||
) -> Tuple[NDArray[np.floating], NDArray[np.floating]]: | ||
""" | ||
Get reduced disparity maps after removing medicis edges full of nans (greater than pandora2d edges) | ||
on both pandora2d and medicis disparity maps. | ||
""" | ||
|
||
# Gets coordinates for which medicis col_map is different from nan | ||
# i.e. points that are not within the edges | ||
non_nan_row_indexes, non_nan_col_indexes = np.where(~np.isnan(medicis_map)) | ||
|
||
# Remove medicis edges | ||
medicis_map = medicis_map[ | ||
non_nan_row_indexes[0] : non_nan_row_indexes[-1] + 1, non_nan_col_indexes[0] : non_nan_col_indexes[-1] + 1 | ||
] | ||
|
||
# Remove pandora2d edges to get the same points as the ones in medicis disparity maps | ||
pandora2d_map = pandora2d_map[ | ||
non_nan_row_indexes[0] : non_nan_row_indexes[-1] + 1, non_nan_col_indexes[0] : non_nan_col_indexes[-1] + 1 | ||
] | ||
|
||
return medicis_map, pandora2d_map | ||
|
||
return inner | ||
|
||
|
||
@pytest.fixture() | ||
def data_path(): | ||
""" | ||
Return path to get left and right images and medicis data | ||
""" | ||
return Path("tests/performance_tests/data_medicis/") | ||
|
||
|
||
@pytest.fixture() | ||
def shift_path(data_path, img_path): | ||
""" | ||
Return path to get left and right images and medicis data | ||
""" | ||
return data_path / img_path | ||
|
||
|
||
@pytest.fixture() | ||
def medicis_maps_path(shift_path, medicis_method_path): | ||
""" | ||
Return path to get medicis data | ||
""" | ||
return shift_path / medicis_method_path |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T19KER/r+0.00c+0.50/mi/gri_resultat_col_disp.tif
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T19KER/r+0.00c-0.25/mi/gri_resultat_col_disp.tif
Binary file not shown.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T19KER/r+0.00c-0.25/mi/gri_resultat_row_disp.tif
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+47.4 KB
...R/r+0.00c-0.25/zncc_dicho_nappe_surech_sinc/gri_zncc_dicho_nappe_surech_sinc_row_disp.tif
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T50JML/r+0.00c+0.50/mi/gri_resultat_col_disp.tif
Binary file not shown.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T50JML/r+0.00c+0.50/mi/gri_resultat_row_disp.tif
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T50JML/r+0.00c-0.25/mi/gri_resultat_col_disp.tif
Binary file not shown.
Binary file added
BIN
+47.4 KB
tests/performance_tests/data_medicis/T50JML/r+0.00c-0.25/mi/gri_resultat_row_disp.tif
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
118 changes: 118 additions & 0 deletions
118
tests/performance_tests/matching_cost/test_mutual_information_performance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# Copyright (c) 2025 Centre National d'Etudes Spatiales (CNES). | ||
# | ||
# This file is part of PANDORA2D | ||
# | ||
# https://github.com/CNES/Pandora2D | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Test the refinement.dichotomy pipeline. | ||
""" | ||
|
||
import pytest | ||
import numpy as np | ||
import rasterio | ||
|
||
|
||
class TestComparisonMedicis: | ||
""" | ||
Test that pandora2d disparity maps are equal or close to the medicis ones | ||
when matching cost is used with mutual information method. | ||
""" | ||
|
||
@pytest.fixture() | ||
def cfg_mutual_information(self, shift_path, subpix): | ||
""" | ||
Make user configuration for mutual information computation | ||
""" | ||
|
||
return { | ||
"input": { | ||
"left": {"nodata": -9999, "img": str(shift_path / "left.tif")}, | ||
"right": {"nodata": -9999, "img": str(shift_path / "right.tif")}, | ||
"col_disparity": {"init": 0, "range": 3}, | ||
"row_disparity": {"init": 0, "range": 3}, | ||
}, | ||
"pipeline": { | ||
"matching_cost": { | ||
"matching_cost_method": "mutual_information", | ||
"window_size": 65, | ||
"step": [1, 1], | ||
"subpix": subpix, | ||
}, | ||
"disparity": {"disparity_method": "wta", "invalid_disparity": np.nan}, | ||
}, | ||
} | ||
|
||
@pytest.mark.parametrize( | ||
[ | ||
"img_path", | ||
"subpix", | ||
"medicis_method_path", | ||
], | ||
[ | ||
pytest.param( | ||
"T19KER/r+0.00c+0.50/", | ||
2, | ||
"mi/gri_resultat_", | ||
id="T19KER (Calama, Chile) shifted of 0.5 in columns with subpix=2", | ||
), | ||
pytest.param( | ||
"T50JML/r+0.00c+0.50/", | ||
2, | ||
"mi/gri_resultat_", | ||
id="T50JML (Perth, Australia) shifted of 0.5 in columns with subpix=2", | ||
), | ||
pytest.param( | ||
"T19KER/r+0.00c-0.25/", | ||
4, | ||
"mi/gri_resultat_", | ||
id="T19KER (Calama, Chile) shifted of -0.25 in columns with subpix=4", | ||
), | ||
pytest.param( | ||
"T50JML/r+0.00c-0.25/", | ||
4, | ||
"mi/gri_resultat_", | ||
id="T50JML (Perth, Australia) shifted of -0.25 in columns with subpix=4", | ||
), | ||
], | ||
) | ||
def test_pandora2d_medicis_mutual_information( | ||
self, run_pipeline, remove_edges, cfg_mutual_information, medicis_maps_path | ||
): | ||
""" | ||
Compute mean errors of medicis and pandora2d disparity maps | ||
""" | ||
|
||
# Run pandora2D pipeline | ||
run_dir = run_pipeline(cfg_mutual_information) | ||
|
||
# Get pandora2d disparity maps | ||
with rasterio.open(run_dir / "output" / "row_map.tif") as src: | ||
row_map_pandora2d = src.read(1) | ||
with rasterio.open(run_dir / "output" / "col_map.tif") as src: | ||
col_map_pandora2d = src.read(1) | ||
|
||
# Get medicis disparity maps | ||
with rasterio.open(str(medicis_maps_path) + "row_disp.tif") as src: | ||
row_map_medicis = src.read(1) | ||
with rasterio.open(str(medicis_maps_path) + "col_disp.tif") as src: | ||
col_map_medicis = src.read(1) | ||
|
||
# Remove medicis edges on both pandora2d and medicis disparity maps | ||
# in order to compare the same sample of points. | ||
row_map_medicis, row_map_pandora2d = remove_edges(row_map_medicis, row_map_pandora2d) | ||
col_map_medicis, col_map_pandora2d = remove_edges(col_map_medicis, col_map_pandora2d) | ||
|
||
np.testing.assert_array_equal(row_map_medicis, row_map_pandora2d) | ||
np.testing.assert_array_equal(col_map_medicis, col_map_pandora2d) |
Oops, something went wrong.