Skip to content

Commit

Permalink
Update image.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-migas committed Dec 9, 2024
1 parent 6feaf23 commit 4fac5e7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/koyo/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,19 @@ def reshape_array_from_coordinates(

def flatten_array_from_coordinates(array: np.ndarray, coordinates: np.ndarray, offset: int = 0) -> np.ndarray:
"""Flatten array based on xy coordinates."""
try:
return array[coordinates[:, 1] - offset, coordinates[:, 0] - offset]
except IndexError:
return array[coordinates[:, 0] - offset, coordinates[:, 1] - offset]
if array.ndim == 2:
try:
return array[coordinates[:, 1] - offset, coordinates[:, 0] - offset]
except IndexError:
return array[coordinates[:, 0] - offset, coordinates[:, 1] - offset]
else:
try:
res = array[:, coordinates[:, 1] - offset, coordinates[:, 0] - offset]
except IndexError:
res = array[:, coordinates[:, 0] - offset, coordinates[:, 1] - offset]
# need to swap axes
res = np.swapaxes(res, 0, 1)
return res


def reshape_array_batch(
Expand Down

0 comments on commit 4fac5e7

Please sign in to comment.