zensvi.transform.ImageTransformer

class zensvi.transform.ImageTransformer(dir_input: str | pathlib.Path, dir_output: str | pathlib.Path, log_path: str | pathlib.Path = None, verbosity: int = 1)

Transforms images by applying various projections such as fisheye and perspective adjustments.

Parameters:
  • dir_input (Union[str, Path]) – Input directory containing images.

  • dir_output (Union[str, Path]) – Output directory where transformed images will be saved.

Raises:

TypeError – If the input or output directories are not specified as string or Path objects.

property dir_input

Property for the input directory.

Returns:

dir_input

Return type:

Path

property dir_output

Property for the output directory.

Returns:

dir_output

Return type:

Path

perspective(img, FOV, THETA, PHI, height, width)

Transforms an image to simulate a perspective view from specific angles.

Parameters:
  • img (np.ndarray) – Source image to transform.

  • FOV (float) – Field of view in degrees.

  • THETA (float) – Rotation around the vertical axis in degrees.

  • PHI (float) – Tilt angle in degrees.

  • height (int) – Height of the output image.

  • width (int) – Width of the output image.

Returns:

Transformed image.

Return type:

np.ndarray

equidistant_fisheye(img)

Transforms an image to an equidistant fisheye projection.

Parameters:

img (np.ndarray) – Source image to transform.

Returns:

Fisheye projected image with transparent background.

Return type:

np.ndarray

orthographic_fisheye(img)

Transforms an image to an orthographic fisheye projection.

Parameters:

img (np.ndarray) – Source image to transform.

Returns:

Fisheye projected image with transparent background.

Return type:

np.ndarray

stereographic_fisheye(img)

Transforms an image to a stereographic fisheye projection.

Parameters:

img (np.ndarray) – Source image to transform.

Returns:

Fisheye projected image with transparent background.

Return type:

np.ndarray

equisolid_fisheye(img)

Transforms an image to an equisolid fisheye projection.

Parameters:

img (np.ndarray) – Source image to transform.

Returns:

Fisheye projected image with transparent background.

Return type:

np.ndarray

transform_images(style_list: str = 'perspective equidistant_fisheye orthographic_fisheye stereographic_fisheye equisolid_fisheye', FOV: int | float = 90, theta: int | float = 90, phi: int | float = 0, aspects: tuple = (9, 16), show_size: int | float = 100, use_upper_half: bool = False, verbosity: int = None)

Applies specified transformations to all images in the input directory and saves them in the output directory.

Parameters:
  • style_list (str) – Space-separated list of transformation styles to apply. Valid styles include ‘perspective’, ‘equidistant_fisheye’, ‘orthographic_fisheye’, ‘stereographic_fisheye’, and ‘equisolid_fisheye’.

  • FOV (Union[int, float], optional) – Field of view for the ‘perspective’ style in degrees.

  • theta (Union[int, float], optional) – Rotation step for generating multiple perspective images in degrees.

  • phi (Union[int, float], optional) – Tilt angle for the ‘perspective’ style in degrees.

  • aspects (tuple, optional) – Aspect ratio of the output images represented as a tuple.

  • show_size (Union[int, float], optional) – Base size to calculate the dimensions of the output images.

  • use_upper_half (bool, optional) – If True, only the upper half of the image is used for fisheye transformations.

  • verbosity (int, optional) – Level of verbosity for progress bars (0=no progress bars, 1=outer loops only, 2=all loops). If None, uses the instance’s verbosity level.

Raises:

ValueError – If an invalid style is specified in style_list.

Notes

This method processes images concurrently, leveraging multi-threading to speed up the transformation tasks. It automatically splits style_list into individual styles and processes each style, creating appropriate subdirectories in the output directory for each style.