Skip to content

Commit

Permalink
Visualize events v1 (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiba24 committed Jun 30, 2023
1 parent 33dab67 commit 01dda6d
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 = (
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)
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

image = Image.fromarray(image)
return image

0 comments on commit 01dda6d

Please sign in to comment.