cars 1.0.0a2__cp310-cp310-win_amd64.whl → 1.0.0a4__cp310-cp310-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cars might be problematic. Click here for more details.

Files changed (144) hide show
  1. cars/__init__.py +3 -3
  2. cars/applications/__init__.py +0 -3
  3. cars/applications/application.py +14 -6
  4. cars/applications/application_template.py +42 -0
  5. cars/applications/auxiliary_filling/abstract_auxiliary_filling_app.py +12 -2
  6. cars/applications/auxiliary_filling/auxiliary_filling_algo.py +2 -2
  7. cars/applications/auxiliary_filling/auxiliary_filling_from_sensors_app.py +95 -46
  8. cars/applications/auxiliary_filling/auxiliary_filling_wrappers.py +7 -6
  9. cars/applications/dem_generation/abstract_dem_generation_app.py +9 -5
  10. cars/applications/dem_generation/dem_generation_algo.py +1 -1
  11. cars/applications/dem_generation/dem_generation_wrappers.py +44 -59
  12. cars/applications/dem_generation/dichotomic_generation_app.py +9 -6
  13. cars/applications/dem_generation/rasterization_app.py +112 -43
  14. cars/applications/dense_match_filling/__init__.py +1 -1
  15. cars/applications/dense_match_filling/abstract_dense_match_filling_app.py +2 -15
  16. cars/applications/dense_match_filling/fill_disp_algo.py +32 -373
  17. cars/applications/dense_match_filling/fill_disp_wrappers.py +0 -343
  18. cars/applications/dense_match_filling/zero_padding_app.py +10 -5
  19. cars/applications/dense_matching/abstract_dense_matching_app.py +2 -1
  20. cars/applications/dense_matching/census_mccnn_sgm_app.py +48 -60
  21. cars/applications/dense_matching/cpp/dense_matching_cpp.cp310-win_amd64.dll.a +0 -0
  22. cars/applications/dense_matching/cpp/dense_matching_cpp.cp310-win_amd64.pyd +0 -0
  23. cars/applications/dense_matching/dense_matching_algo.py +48 -14
  24. cars/applications/dense_matching/dense_matching_wrappers.py +11 -3
  25. cars/applications/dense_matching/disparity_grid_algo.py +95 -79
  26. cars/applications/dense_matching/loaders/config_mapping.json +13 -0
  27. cars/applications/dense_matching/loaders/global_land_cover_map.tif +0 -0
  28. cars/applications/dense_matching/loaders/pandora_loader.py +169 -34
  29. cars/applications/dsm_filling/border_interpolation_app.py +11 -12
  30. cars/applications/dsm_filling/bulldozer_filling_app.py +16 -15
  31. cars/applications/dsm_filling/exogenous_filling_app.py +14 -14
  32. cars/applications/grid_generation/abstract_grid_generation_app.py +1 -1
  33. cars/applications/grid_generation/epipolar_grid_generation_app.py +4 -2
  34. cars/applications/grid_generation/grid_correction_app.py +4 -1
  35. cars/applications/grid_generation/grid_generation_algo.py +7 -2
  36. cars/applications/ground_truth_reprojection/abstract_ground_truth_reprojection_app.py +1 -1
  37. cars/applications/ground_truth_reprojection/direct_localization_app.py +2 -2
  38. cars/applications/ground_truth_reprojection/ground_truth_reprojection_algo.py +2 -1
  39. cars/applications/point_cloud_fusion/abstract_pc_fusion_app.py +0 -155
  40. cars/applications/point_cloud_fusion/mapping_to_terrain_tiles_app.py +0 -658
  41. cars/applications/point_cloud_fusion/pc_fusion_algo.py +0 -1339
  42. cars/applications/point_cloud_fusion/pc_fusion_wrappers.py +0 -869
  43. cars/applications/point_cloud_outlier_removal/abstract_outlier_removal_app.py +11 -6
  44. cars/applications/point_cloud_outlier_removal/outlier_removal_algo.py +9 -8
  45. cars/applications/point_cloud_outlier_removal/small_components_app.py +101 -270
  46. cars/applications/point_cloud_outlier_removal/statistical_app.py +120 -277
  47. cars/applications/rasterization/abstract_pc_rasterization_app.py +2 -1
  48. cars/applications/rasterization/rasterization_algo.py +18 -6
  49. cars/applications/rasterization/rasterization_wrappers.py +2 -1
  50. cars/applications/rasterization/simple_gaussian_app.py +88 -116
  51. cars/applications/resampling/abstract_resampling_app.py +1 -1
  52. cars/applications/resampling/bicubic_resampling_app.py +3 -1
  53. cars/applications/resampling/resampling_algo.py +60 -53
  54. cars/applications/resampling/resampling_wrappers.py +3 -1
  55. cars/applications/sparse_matching/abstract_sparse_matching_app.py +1 -1
  56. cars/applications/sparse_matching/sift_app.py +5 -25
  57. cars/applications/sparse_matching/sparse_matching_algo.py +3 -2
  58. cars/applications/sparse_matching/sparse_matching_wrappers.py +1 -1
  59. cars/applications/triangulation/abstract_triangulation_app.py +1 -1
  60. cars/applications/triangulation/line_of_sight_intersection_app.py +13 -11
  61. cars/applications/triangulation/pc_transform.py +552 -0
  62. cars/applications/triangulation/triangulation_algo.py +6 -4
  63. cars/applications/triangulation/triangulation_wrappers.py +1 -0
  64. cars/bundleadjustment.py +6 -6
  65. cars/cars.py +11 -9
  66. cars/core/cars_logging.py +80 -49
  67. cars/core/constants.py +0 -1
  68. cars/core/datasets.py +5 -2
  69. cars/core/geometry/abstract_geometry.py +364 -22
  70. cars/core/geometry/shareloc_geometry.py +112 -82
  71. cars/core/inputs.py +72 -19
  72. cars/core/outputs.py +1 -1
  73. cars/core/preprocessing.py +17 -3
  74. cars/core/projection.py +126 -6
  75. cars/core/tiling.py +10 -3
  76. cars/data_structures/cars_dataset.py +12 -10
  77. cars/data_structures/corresponding_tiles_tools.py +0 -103
  78. cars/data_structures/format_transformation.py +4 -1
  79. cars/devibrate.py +6 -3
  80. cars/extractroi.py +20 -21
  81. cars/orchestrator/cluster/abstract_cluster.py +15 -5
  82. cars/orchestrator/cluster/abstract_dask_cluster.py +6 -2
  83. cars/orchestrator/cluster/dask_jobqueue_utils.py +1 -1
  84. cars/orchestrator/cluster/log_wrapper.py +149 -22
  85. cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py +12 -4
  86. cars/orchestrator/cluster/mp_cluster/multiprocessing_profiler.py +2 -2
  87. cars/orchestrator/cluster/pbs_dask_cluster.py +1 -1
  88. cars/orchestrator/cluster/sequential_cluster.py +5 -4
  89. cars/orchestrator/cluster/slurm_dask_cluster.py +1 -1
  90. cars/orchestrator/orchestrator.py +15 -4
  91. cars/orchestrator/registry/id_generator.py +1 -0
  92. cars/orchestrator/registry/saver_registry.py +2 -2
  93. cars/pipelines/conf_resolution/conf_final_resolution.json +5 -3
  94. cars/pipelines/default/default_pipeline.py +461 -1052
  95. cars/pipelines/parameters/advanced_parameters.py +91 -64
  96. cars/pipelines/parameters/advanced_parameters_constants.py +6 -5
  97. cars/pipelines/parameters/application_parameters.py +71 -0
  98. cars/pipelines/parameters/depth_map_inputs.py +0 -314
  99. cars/pipelines/parameters/dsm_inputs.py +40 -4
  100. cars/pipelines/parameters/output_parameters.py +44 -8
  101. cars/pipelines/parameters/sensor_inputs.py +122 -73
  102. cars/pipelines/parameters/sensor_inputs_constants.py +0 -2
  103. cars/pipelines/parameters/sensor_loaders/__init__.py +4 -3
  104. cars/pipelines/parameters/sensor_loaders/basic_classif_loader.py +106 -0
  105. cars/pipelines/parameters/sensor_loaders/{basic_sensor_loader.py → basic_image_loader.py} +16 -22
  106. cars/pipelines/parameters/sensor_loaders/pivot_classif_loader.py +121 -0
  107. cars/pipelines/parameters/sensor_loaders/{pivot_sensor_loader.py → pivot_image_loader.py} +10 -21
  108. cars/pipelines/parameters/sensor_loaders/sensor_loader.py +4 -6
  109. cars/pipelines/parameters/sensor_loaders/sensor_loader_template.py +1 -3
  110. cars/pipelines/pipeline_template.py +1 -3
  111. cars/pipelines/unit/unit_pipeline.py +676 -1070
  112. cars/starter.py +4 -3
  113. cars-1.0.0a4.dist-info/DELVEWHEEL +2 -0
  114. {cars-1.0.0a2.dist-info → cars-1.0.0a4.dist-info}/METADATA +135 -53
  115. {cars-1.0.0a2.dist-info → cars-1.0.0a4.dist-info}/RECORD +120 -134
  116. cars.libs/libgcc_s_seh-1-b2494fcbd4d80cf2c98fdd5261f6d850.dll +0 -0
  117. cars.libs/libstdc++-6-e9b0d12ae0e9555bbae55e8dfd08c3f7.dll +0 -0
  118. cars.libs/libwinpthread-1-7882d1b093714ccdfaf4e0789a817792.dll +0 -0
  119. cars/applications/dense_match_filling/cpp/__init__.py +0 -0
  120. cars/applications/dense_match_filling/cpp/dense_match_filling_cpp.cp310-win_amd64.dll.a +0 -0
  121. cars/applications/dense_match_filling/cpp/dense_match_filling_cpp.cp310-win_amd64.pyd +0 -0
  122. cars/applications/dense_match_filling/cpp/dense_match_filling_cpp.py +0 -72
  123. cars/applications/dense_match_filling/cpp/includes/dense_match_filling.hpp +0 -46
  124. cars/applications/dense_match_filling/cpp/meson.build +0 -9
  125. cars/applications/dense_match_filling/cpp/src/bindings.cpp +0 -11
  126. cars/applications/dense_match_filling/cpp/src/dense_match_filling.cpp +0 -142
  127. cars/applications/dense_match_filling/plane_app.py +0 -556
  128. cars/applications/hole_detection/__init__.py +0 -30
  129. cars/applications/hole_detection/abstract_hole_detection_app.py +0 -125
  130. cars/applications/hole_detection/cloud_to_bbox_app.py +0 -346
  131. cars/applications/hole_detection/hole_detection_algo.py +0 -144
  132. cars/applications/hole_detection/hole_detection_wrappers.py +0 -53
  133. cars/applications/point_cloud_denoising/__init__.py +0 -29
  134. cars/applications/point_cloud_denoising/abstract_pc_denoising_app.py +0 -273
  135. cars/applications/point_cloud_fusion/__init__.py +0 -30
  136. cars/applications/point_cloud_fusion/cloud_fusion_constants.py +0 -39
  137. cars/applications/sparse_matching/pandora_sparse_matching_app.py +0 -0
  138. cars/pipelines/parameters/depth_map_inputs_constants.py +0 -25
  139. cars-1.0.0a2.dist-info/DELVEWHEEL +0 -2
  140. cars.libs/libgcc_s_seh-1-f2b6825d483bdf14050493af93b5997d.dll +0 -0
  141. cars.libs/libstdc++-6-6b0059df6bc601df5a0f18a5805eea05.dll +0 -0
  142. cars.libs/libwinpthread-1-e01b8e85fd67c2b861f64d4ccc7df607.dll +0 -0
  143. {cars-1.0.0a2.dist-info → cars-1.0.0a4.dist-info}/WHEEL +0 -0
  144. {cars-1.0.0a2.dist-info → cars-1.0.0a4.dist-info}/entry_points.txt +0 -0
