fovi.utils.image

fovi.utils.image.fig_to_frame(fig)[source]

Convert a matplotlib figure to a numpy array frame.

Renders the figure to an RGB buffer and converts it to a numpy array suitable for video creation or image processing.

Parameters:

fig (matplotlib.figure.Figure) – The matplotlib figure to convert.

Returns:

RGB image array of shape (H, W, 3) with dtype uint8.

Return type:

np.ndarray

fovi.utils.image.plotly_fig_to_frame(fig)[source]

Convert a plotly figure to a PIL Image frame.

Saves the figure to a temporary PNG file and reads it back as a PIL Image.

Parameters:

fig (plotly.graph_objects.Figure) – The plotly figure to convert.

Returns:

The figure as a PIL Image.

Return type:

PIL.Image.Image

fovi.utils.image.resize_image_fixed_aspect(image, target_width=None, target_height=None)[source]

Resize an image while preserving aspect ratio.

Resizes the image to match either the target width or target height, computing the other dimension to maintain the original aspect ratio.

Parameters:
  • image (PIL.Image.Image) – The image to resize.

  • target_width (int, optional) – Desired width. If provided, height is computed to maintain aspect ratio. Defaults to None.

  • target_height (int, optional) – Desired height. If provided, width is computed to maintain aspect ratio. Defaults to None.

Returns:

The resized image.

Return type:

PIL.Image.Image

Raises:

ValueError – If neither target_width nor target_height is specified.

fovi.utils.image.save_frames_as_video(frames, output_path, fps=2)[source]

Save a list of frames as a video file.

Parameters:
  • frames (list) – List of frames, each either a numpy array or PIL.Image.

  • output_path (str) – Path to save the output video file.

  • fps (int, optional) – Frames per second for the video. Defaults to 2.

fovi.utils.image.crop_frame(frame, left=0.05, right=0.95, top=0.1, bottom=0.9)[source]

Crop frame using normalized coordinates from edges.

Parameters:
  • frame – Input frame/image array

  • left – Left edge position in normalized coords (0-1)

  • right – Right edge position in normalized coords (0-1)

  • top – Top edge position in normalized coords (0-1)

  • bottom – Bottom edge position in normalized coords (0-1)

Returns:

Cropped frame array