Skip to content

Commit

Permalink
Merge branch '835-le-reechantillonnage-de-la-classification-est-gourm…
Browse files Browse the repository at this point in the history
…and-en-temps-et-memoire-et-provoque-des' into 'master'

Resolve "Le rééchantillonnage de la classification est gourmand en temps et mémoire et provoque des freeze"

Closes #835

See merge request 3d/cars-park/cars!744
  • Loading branch information
dyoussef committed Oct 14, 2024
2 parents db05953 + 13b291f commit 15f1bbb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 47 deletions.
61 changes: 35 additions & 26 deletions cars/applications/resampling/bicubic_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def pre_run(
largest_epipolar_region,
)

def run(
def run( # noqa: C901
self,
sensor_image_left,
sensor_image_right,
Expand All @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -719,6 +725,7 @@ def generate_epipolar_images_wrapper(
nodata1=nodata1,
nodata2=nodata2,
add_color=add_color,
add_classif=add_classif,
)

if add_color:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cars/applications/resampling/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def run(
tile_height=None,
step=None,
add_color=True,
add_classif=True,
epipolar_roi=None,
): # noqa: C901
"""
Expand Down
44 changes: 23 additions & 21 deletions cars/applications/resampling/resampling_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"] = []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def run(self):
tile_width=None,
tile_height=None,
add_color=False,
add_classif=False,
)

# Run epipolar sparse_matching application
Expand Down

0 comments on commit 15f1bbb

Please sign in to comment.