Skip to content

Commit

Permalink
Update visuals.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-migas committed Sep 25, 2024
1 parent 940e49d commit 110ff3e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/koyo/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import matplotlib.pyplot as plt
import numba as nb
import numpy as np
from koyo.typing import PathLike

from koyo.image import clip_hotspots
from koyo.utilities import is_above_version
Expand Down Expand Up @@ -44,6 +45,20 @@ def close_pil_image(fig: Image) -> None:
del fig


def save_rgb(path: PathLike, image: np.ndarray) -> None:
"""Save image a RGB using PIL."""
from PIL import Image

Image.fromarray(image).save(path)


def save_gray(path: PathLike, image: np.ndarray, multiplier: int = 255) -> None:
"""Save image as grayscale using PIL."""
from PIL import Image

Image.fromarray(image * multiplier).convert("L").save(path)


def set_tick_fmt(ax: plt.Axes, use_offset: bool = False, axis: str = "both") -> plt.Axes:
"""Set tick format to control whether scientific notation is shown."""
ax.ticklabel_format(axis=axis, style="scientific" if use_offset else "plain", useOffset=use_offset)
Expand Down

0 comments on commit 110ff3e

Please sign in to comment.