@@ -1,30 +0,0 @@
1
- # !/usr/bin/env python
2
- # coding: utf8
3
- #
4
- # Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
5
- #
6
- # This file is part of CARS
7
- # (see https://github.com/CNES/cars).
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- """
22
- CARS holes detection module init file
23
- """
24
- # flake8: noqa: F401
25
-
26
- from cars.applications.hole_detection.abstract_hole_detection_app import (
27
- HoleDetection,
28
- )
29
-
30
- from . import cloud_to_bbox_app
@@ -1,125 +0,0 @@
1
- # !/usr/bin/env python
2
- # coding: utf8
3
- #
4
- # Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
5
- #
6
- # This file is part of CARS
7
- # (see https://github.com/CNES/cars).
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- """
22
- CARS hole detection module init file
23
- """
24
-
25
- import logging
26
- from abc import ABCMeta, abstractmethod
27
- from typing import Dict
28
-
29
- from cars.applications.application import Application
30
- from cars.applications.application_template import ApplicationTemplate
31
-
32
-
33
- @Application.register("hole_detection")
34
- class HoleDetection(ApplicationTemplate, metaclass=ABCMeta):
35
- """
36
- HoleDetection
37
- """
38
-
39
- available_applications: Dict = {}
40
- default_application = "cloud_to_bbox"
41
-
42
- def __new__(cls, conf=None): # pylint: disable=W0613
43
- """
44
- Return the required application
45
- :raises:
46
- - KeyError when the required application is not registered
47
-
48
- :param conf: configuration for hole_detection
49
- :return: a application_to_use object
50
- """
51
-
52
- hole_detection_method = cls.default_application
53
- if bool(conf) is False or "method" not in conf:
54
- logging.info(
55
- "Holes Detection method not specified, "
56
- "default {} is used".format(hole_detection_method)
57
- )
58
- else:
59
- hole_detection_method = conf["method"]
60
-
61
- if hole_detection_method not in cls.available_applications:
62
- logging.error(
63
- "No hole_detection application named {} registered".format(
64
- hole_detection_method
65
- )
66
- )
67
- raise KeyError(
68
- "No hole_detection application named {} registered".format(
69
- hole_detection_method
70
- )
71
- )
72
-
73
- logging.info(
74
- "The HoleDetection({}) application will be used".format(
75
- hole_detection_method
76
- )
77
- )
78
-
79
- return super(HoleDetection, cls).__new__(
80
- cls.available_applications[hole_detection_method]
81
- )
82
-
83
- def __init_subclass__(cls, short_name, **kwargs): # pylint: disable=E0302
84
- super().__init_subclass__(**kwargs)
85
- cls.available_applications[short_name] = cls
86
-
87
- @abstractmethod
88
- def run(
89
- self,
90
- epipolar_images_left,
91
- epipolar_images_right,
92
- is_activated=True,
93
- margin=0,
94
- mask_holes_to_fill_left=None,
95
- mask_holes_to_fill_right=None,
96
- orchestrator=None,
97
- pair_folder=None,
98
- pair_key="PAIR_0",
99
- ):
100
- """
101
- Run Refill application using plane method.
102
-
103
- :param epipolar_images_left: left epipolar image
104
- :type epipolar_images_left: CarsDataset
105
- :param epipolar_images_right: right epipolar image
106
- :type epipolar_images_right: CarsDataset
107
- :param is_activated: activate application
108
- :type is_activated: bool
109
- :param margin: margin to use
110
- :type margin: int
111
- :param mask_holes_to_fill_left: mask classes to use
112
- :type mask_holes_to_fill_left: list(int)
113
- :param mask_holes_to_fill_right: mask classes to use
114
- :type mask_holes_to_fill_right: list(int)
115
- :param orchestrator: orchestrator used
116
- :type orchestrator: Orchestrator
117
- :param pair_folder: folder used for current pair
118
- :type pair_folder: str
119
- :param pair_key: pair id
120
- :type pair_key: str
121
-
122
- :return: left holes, right holes
123
- :rtype: Tuple(CarsDataset, CarsDataset)
124
-
125
- """
@@ -1,346 +0,0 @@
1
- # !/usr/bin/env python
2
- # coding: utf8
3
- #
4
- # Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
5
- #
6
- # This file is part of CARS
7
- # (see https://github.com/CNES/cars).
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- """
22
- CARS holes detection module init file
23
- """
24
-
25
- import logging
26
-
27
- # Standard imports
28
- import os
29
-
30
- # Third party imports
31
- from json_checker import Checker, OptionalKey
32
-
33
- import cars.orchestrator.orchestrator as ocht
34
- from cars.applications import application_constants
35
- from cars.applications.hole_detection import hole_detection_algo
36
- from cars.applications.hole_detection.abstract_hole_detection_app import (
37
- HoleDetection,
38
- )
39
-
40
- # CARS imports
41
- from cars.core.utils import safe_makedirs
42
- from cars.data_structures import cars_dataset, cars_dict
43
-
44
-
45
- class CloudToBbox(
46
- HoleDetection, short_name="cloud_to_bbox"
47
- ): # pylint: disable=R0903
48
- """
49
- CloudToBbox
50
- """
51
-
52
- # pylint: disable=too-many-instance-attributes
53
-
54
- def __init__(self, conf=None):
55
- """
56
- Init function of CloudToBbox
57
-
58
- :param conf: configuration for hole detection
59
- :return: a application_to_use object
60
- """
61
-
62
- super().__init__(conf=conf)
63
-
64
- # check conf
65
-
66
- # get rasterization parameter
67
- self.used_method = self.used_config["method"]
68
-
69
- # Init orchestrator
70
- self.orchestrator = None
71
-
72
- def check_conf(self, conf):
73
- """
74
- Check configuration
75
-
76
- :param conf: configuration to check
77
- :type conf: dict
78
-
79
- :return: overloaded configuration
80
- :rtype: dict
81
-
82
- """
83
-
84
- # init conf
85
- if conf is not None:
86
- overloaded_conf = conf.copy()
87
- else:
88
- conf = {}
89
- overloaded_conf = {}
90
-
91
- # Overload conf
92
-
93
- # get rasterization parameter
94
- overloaded_conf["method"] = conf.get("method", "cloud_to_bbox")
95
-
96
- hole_detection_schema = {
97
- "method": str,
98
- OptionalKey(application_constants.SAVE_INTERMEDIATE_DATA): bool,
99
- }
100
-
101
- # Check conf
102
- checker = Checker(hole_detection_schema)
103
- checker.validate(overloaded_conf)
104
-
105
- return overloaded_conf
106
-
107
- def run(
108
- self,
109
- epipolar_images_left,
110
- epipolar_images_right,
111
- classification=None,
112
- margin=0,
113
- orchestrator=None,
114
- pair_folder=None,
115
- pair_key="PAIR_0",
116
- ):
117
- """
118
- Run Refill application using plane method.
119
-
120
- :param epipolar_images_left: left epipolar image
121
- :type epipolar_images_left: CarsDataset
122
- :param epipolar_images_right: right epipolar image
123
- :type epipolar_images_right: CarsDataset
124
- :param is_activated: activate application
125
- :type is_activated: bool
126
- :param margin: margin to use
127
- :type margin: int
128
- :param classification: mask classes to use
129
- :type classification: list(str)
130
- :param orchestrator: orchestrator used
131
- :type orchestrator: Orchestrator
132
- :param pair_folder: folder used for current pair
133
- :type pair_folder: str
134
- :param pair_key: pair id
135
- :type pair_key: str
136
-
137
- :return: left holes, right holes
138
- :rtype: Tuple(CarsDataset, CarsDataset)
139
-
140
- """
141
-
142
- # Default orchestrator
143
- if orchestrator is None:
144
- # Create default sequential orchestrator for current application
145
- # be awere, no out_json will be shared between orchestrators
146
- # No files saved
147
- self.orchestrator = ocht.Orchestrator(
148
- orchestrator_conf={"mode": "sequential"}
149
- )
150
- else:
151
- self.orchestrator = orchestrator
152
-
153
- if pair_folder is None:
154
- pair_folder = os.path.join(self.orchestrator.out_dir, "tmp")
155
- safe_makedirs(pair_folder)
156
-
157
- if epipolar_images_left.dataset_type == "arrays":
158
- # Create CarsDataset
159
- # Epipolar_disparity
160
- left_bbox_cars_ds = cars_dataset.CarsDataset(
161
- "dict", name="cloud_to_bbox_left_" + pair_key
162
- )
163
- left_bbox_cars_ds.create_empty_copy(epipolar_images_left)
164
- left_bbox_cars_ds.overlaps *= 0
165
-
166
- right_bbox_cars_ds = cars_dataset.CarsDataset(
167
- "dict", name="cloud_to_bbox_left_" + pair_key
168
- )
169
- right_bbox_cars_ds.create_empty_copy(epipolar_images_right)
170
- right_bbox_cars_ds.overlaps *= 0
171
-
172
- # Add infos to orchestrator.out_json
173
- updating_dict = {
174
- application_constants.APPLICATION_TAG: {pair_key: {}}
175
- }
176
- self.orchestrator.update_out_info(updating_dict)
177
- logging.info(
178
- "Compute bbox: number tiles: {}".format(
179
- epipolar_images_left.shape[1]
180
- * epipolar_images_left.shape[0]
181
- )
182
- )
183
-
184
- if classification not in (None, []):
185
- # Get saving infos in order to save tiles when they are computed
186
- [
187
- saving_info_left,
188
- saving_info_right,
189
- ] = self.orchestrator.get_saving_infos(
190
- [left_bbox_cars_ds, right_bbox_cars_ds]
191
- )
192
-
193
- # Add to replace list so tiles will be readble at the same time
194
- self.orchestrator.add_to_replace_lists(
195
- left_bbox_cars_ds, cars_ds_name="epi_msk_bbox_left"
196
- )
197
- self.orchestrator.add_to_replace_lists(
198
- right_bbox_cars_ds, cars_ds_name="epi_msk_bbox_right"
199
- )
200
-
201
- # Generate disparity maps
202
- for col in range(epipolar_images_left.shape[1]):
203
- for row in range(epipolar_images_left.shape[0]):
204
- if (epipolar_images_left[row, col] is not None) or (
205
- epipolar_images_right[row, col] is not None
206
- ):
207
- # update saving_info with row and col needed for
208
- # replacement
209
- full_saving_info_left = ocht.update_saving_infos(
210
- saving_info_left, row=row, col=col
211
- )
212
- full_saving_info_right = ocht.update_saving_infos(
213
- saving_info_right, row=row, col=col
214
- )
215
-
216
- # get window and overlaps
217
- window_left = epipolar_images_left.tiling_grid[
218
- row, col, :
219
- ]
220
- window_right = epipolar_images_right.tiling_grid[
221
- row, col, :
222
- ]
223
- overlap_left = epipolar_images_left.overlaps[
224
- row, col, :
225
- ]
226
- overlap_right = epipolar_images_right.overlaps[
227
- row, col, :
228
- ]
229
-
230
- # Compute bbox
231
- (
232
- left_bbox_cars_ds[row, col],
233
- right_bbox_cars_ds[row, col],
234
- ) = self.orchestrator.cluster.create_task(
235
- compute_mask_bboxes_wrapper, nout=2
236
- )(
237
- epipolar_images_left[row, col],
238
- epipolar_images_right[row, col],
239
- window_left,
240
- window_right,
241
- overlap_left,
242
- overlap_right,
243
- classification,
244
- saving_info_left=full_saving_info_left,
245
- saving_info_right=full_saving_info_right,
246
- )
247
- else:
248
- logging.error(
249
- "CloudToBbox application doesn't "
250
- "support this input data format"
251
- )
252
-
253
- return left_bbox_cars_ds, right_bbox_cars_ds
254
-
255
-
256
- def compute_mask_bboxes_wrapper(
257
- left_image_dataset,
258
- right_image_dataset,
259
- window_left,
260
- window_right,
261
- overlap_left,
262
- overlap_right,
263
- classification,
264
- margin=20,
265
- saving_info_left=None,
266
- saving_info_right=None,
267
- ):
268
- """
269
- Compute mask bounding boxes.
270
-
271
- :param left_image_dataset: tiled Left image
272
- - dataset with :
273
-
274
- - cst.EPI_IMAGE
275
- - cst.EPI_MSK (if given)
276
- - cst.EPI_TEXTURE (for left, if given)
277
- :type left_image_dataset: xr.Dataset
278
- - dataset with :
279
-
280
- - cst.EPI_IMAGE
281
- - cst.EPI_MSK (if given)
282
- - cst.EPI_TEXTURE (for left, if given)
283
- :param right_image_dataset: tiled Right image
284
- :type right_image_dataset: xr.Dataset
285
- :param window_left: left window
286
- :type window_left: dict
287
- :param window_right: right window
288
- :type window_right: dict
289
- :param overlap_left: left overlpas
290
- :type overlap_left: dict
291
- :param overlap_right: right overlaps
292
- :type overlap_right: dict
293
- :param classification: mask classes to use
294
- :type classification: list(str)
295
- :param margin: margin to use
296
- :type margin: int
297
- :param saving_info_left: saving infos left
298
- :type saving_info_left: dict
299
- :param saving_info_right: saving infos right
300
- :type saving_info_right: dict
301
-
302
- :return: Left image object, Right image object (if exists)
303
-
304
- Returned objects are composed of dataset with :
305
-
306
- - cst.EPI_IMAGE
307
- - cst.EPI_MSK (if given)
308
- - cst.EPI_TEXTURE (for left, if given)
309
- """
310
-
311
- # compute offsets
312
- row_offset_left = window_left[0] - overlap_left[0]
313
- col_offset_left = window_left[2] - overlap_left[2]
314
- row_offset_right = window_right[0] - overlap_right[0]
315
- col_offset_right = window_right[2] - overlap_right[2]
316
-
317
- bbox_left = {}
318
-
319
- if left_image_dataset is not None:
320
- bbox_left = hole_detection_algo.localize_masked_areas(
321
- left_image_dataset,
322
- classification,
323
- row_offset=row_offset_left,
324
- col_offset=col_offset_left,
325
- margin=margin,
326
- )
327
-
328
- bbox_right = {}
329
-
330
- if right_image_dataset is not None:
331
- bbox_right = hole_detection_algo.localize_masked_areas(
332
- right_image_dataset,
333
- classification,
334
- row_offset=row_offset_right,
335
- col_offset=col_offset_right,
336
- margin=margin,
337
- )
338
-
339
- # add saving infos
340
- bbox_left_dict = cars_dict.CarsDict({"list_bbox": bbox_left})
341
- cars_dataset.fill_dict(bbox_left_dict, saving_info=saving_info_left)
342
-
343
- bbox_right_dict = cars_dict.CarsDict({"list_bbox": bbox_right})
344
- cars_dataset.fill_dict(bbox_right_dict, saving_info=saving_info_right)
345
-
346
- return bbox_left_dict, bbox_right_dict
@@ -1,144 +0,0 @@
1
- #!/usr/bin/env python
2
- # coding: utf8
3
- #
4
- # Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
5
- #
6
- # This file is part of CARS
7
- # (see https://github.com/CNES/cars).
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- """
21
- This module contains function for holes detection.
22
- """
23
- # pylint: disable=too-many-lines
24
-
25
- import logging
26
-
27
- # Standard imports
28
- from typing import List
29
-
30
- # Third party imports
31
- import numpy as np
32
- import rasterio
33
- import rasterio.features
34
- import xarray as xr
35
- from affine import Affine
36
- from scipy.ndimage import binary_dilation, generate_binary_structure, label
37
- from shapely.geometry import Polygon
38
-
39
- from cars.applications.hole_detection import (
40
- hole_detection_wrappers as hole_wrap,
41
- )
42
- from cars.core import constants as cst
43
-
44
-
45
- def get_roi_coverage_as_poly_with_margins(
46
- msk_values: np.ndarray, row_offset=0, col_offset=0, margin=0
47
- ) -> List[Polygon]:
48
- """
49
- Finds all roi existing in binary msk and stores their coverage as
50
- list of Polygon
51
-
52
- :param msk_values: msk layer of left/right epipolar image dataset
53
- :type msk_values: np.ndarray
54
- :param row_offset: offset on row to apply
55
- :type row_offset: int
56
- :param col_offset: offset on col to apply
57
- :type col_offset: int
58
- :param margin: margin added to bbox in case masked region is
59
- localized at tile border (to ensure later disparity values
60
- at mask border extraction)
61
- :type margin: int
62
-
63
- :return: list of polygon
64
-
65
- """
66
-
67
- bbox = []
68
- coord_shapes = []
69
- # Check if at least one masked area in roi
70
- if np.sum(msk_values) != 0:
71
- msk_values_dil = msk_values
72
- if margin != 0:
73
- # Dilates areas in mask according to parameter 'margin' in order
74
- # to get enough disparity values if region is near a tile border
75
- # 1. Generates a structuring element that will consider features
76
- # connected even if they touch diagonally
77
- struct = generate_binary_structure(2, 2)
78
- # 2. Dilation operation
79
- msk_values_dil = binary_dilation(
80
- msk_values, structure=struct, iterations=margin
81
- )
82
- labeled_array, __ = label(np.array(msk_values_dil).astype("int"))
83
- shapes = rasterio.features.shapes(
84
- labeled_array,
85
- transform=Affine(1.0, 0.0, 0.0, 0.0, 1.0, 0.0),
86
- )
87
- for geometry, value in shapes:
88
- if value != 0:
89
- # Get polygon coordinates of labelled region
90
- coords = geometry["coordinates"][0]
91
- coords = [
92
- (c[1] + row_offset, c[0] + col_offset) for c in coords
93
- ]
94
- coord_shapes.append(coords)
95
- bbox.extend([Polygon(c) for c in coord_shapes])
96
- return bbox
97
-
98
-
99
- def localize_masked_areas(
100
- dataset: xr.Dataset,
101
- classification: List[str],
102
- row_offset: int = 0,
103
- col_offset: int = 0,
104
- margin: int = 0,
105
- ) -> np.ndarray:
106
- """
107
- Calculates bbox of masked region(s) if mask exists for
108
- input image file (see configuration "mask" and "mask_classes"
109
- in input .json configuration file)
110
-
111
- :param dataset: epipolar image dataset
112
- :type dataset: CarsDataset
113
- :param classification: label of masked region to use
114
- :type classification: List of str
115
- :param row_offset: offset on row to apply
116
- :type row_offset: int
117
- :param col_offset: offset on col to apply
118
- :type col_offset: int
119
- :param margin: margin added to bbox in case masked region is
120
- localized at tile border (to ensure later disparity values
121
- at mask border extraction)
122
- :type margin: int
123
-
124
- :return: bounding box of masked area(s)
125
-
126
- """
127
- # binarize msk layer of epipolar image dataset
128
- # 0: 'valid' data, 1: masked data according to key_id
129
- if cst.EPI_CLASSIFICATION not in dataset:
130
- logging.debug("No classif provided")
131
- bbox = []
132
- else:
133
- if not isinstance(classification, list):
134
- logging.error("no mask classes provided for DisparityFilling")
135
- raise RuntimeError("no mask classes provided for DisparityFilling")
136
- msk_values = hole_wrap.classif_to_stacked_array(dataset, classification)
137
- # Finds roi in msk and stores its localization as polygon list
138
- bbox = get_roi_coverage_as_poly_with_margins(
139
- msk_values,
140
- row_offset=row_offset,
141
- col_offset=col_offset,
142
- margin=margin,
143
- )
144
- return bbox
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env python
2
- # coding: utf8
3
- #
4
- # Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
5
- #
6
- # This file is part of CARS
7
- # (see https://github.com/CNES/cars).
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- """
21
- This module contains function for holes detection.
22
- """
23
-
24
- # Third party imports
25
- import numpy as np
26
-
27
- from cars.core import constants as cst
28
-
29
-
30
- def classif_to_stacked_array(disp_map, class_index):
31
- """
32
- Convert disparity dataset to mask correspoding to all classes
33
-
34
- :param disp_map: disparity dataset
35
- :type disp_map: xarray Dataset
36
- :param class_index: classification tags
37
- :type class_index: list of str
38
-
39
- """
40
-
41
- index_class = np.where(
42
- np.isin(
43
- np.array(disp_map.coords[cst.BAND_CLASSIF].values),
44
- np.array(class_index),
45
- )
46
- )[0].tolist()
47
- # get index for each band classification of the non zero values
48
- stack_index = np.any(
49
- disp_map[cst.EPI_CLASSIFICATION].values[index_class, :, :] > 0,
50
- axis=0,
51
- )
52
-
53
- return stack_index