Skip to content

Commit

Permalink
Merge branch 'fix-get-coordinates-static' into 'release'
Browse files Browse the repository at this point in the history
fix: update the get_coordinates method to static method

See merge request 3d/PandoraBox/pandora!369
  • Loading branch information
lecontm committed Nov 26, 2024
2 parents 6a02707 + bf0a1c5 commit c472dee
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pandora/matching_cost/matching_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def compute_cost_volume(
:rtype: xarray.Dataset
"""

def get_coordinates(self, margin: int, img_coordinates: np.ndarray, step: int) -> np.ndarray:
@staticmethod
def get_coordinates(margin: int, img_coordinates: np.ndarray, step: int) -> np.ndarray:
"""
In the case of a ROI, computes the right coordinates to be sure to process the first point of the ROI.
Expand All @@ -273,7 +274,7 @@ def get_coordinates(self, margin: int, img_coordinates: np.ndarray, step: int) -
:rtype: np.ndarray
"""

index_compute_col = np.arange(img_coordinates[0], img_coordinates[-1] + 1, step) # type: np.ndarray
index_compute = np.arange(img_coordinates[0], img_coordinates[-1] + 1, step) # type: np.ndarray

# Check if the first column of roi is inside the final CV (with the step)
if margin % step != 0:
Expand All @@ -289,7 +290,7 @@ def get_coordinates(self, margin: int, img_coordinates: np.ndarray, step: int) -
# Our starting point would be at index left_margin = 2 --> starting point = 1st point of ROI
# We are directly on the first point to compute

index_compute_col = np.arange(img_coordinates[0] + margin, img_coordinates[-1] + 1, step)
index_compute = np.arange(img_coordinates[0] + margin, img_coordinates[-1] + 1, step)
else:
# For example, given left_margin = 3 and step = 2
#
Expand All @@ -314,10 +315,10 @@ def get_coordinates(self, margin: int, img_coordinates: np.ndarray, step: int) -
# With a step of 3, the first point of ROI is calculated without cropping margins too much

# give the number of the first column to compute
start = step - (self.find_nearest_multiple_of_step(margin, step) - margin)
index_compute_col = np.arange(img_coordinates[0] + start, img_coordinates[-1] + 1, step)
start = step - (AbstractMatchingCost.find_nearest_multiple_of_step(margin, step) - margin)
index_compute = np.arange(img_coordinates[0] + start, img_coordinates[-1] + 1, step)

return index_compute_col
return index_compute

def grid_estimation(
self, img: xr.Dataset, cfg: Union[Dict[str, dict], None], disparity_grids: Tuple[np.ndarray, np.ndarray]
Expand Down Expand Up @@ -602,7 +603,8 @@ def get_min_max_from_grid(disp_min: np.ndarray, disp_max: np.ndarray) -> Tuple[i
"""
return int(np.nanmin(disp_min)), int(np.nanmax(disp_max))

def find_nearest_multiple_of_step(self, value: int, step: int) -> int:
@staticmethod
def find_nearest_multiple_of_step(value: int, step: int) -> int:
"""
In case value is not a multiple of step, find nearest greater value for which it is the case.
Expand Down

0 comments on commit c472dee

Please sign in to comment.