Skip to content

Commit

Permalink
Merge branch '975-decimer-les-bandeaux-pour-les-sifts' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Decimer les bandeaux pour les sifts"

Closes #975

See merge request 3d/cars-park/cars!800
  • Loading branch information
dyoussef committed Jan 29, 2025
2 parents 403bea3 + 666dec2 commit ead3395
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cars/applications/dense_matching/census_mccnn_sgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def check_conf(self, conf):
fake_dataset = xr.Dataset(
data_vars={},
coords={
"band_im": [(None)],
"band_im": [None],
"row": np.arange(10),
"col": np.arange(10),
},
Expand Down
2 changes: 1 addition & 1 deletion cars/applications/dense_matching/loaders/pandora_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def get_config_input_custom_cars(user_cfg: Dict[str, dict]) -> Dict[str, dict]:


def check_input_section_custom_cars(
user_cfg: Dict[str, dict]
user_cfg: Dict[str, dict],
) -> Dict[str, dict]:
"""
Complete and check if the dictionary is correct
Expand Down
13 changes: 8 additions & 5 deletions cars/applications/grid_generation/grid_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def estimate_right_grid_correction(
grid_right,
initial_cars_ds=None,
save_matches=False,
minimum_nb_matches=100,
pair_folder="",
pair_key="pair_0",
orchestrator=None,
Expand All @@ -185,6 +186,8 @@ def estimate_right_grid_correction(
:type grid_right: CarsDataset
:param save_matches: true is matches needs to be saved
:type save_matches: bool
:param minimum_nb_matches: minimum number of matches required
:type minimum_nb_matches: int
:param pair_folder: folder used for current pair
:type pair_folder: str
Expand All @@ -206,15 +209,15 @@ def estimate_right_grid_correction(
else:
cars_orchestrator = orchestrator

if matches.shape[0] < 100:
if matches.shape[0] < minimum_nb_matches:
logging.error(
"Insufficient amount of matches found (< 100), can not safely "
"estimate epipolar error correction"
"Insufficient amount of matches found"
", can not safely estimate epipolar error correction"
)

raise ValueError(
"Insufficient amount of matches found (< 100), can not safely "
"estimate epipolar error correction"
f"Insufficient amount of matches found (< {minimum_nb_matches})"
", can not safely estimate epipolar error correction"
)

# Get grids attributes
Expand Down
32 changes: 31 additions & 1 deletion cars/applications/sparse_matching/sift.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self, conf=None):
self.matches_filter_dev_factor = self.used_config[
"matches_filter_dev_factor"
]
self.decimation_factor = self.used_config["decimation_factor"]

# Saving files
self.save_intermediate_data = self.used_config["save_intermediate_data"]
Expand Down Expand Up @@ -138,6 +139,9 @@ def check_conf(self, conf):
overloaded_conf["elevation_delta_lower_bound"] = conf.get(
"elevation_delta_lower_bound", None
)
overloaded_conf["decimation_factor"] = conf.get(
"decimation_factor", 100
)
overloaded_conf["elevation_delta_upper_bound"] = conf.get(
"elevation_delta_upper_bound", None
)
Expand Down Expand Up @@ -212,6 +216,7 @@ def check_conf(self, conf):
"sift_edge_threshold": float,
"sift_magnification": And(float, lambda x: x > 0),
"sift_window_size": And(int, lambda x: x > 0),
"decimation_factor": And(int, lambda x: x > 0),
"sift_back_matching": bool,
"matches_filter_knn": int,
"matches_filter_dev_factor": Or(int, float),
Expand Down Expand Up @@ -321,6 +326,22 @@ def get_matches_filter_dev_factor(self):
"""
return self.matches_filter_dev_factor

def get_decimation_factor(self):
"""
Get decimation_factor
:return: decimation_factor
"""
return self.decimation_factor

def set_decimation_factor(self, value):
"""
set decimation_factor
"""
self.decimation_factor = value

def run(
self,
epipolar_image_left,
Expand Down Expand Up @@ -489,7 +510,16 @@ def run(
epipolar_disparity_map_left, cars_ds_name="epi_matches_left"
)
# Generate disparity maps
for row in range(epipolar_disparity_map_left.shape[0]):
total_nb_band_sift = epipolar_disparity_map_left.shape[0]

step = int(np.round(100 / self.decimation_factor))

if total_nb_band_sift in (1, 2):
step = 1
elif total_nb_band_sift == 3:
step = 2

for row in range(0, total_nb_band_sift, step):
# initialize list of matches
full_saving_info_left = ocht.update_saving_infos(
saving_info_left, row=row, col=0
Expand Down
12 changes: 12 additions & 0 deletions cars/pipelines/default/default_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,13 @@ def check_applications_with_inputs(self, inputs_conf, application_conf):
)
)

if (
self.sparse_mtch_pandora_app.used_config.get("activated", False)
is True
and self.sparse_mtch_sift_app.get_decimation_factor() == 100
):
self.sparse_mtch_sift_app.set_decimation_factor(30)

return application_conf

def sensor_to_depth_maps(self): # noqa: C901
Expand Down Expand Up @@ -1102,6 +1109,10 @@ def sensor_to_depth_maps(self): # noqa: C901
)
)

