diff --git a/cars/applications/resampling/bicubic_resampling.py b/cars/applications/resampling/bicubic_resampling.py index 46107c39..d878d1ae 100644 --- a/cars/applications/resampling/bicubic_resampling.py +++ b/cars/applications/resampling/bicubic_resampling.py @@ -213,7 +213,7 @@ def pre_run( largest_epipolar_region, ) - def run( + def run( # noqa: C901 self, sensor_image_left, sensor_image_right, @@ -226,8 +226,9 @@ def run( tile_width=None, tile_height=None, add_color=True, + add_classif=True, epipolar_roi=None, - ): # noqa: C901 + ): """ Run resampling application. @@ -276,6 +277,8 @@ def run( :type tile_height: int :param add_color: add color image to dataset :type add_color: bool + :param add_classif: add classif to dataset + :type add_classif: bool :param epipolar_roi: Epipolar roi to use if set. Set None tiles outsize roi :type epipolar_roi: list(int), [row_min, row_max, col_min, col_max] @@ -437,6 +440,15 @@ def margins_fun( # pylint: disable=unused-argument dtype=np.uint8, ) + self.orchestrator.add_to_save_lists( + os.path.join(pair_folder, "epi_img_right_mask.tif"), + cst.EPI_MSK, + epipolar_images_right, + cars_ds_name="epi_img_right_mask", + dtype=np.uint8, + ) + + if self.save_intermediate_data and add_classif: self.orchestrator.add_to_save_lists( os.path.join(pair_folder, "epi_img_left_classif.tif"), cst.EPI_CLASSIFICATION, @@ -446,14 +458,6 @@ def margins_fun( # pylint: disable=unused-argument optional_data=True, ) - self.orchestrator.add_to_save_lists( - os.path.join(pair_folder, "epi_img_right_mask.tif"), - cst.EPI_MSK, - epipolar_images_right, - cars_ds_name="epi_img_right_mask", - dtype=np.uint8, - ) - self.orchestrator.add_to_save_lists( os.path.join(pair_folder, "epi_img_right_classif.tif"), cst.EPI_CLASSIFICATION, @@ -610,6 +614,7 @@ def margins_fun( # pylint: disable=unused-argument used_disp_min=used_disp_min[row, col], used_disp_max=used_disp_max[row, col], add_color=add_color, + add_classif=add_classif, color1=color1, mask1=mask1, mask2=mask2, @@ -647,6 +652,7 @@ def generate_epipolar_images_wrapper( used_disp_min=None, used_disp_max=None, add_color=True, + add_classif=True, color1=None, mask1=None, mask2=None, @@ -719,6 +725,7 @@ def generate_epipolar_images_wrapper( nodata1=nodata1, nodata2=nodata2, add_color=add_color, + add_classif=add_classif, ) if add_color: @@ -753,22 +760,24 @@ def generate_epipolar_images_wrapper( left_dataset[cst.EPI_IMAGE].attrs["color_type"] = color_types # Add classification layers to dataset - if left_classif_dataset: - left_dataset.coords[cst.BAND_CLASSIF] = left_classif_dataset.attrs[ - cst.BAND_NAMES - ] - left_dataset[cst.EPI_CLASSIFICATION] = xr.DataArray( - left_classif_dataset[cst.EPI_IMAGE].values, - dims=[cst.BAND_CLASSIF, cst.ROW, cst.COL], - ).astype(bool) - if right_classif_dataset: - right_dataset.coords[cst.BAND_CLASSIF] = right_classif_dataset.attrs[ - cst.BAND_NAMES - ] - right_dataset[cst.EPI_CLASSIFICATION] = xr.DataArray( - right_classif_dataset[cst.EPI_IMAGE].values, - dims=[cst.BAND_CLASSIF, cst.ROW, cst.COL], - ).astype(bool) + if add_classif: + if left_classif_dataset: + left_dataset.coords[cst.BAND_CLASSIF] = left_classif_dataset.attrs[ + cst.BAND_NAMES + ] + left_dataset[cst.EPI_CLASSIFICATION] = xr.DataArray( + left_classif_dataset[cst.EPI_IMAGE].values, + dims=[cst.BAND_CLASSIF, cst.ROW, cst.COL], + ).astype(bool) + if right_classif_dataset: + right_dataset.coords[cst.BAND_CLASSIF] = ( + right_classif_dataset.attrs[cst.BAND_NAMES] + ) + right_dataset[cst.EPI_CLASSIFICATION] = xr.DataArray( + right_classif_dataset[cst.EPI_IMAGE].values, + dims=[cst.BAND_CLASSIF, cst.ROW, cst.COL], + ).astype(bool) + # Add attributes info attributes = {} # fill datasets with saving info, window, profile, overlaps for correct diff --git a/cars/applications/resampling/resampling.py b/cars/applications/resampling/resampling.py index 4d99c254..30b8a0bd 100644 --- a/cars/applications/resampling/resampling.py +++ b/cars/applications/resampling/resampling.py @@ -109,6 +109,7 @@ def run( tile_height=None, step=None, add_color=True, + add_classif=True, epipolar_roi=None, ): # noqa: C901 """ diff --git a/cars/applications/resampling/resampling_tools.py b/cars/applications/resampling/resampling_tools.py index ab2f9708..5032310c 100644 --- a/cars/applications/resampling/resampling_tools.py +++ b/cars/applications/resampling/resampling_tools.py @@ -63,6 +63,7 @@ def epipolar_rectify_images( nodata1=0, nodata2=0, add_color=True, + add_classif=True, ): """ Resample left and right images, with color on left @@ -184,28 +185,29 @@ def epipolar_rectify_images( # resample the mask images left_classif_dataset = None - if classif1: - left_classif_dataset = resample_image( - classif1, - grid1, - [epipolar_size_x, epipolar_size_y], - region=left_region, - band_coords=cst.BAND_CLASSIF, - interpolator_img=interpolator_classif, - interpolator_mask=interpolator_mask, - ) - right_classif_dataset = None - if classif2: - right_classif_dataset = resample_image( - classif2, - grid2, - [epipolar_size_x, epipolar_size_y], - region=right_region, - band_coords=cst.BAND_CLASSIF, - interpolator_img=interpolator_classif, - interpolator_mask=interpolator_mask, - ) + if add_classif: + if classif1: + left_classif_dataset = resample_image( + classif1, + grid1, + [epipolar_size_x, epipolar_size_y], + region=left_region, + band_coords=cst.BAND_CLASSIF, + interpolator_img=interpolator_classif, + interpolator_mask=interpolator_mask, + ) + + if classif2: + right_classif_dataset = resample_image( + classif2, + grid2, + [epipolar_size_x, epipolar_size_y], + region=right_region, + band_coords=cst.BAND_CLASSIF, + interpolator_img=interpolator_classif, + interpolator_mask=interpolator_mask, + ) return ( left_dataset, diff --git a/cars/pipelines/sensor_to_dense_dsm/sensor_to_dense_dsm_pipeline.py b/cars/pipelines/sensor_to_dense_dsm/sensor_to_dense_dsm_pipeline.py index 93e7a3de..18bdc286 100644 --- a/cars/pipelines/sensor_to_dense_dsm/sensor_to_dense_dsm_pipeline.py +++ b/cars/pipelines/sensor_to_dense_dsm/sensor_to_dense_dsm_pipeline.py @@ -673,6 +673,7 @@ def run(self): # noqa C901 # with any order. the .1 will be performed before the .2 pairs[pair_key]["holes_classif"] = [] pairs[pair_key]["holes_poly_margin"] = 0 + add_classif = False if self.dense_matches_filling_1.used_method == "plane": pairs[pair_key][ "holes_classif" @@ -681,6 +682,7 @@ def run(self): # noqa C901 pairs[pair_key]["holes_poly_margin"], self.dense_matches_filling_1.get_poly_margin(), ) + add_classif = True if self.dense_matches_filling_2.used_method == "plane": pairs[pair_key][ "holes_classif" @@ -689,6 +691,7 @@ def run(self): # noqa C901 pairs[pair_key]["holes_poly_margin"], self.dense_matches_filling_2.get_poly_margin(), ) + add_classif = True pairs[pair_key]["holes_bbox_left"] = [] pairs[pair_key]["holes_bbox_right"] = [] @@ -717,6 +720,7 @@ def run(self): # noqa C901 tile_width=None, tile_height=None, add_color=False, + add_classif=add_classif, ) # Generate the holes polygons in epipolar images @@ -1233,6 +1237,7 @@ def run(self): # noqa C901 tile_width=optimum_tile_size, tile_height=optimum_tile_size, add_color=True, + add_classif=True, epipolar_roi=epipolar_roi, ) diff --git a/cars/pipelines/sensor_to_sparse_dsm/sensor_to_sparse_dsm_pipeline.py b/cars/pipelines/sensor_to_sparse_dsm/sensor_to_sparse_dsm_pipeline.py index 839898eb..03d63bff 100644 --- a/cars/pipelines/sensor_to_sparse_dsm/sensor_to_sparse_dsm_pipeline.py +++ b/cars/pipelines/sensor_to_sparse_dsm/sensor_to_sparse_dsm_pipeline.py @@ -370,6 +370,7 @@ def run(self): tile_width=None, tile_height=None, add_color=False, + add_classif=False, ) # Run epipolar sparse_matching application