Skip to content

Commit

Permalink
Visualize events v1
Browse files Browse the repository at this point in the history
  • Loading branch information
shiba24 committed Jun 30, 2023
1 parent 33dab67 commit d4406e8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/evlib/vis/view2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,28 @@ def optical_flow(
else:
wheel = None
return image, wheel


def events(events: np.ndarray, image_shape: tuple) -> Image.Image:
"""Visualize events with polarity color.
Args:
events (np.ndarray): _description_
image_shape (tuple): _description_
Returns:
_type_: _description_
"""
background_color = 255
image = (

Check warning on line 91 in src/evlib/vis/view2d.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/vis/view2d.py#L90-L91

Added lines #L90 - L91 were not covered by tests
np.ones((image_shape[0], image_shape[1], 3), dtype=np.uint8)
* background_color
) # RGBA channel

events[:, 0] = np.clip(events[:, 0], 0, image_shape[0] - 1)
events[:, 1] = np.clip(events[:, 1], 0, image_shape[1] - 1)

Check warning on line 97 in src/evlib/vis/view2d.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/vis/view2d.py#L96-L97

Added lines #L96 - L97 were not covered by tests
colors = np.array([(255, 0, 0) if e[3] == 1 else (0, 0, 255) for e in events])
image[events[:, 0].astype(np.int32), events[:, 1].astype(np.int32), :] = colors

Check warning on line 99 in src/evlib/vis/view2d.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/vis/view2d.py#L99

Added line #L99 was not covered by tests

image = Image.fromarray(image)
return image

Check warning on line 102 in src/evlib/vis/view2d.py

View check run for this annotation

Codecov / codecov/patch

src/evlib/vis/view2d.py#L101-L102

Added lines #L101 - L102 were not covered by tests

0 comments on commit d4406e8

Please sign in to comment.