|
57 | 57 | semantic_segmentation,
|
58 | 58 | )
|
59 | 59 | from pandora.margins import GlobalMargins
|
60 |
| -from pandora.img_tools import rasterio_open |
61 | 60 |
|
62 | 61 | from pandora.criteria import validity_mask
|
63 | 62 |
|
@@ -315,9 +314,19 @@ def matching_cost_prepare(self, cfg: Dict[str, dict], input_step: str) -> None:
|
315 | 314 | self.right_disp_min = self.right_disp_min * self.scale_factor
|
316 | 315 | self.right_disp_max = self.right_disp_max * self.scale_factor
|
317 | 316 |
|
318 |
| - self.right_cv = self.matching_cost_.allocate_cost_volume( |
319 |
| - self.right_img, (self.right_disp_min, self.right_disp_max), cfg |
320 |
| - ) |
| 317 | + if self.right_disp_map == "cross_checking_accurate": |
| 318 | + # allocate the cost volume the standard way |
| 319 | + self.right_cv = self.matching_cost_.allocate_cost_volume( |
| 320 | + self.right_img, (self.right_disp_min, self.right_disp_max), cfg |
| 321 | + ) |
| 322 | + |
| 323 | + elif self.right_disp_map == "cross_checking_fast": |
| 324 | + # the right cv may have a different size from left cv if created from its disp range |
| 325 | + # (ex: with the test disparity grids) |
| 326 | + # create it from the left disps instead, to match the left cv's size |
| 327 | + self.right_cv = self.matching_cost_.allocate_cost_volume( |
| 328 | + self.right_img, (-self.disp_max, -self.disp_min), cfg |
| 329 | + ) |
321 | 330 |
|
322 | 331 | # Compute validity mask to identify invalid points in cost volume
|
323 | 332 | self.right_cv = validity_mask(self.right_img, self.left_img, self.right_cv)
|
@@ -426,7 +435,7 @@ def disparity_run(self, cfg: Dict[str, dict], input_step: str) -> None:
|
426 | 435 | # Fast cross checking is used, compute right cv at wta time
|
427 | 436 | # Compute right cost volume and mask it
|
428 | 437 | self.right_cv["cost_volume"].data = matching_cost.AbstractMatchingCost.reverse_cost_volume(
|
429 |
| - self.left_cv["cost_volume"].data, self.right_disp_min.min() |
| 438 | + self.left_cv["cost_volume"].data, np.nanmin(self.right_disp_min) |
430 | 439 | )
|
431 | 440 |
|
432 | 441 | self.right_cv.attrs["type_measure"] = self.left_cv.attrs["type_measure"]
|
@@ -638,8 +647,10 @@ def run_prepare(
|
638 | 647 | self.right_disp_min = right_img["disparity"].sel(band_disp="min").data
|
639 | 648 | self.right_disp_max = right_img["disparity"].sel(band_disp="max").data
|
640 | 649 | else:
|
641 |
| - self.right_disp_min = -left_img["disparity"].sel(band_disp="max").data |
642 |
| - self.right_disp_max = -left_img["disparity"].sel(band_disp="min").data |
| 650 | + # Right disparities : always infered from left disparities |
| 651 | + self.right_disp_min, self.right_disp_max = matching_cost.AbstractMatchingCost.reverse_disp_range( |
| 652 | + self.disp_min, self.disp_max |
| 653 | + ) |
643 | 654 |
|
644 | 655 | # Initiate output disparity datasets
|
645 | 656 | self.left_disparity = xr.Dataset()
|
@@ -875,31 +886,11 @@ def validation_check_conf(self, cfg: Dict[str, dict], input_step: str) -> None:
|
875 | 886 | # If both disp bounds are lists, check that they add up
|
876 | 887 | if isinstance(ds_left, list) and isinstance(ds_right, list):
|
877 | 888 | if ds_left[0] != -ds_right[1] or ds_left[1] != -ds_right[0]:
|
878 |
| - raise AttributeError( |
879 |
| - "The cross-checking step can't be processed if disp_min, disp_max, disp_right_min, disp_right_max " |
880 |
| - "are all ints and disp_min != -disp_right_max or disp_max != -disp_right_min" |
881 |
| - ) |
| 889 | + raise AttributeError("disp_min != -disp_right_max or disp_max != -disp_right_min") |
882 | 890 |
|
883 |
| - # If both disp bounds are strs, check that their global min/max adds up |
| 891 | + # If both disp bounds are strs, warn that the right disp will be ignored |
884 | 892 | elif isinstance(ds_left, str) and isinstance(ds_right, str):
|
885 |
| - left_img = rasterio_open(ds_left).read() |
886 |
| - right_img = rasterio_open(ds_right).read() |
887 |
| - |
888 |
| - left_min = left_img.min() |
889 |
| - left_max = left_img.max() |
890 |
| - right_min = right_img.min() |
891 |
| - right_max = right_img.max() |
892 |
| - |
893 |
| - if left_min != -right_max or left_max != -right_min: |
894 |
| - raise AttributeError( |
895 |
| - "The cross-checking step can't be processed if " |
896 |
| - "disp_min != -disp_right_max or disp_max != -disp_right_min" |
897 |
| - ) |
898 |
| - |
899 |
| - elif type(ds_left) != type(ds_right) and ds_left is not None and ds_right is not None: |
900 |
| - raise AttributeError( |
901 |
| - "The cross-checking step does not support left and right disparities of different kinds at this time." |
902 |
| - ) |
| 893 | + logging.warning("The right disp will be ignored, and instead computed from the left disp.") |
903 | 894 |
|
904 | 895 | def multiscale_check_conf(self, cfg: Dict[str, dict], input_step: str) -> None:
|
905 | 896 | """
|
|
0 commit comments