minimum_nb_matches = (
self.sparse_mtch_sift_app.get_minimum_nb_matches()
)

# Compute grid correction
(
self.pairs[pair_key]["grid_correction_coef"],
Expand All @@ -1116,6 +1127,7 @@ def sensor_to_depth_maps(self): # noqa: C901
"epipolar_matches_left"
],
save_matches=save_matches,
minimum_nb_matches=minimum_nb_matches,
pair_folder=os.path.join(
self.dump_dir, "grid_correction", "initial", pair_key
),
Expand Down
43 changes: 24 additions & 19 deletions docs/source/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -984,28 +984,33 @@ The structure follows this organization:

**Sift:**

+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| Name | Description | Type | Available value | Default value | Required |
+======================================+================================================================================================+=============+========================+===============+==========+
| disparity_outliers_rejection_percent | Percentage of outliers to reject | float | between 0 and 1 | 0.1 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_matching_threshold | Threshold for the ratio to nearest second match | float | should be > 0 | 0.7 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_n_octave | The number of octaves of the Difference of Gaussians scale space | int | should be > 0 | 8 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_n_scale_per_octave | The numbers of levels per octave of the Difference of Gaussians scale space | int | should be > 0 | 3 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_peak_threshold | Constrast threshold to discard a match (at None it will be set according to image type) | float | should be > 0 | 4.0 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_edge_threshold | Distance to image edge threshold to discard a match | float | | 10.0 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_magnification | The descriptor magnification factor | float | should be > 0 | 7.0 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
| sift_window_size | smaller values let the center of the descriptor count more | int | should be > 0 | 2 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+---------------+----------+
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| Name | Description | Type | Available value | Default value | Required |
+======================================+================================================================================================+=============+========================+===========================================+==========+
| disparity_outliers_rejection_percent | Percentage of outliers to reject | float | between 0 and 1 | 0.1 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_matching_threshold | Threshold for the ratio to nearest second match | float | should be > 0 | 0.7 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_n_octave | The number of octaves of the Difference of Gaussians scale space | int | should be > 0 | 8 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_n_scale_per_octave | The numbers of levels per octave of the Difference of Gaussians scale space | int | should be > 0 | 3 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_peak_threshold | Constrast threshold to discard a match (at None it will be set according to image type) | float | should be > 0 | 4.0 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_edge_threshold | Distance to image edge threshold to discard a match | float | | 10.0 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_magnification | The descriptor magnification factor | float | should be > 0 | 7.0 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| sift_window_size | smaller values let the center of the descriptor count more | int | should be > 0 | 2 | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+
| decimation_factor | Reduce the number of sifts | int | should be > 0 | 20 if pandora is activated, 100 otherwise | No |
+--------------------------------------+------------------------------------------------------------------------------------------------+-------------+------------------------+-------------------------------------------+----------+

For more information about these parameters, please refer to the `VLFEAT SIFT documentation <https://www.vlfeat.org/api/sift.html>`_.

.. note::
For the decimation factor, a value of 33 means that we divide the number of sift by 3, a value of 100 means that we do not decimate them


**Pandora:**

Expand Down
Binary file modified tests/data/ref_output/color_end2end_gizeh_crop_no_merging.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_gizeh_fill_with_zero.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_split_4326.tif
Binary file not shown.
Binary file modified tests/data/ref_output/dsm_end2end_gizeh_crop_no_merging.tif
Binary file not shown.
Binary file modified tests/data/ref_output/dsm_end2end_gizeh_fill_with_zero.tif
Binary file not shown.
Binary file modified tests/data/ref_output/dsm_end2end_ventoux_split_4326.tif
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/ref_output/source_pc_end2end_ventoux_split_4326.tif
Binary file not shown.
Loading

0 comments on commit ead3395

Please sign in to comment.