diff --git a/cars/applications/rasterization/rasterization_tools.py b/cars/applications/rasterization/rasterization_tools.py index 405e0606..b3a83ac2 100644 --- a/cars/applications/rasterization/rasterization_tools.py +++ b/cars/applications/rasterization/rasterization_tools.py @@ -867,21 +867,23 @@ def update_data( old_valid = old_weights != 0 both_valid = np.logical_and(current_valid, old_valid) - total_weight = np.zeros(shape) - total_weight[both_valid] = weights[both_valid] + old_weights[both_valid] + total_weights = np.zeros(shape) + total_weights[both_valid] = ( + weights[both_valid] + old_weights[both_valid] + ) # current factor current_factor = np.zeros(shape) current_factor[current_valid] = 1 current_factor[both_valid] = ( - weights[both_valid] / total_weight[both_valid] + weights[both_valid] / total_weights[both_valid] ) # old factor old_factor = np.zeros(shape) old_factor[old_valid] = 1 old_factor[both_valid] = ( - old_weights[both_valid] / total_weight[both_valid] + old_weights[both_valid] / total_weights[both_valid] ) # assign old weights @@ -900,6 +902,10 @@ def update_data( new_data[old_valid] = old_data[old_valid] new_data[current_valid] += current_data[current_valid] + # round result if saved as integer + if np.issubdtype(current_data.dtype, np.integer): + new_data = np.round(new_data).astype(current_data.dtype) + # set nodata all_nodata = (current_valid + old_valid) == 0 new_data[all_nodata] = nodata diff --git a/cars/applications/rasterization/simple_gaussian.py b/cars/applications/rasterization/simple_gaussian.py index a4a113d4..1d597a3e 100644 --- a/cars/applications/rasterization/simple_gaussian.py +++ b/cars/applications/rasterization/simple_gaussian.py @@ -812,6 +812,7 @@ def run( # noqa: C901 function is too complex sigma=self.sigma, dsm_no_data=self.dsm_no_data, color_no_data=self.color_no_data, + color_dtype=color_dtype, msk_no_data=self.msk_no_data, source_pc_names=source_pc_names, ) @@ -848,6 +849,7 @@ def run( # noqa: C901 function is too complex sigma=self.sigma, dsm_no_data=self.dsm_no_data, color_no_data=self.color_no_data, + color_dtype=color_dtype, msk_no_data=self.msk_no_data, source_pc_names=source_pc_names, ) @@ -872,6 +874,7 @@ def rasterization_wrapper( radius: int = 1, dsm_no_data: int = np.nan, color_no_data: int = np.nan, + color_dtype: str = "float32", msk_no_data: int = 255, source_pc_names=None, ): @@ -1030,13 +1033,14 @@ def rasterization_wrapper( ) # Fill raster + attributes = {"color_type": color_dtype} if raster is not None: cars_dataset.fill_dataset( raster, saving_info=saving_info, window=window, profile=profile, - attributes=None, + attributes=attributes, overlaps=None, ) @@ -1062,8 +1066,10 @@ def raster_final_function(orchestrator, future_object): rasterization_step.update_weights(old_weights, weights), weights.shape ) - # Get data dsm + # Get color type + color_type = future_object.attrs["attributes"]["color_type"] + # Get data dsm for tag in future_object.keys(): if tag != cst.RASTER_WEIGHTS_SUM: @@ -1076,12 +1082,15 @@ def raster_final_function(orchestrator, future_object): cst.RASTER_SOURCE_PC, ]: method = "bool" - else: method = "basic" old_data, nodata_raster = orchestrator.get_data(tag, future_object) current_data = future_object[tag].values + if tag == cst.RASTER_COLOR_IMG and np.issubdtype( + color_type, np.integer + ): + current_data = np.round(current_data).astype(color_type) future_object[tag].values = np.reshape( rasterization_step.update_data( old_data, diff --git a/tests/data/ref_output/clr_end2end_ventoux_split_no_merging.tif b/tests/data/ref_output/clr_end2end_ventoux_split_no_merging.tif index a227a2ea..4f94d345 100644 Binary files a/tests/data/ref_output/clr_end2end_ventoux_split_no_merging.tif and b/tests/data/ref_output/clr_end2end_ventoux_split_no_merging.tif differ diff --git a/tests/data/ref_output/color_end2end_gizeh_crop_no_merging.tif b/tests/data/ref_output/color_end2end_gizeh_crop_no_merging.tif index f826f85b..b70e1f78 100644 Binary files a/tests/data/ref_output/color_end2end_gizeh_crop_no_merging.tif and b/tests/data/ref_output/color_end2end_gizeh_crop_no_merging.tif differ diff --git a/tests/data/ref_output/color_end2end_gizeh_fill.tif b/tests/data/ref_output/color_end2end_gizeh_fill.tif index a73a13db..189b8a3b 100644 Binary files a/tests/data/ref_output/color_end2end_gizeh_fill.tif and b/tests/data/ref_output/color_end2end_gizeh_fill.tif differ diff --git a/tests/data/ref_output/color_end2end_gizeh_fill_with_zero.tif b/tests/data/ref_output/color_end2end_gizeh_fill_with_zero.tif index e7166cf0..0191c691 100644 Binary files a/tests/data/ref_output/color_end2end_gizeh_fill_with_zero.tif and b/tests/data/ref_output/color_end2end_gizeh_fill_with_zero.tif differ diff --git a/tests/data/ref_output/color_end2end_paca_bulldozer.tif b/tests/data/ref_output/color_end2end_paca_bulldozer.tif index 36d9860f..eec51701 100644 Binary files a/tests/data/ref_output/color_end2end_paca_bulldozer.tif and b/tests/data/ref_output/color_end2end_paca_bulldozer.tif differ diff --git a/tests/data/ref_output/color_end2end_paca_matches_filling.tif b/tests/data/ref_output/color_end2end_paca_matches_filling.tif index 8c419c9d..ac253976 100644 Binary files a/tests/data/ref_output/color_end2end_paca_matches_filling.tif and b/tests/data/ref_output/color_end2end_paca_matches_filling.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux.tif b/tests/data/ref_output/color_end2end_ventoux.tif index 5106e7d5..1e50cc21 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux.tif and b/tests/data/ref_output/color_end2end_ventoux.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_egm96.tif b/tests/data/ref_output/color_end2end_ventoux_egm96.tif index 5106e7d5..1e50cc21 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_egm96.tif and b/tests/data/ref_output/color_end2end_ventoux_egm96.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_egm96_custom_geoid.tif b/tests/data/ref_output/color_end2end_ventoux_egm96_custom_geoid.tif index f7a65034..b5959240 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_egm96_custom_geoid.tif and b/tests/data/ref_output/color_end2end_ventoux_egm96_custom_geoid.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_no_elevation.tif b/tests/data/ref_output/color_end2end_ventoux_no_elevation.tif index 439956d9..1f089eee 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_no_elevation.tif and b/tests/data/ref_output/color_end2end_ventoux_no_elevation.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_no_srtm.tif b/tests/data/ref_output/color_end2end_ventoux_no_srtm.tif index 8ece5bc4..c00e1af9 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_no_srtm.tif and b/tests/data/ref_output/color_end2end_ventoux_no_srtm.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_quality_stats.tif b/tests/data/ref_output/color_end2end_ventoux_quality_stats.tif index 11359b1f..e6f72fe1 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_quality_stats.tif and b/tests/data/ref_output/color_end2end_ventoux_quality_stats.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_split_4326.tif b/tests/data/ref_output/color_end2end_ventoux_split_4326.tif index e25fdc70..f62f9be3 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_split_4326.tif and b/tests/data/ref_output/color_end2end_ventoux_split_4326.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_with_color.tif b/tests/data/ref_output/color_end2end_ventoux_with_color.tif index c6599578..84695425 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_with_color.tif and b/tests/data/ref_output/color_end2end_ventoux_with_color.tif differ diff --git a/tests/data/ref_output/color_end2end_ventoux_with_snap_to_img1.tif b/tests/data/ref_output/color_end2end_ventoux_with_snap_to_img1.tif index 70721eee..44fb5d34 100644 Binary files a/tests/data/ref_output/color_end2end_ventoux_with_snap_to_img1.tif and b/tests/data/ref_output/color_end2end_ventoux_with_snap_to_img1.tif differ diff --git a/tests/data/ref_output/dsm_end2end_ventoux_quality_stats.tif b/tests/data/ref_output/dsm_end2end_ventoux_quality_stats.tif index 6afe8e18..cf8964fd 100644 Binary files a/tests/data/ref_output/dsm_end2end_ventoux_quality_stats.tif and b/tests/data/ref_output/dsm_end2end_ventoux_quality_stats.tif differ diff --git a/tests/data/ref_output/dsm_mean_end2end_ventoux_quality_stats.tif b/tests/data/ref_output/dsm_mean_end2end_ventoux_quality_stats.tif index 08aa8dcb..fea7a221 100644 Binary files a/tests/data/ref_output/dsm_mean_end2end_ventoux_quality_stats.tif and b/tests/data/ref_output/dsm_mean_end2end_ventoux_quality_stats.tif differ diff --git a/tests/data/ref_output/dsm_n_pts_end2end_ventoux_quality_stats.tif b/tests/data/ref_output/dsm_n_pts_end2end_ventoux_quality_stats.tif index bf1ec609..0e33d65f 100644 Binary files a/tests/data/ref_output/dsm_n_pts_end2end_ventoux_quality_stats.tif and b/tests/data/ref_output/dsm_n_pts_end2end_ventoux_quality_stats.tif differ diff --git a/tests/data/ref_output/dsm_pts_in_cell_end2end_ventoux_quality_stats.tif b/tests/data/ref_output/dsm_pts_in_cell_end2end_ventoux_quality_stats.tif index 7121bca8..cb380d59 100644 Binary files a/tests/data/ref_output/dsm_pts_in_cell_end2end_ventoux_quality_stats.tif and b/tests/data/ref_output/dsm_pts_in_cell_end2end_ventoux_quality_stats.tif differ diff --git a/tests/data/ref_output/dsm_std_end2end_ventoux_quality_stats.tif b/tests/data/ref_output/dsm_std_end2end_ventoux_quality_stats.tif index 5d2e1503..25fc9a19 100644 Binary files a/tests/data/ref_output/dsm_std_end2end_ventoux_quality_stats.tif and b/tests/data/ref_output/dsm_std_end2end_ventoux_quality_stats.tif differ diff --git a/tests/test_end2end.py b/tests/test_end2end.py index 5af25a63..505bf8c0 100644 --- a/tests/test_end2end.py +++ b/tests/test_end2end.py @@ -2926,8 +2926,6 @@ def test_end2end_ventoux_with_color(): input_config_dense_dsm["pipeline"] = "sensors_to_dense_dsm" input_config_dense_dsm["output"]["product_level"] = ["dsm"] - print(json.dumps(input_config_dense_dsm, indent=4)) - dense_dsm_pipeline = default.DefaultPipeline(input_config_dense_dsm) dense_dsm_pipeline.run() @@ -3663,7 +3661,6 @@ def test_end2end_quality_stats(): # Save all intermediate data and add merging input_config_dense_dsm["advanced"] = { "save_intermediate_data": True, - "merging": True, } dense_dsm_pipeline = default.DefaultPipeline(input_config_dense_dsm) @@ -4294,8 +4291,6 @@ def test_end2end_paca_with_mask(): resolution = 0.5 input_config_dense_dsm["output"]["resolution"] = resolution - print(json.dumps(input_config_dense_dsm, indent=4)) - dense_dsm_pipeline_bulldozer = default.DefaultPipeline( input_config_dense_dsm )