pierogis.ingredients.pierogi module

define an image wrapper ingredient

class pierogis.ingredients.pierogi.Pierogi(opacity: int = 100, mask: Optional[numpy.ndarray] = None, **kwargs)[source]

Bases: pierogis.ingredients.ingredient.Ingredient

image container for iterative pixel manipulation

create a Pierogi from: - pixel array - video file with a frame index - image file - PIL image

unless pixels are provided explicitly ( Pierogi(pixels=pixels) ), the pixels member is a property that is lazy loaded (usually from a file) and cached

RESIZE_RESAMPLE = 0

default resize algorithm is nearest neighbor

ROTATE_RESAMPLE = 0

default rotate algorithm is nearest neighbor

cook(pixels: numpy.ndarray) numpy.ndarray[source]

performs actions on a pixel array and returns a cooked array

classmethod from_path(path: str, frame_index: int = 0) pierogis.ingredients.pierogi.Pierogi[source]
Parameters
  • path – file path to load from

  • frame_index – if path is a multiframe format (video), use this specified frame

classmethod from_pil_image(image: PIL.Image.Image)[source]
Parameters

image – PIL Image that has already been loaded

classmethod from_shape(shape: tuple) pierogis.ingredients.pierogi.Pierogi[source]
Parameters

shape – (width, height) to make default pixels array

property height: int

2nd dimension of the underlying pixel array

property image: PIL.Image.Image

turn the numpy array into a PIL Image

load() None[source]

use the loader return the contained pixels one time

property pixels: numpy.ndarray
prep(pixels: Optional[numpy.ndarray] = None, loader: Optional[Callable[[], numpy.ndarray]] = None, **kwargs) None[source]

provide the source image in a number of ways

Parameters
  • pixels – numpy array

  • loader – function that produces a pixels array

resize(width: int, height: int, resample: int = 0)[source]

resize pixels to new width and height

Parameters
  • width – width to resize to

  • height – height to resize to

  • resample – resample method to use in Image.resize.

PIL documentation:

> “An optional resampling filter. > This can be one of PIL.Image.NEAREST (use nearest neighbour), > PIL.Image.BILINEAR (linear interpolation), > PIL.Image.BICUBIC (cubic spline interpolation), > or PIL.Image.LANCZOS (a high-quality downsampling filter). > If omitted, or if the image has mode “1” or “P”, it is set PIL.Image.NEAREST.”

rotate(angle: float, resample: int = 0)[source]

rotate underlying pixel array by an angle

Parameters
  • angle – angle to rotate

  • resample – resample method to use in Image.resize.

PIL documentation:

> “An optional resampling filter. > This can be one of PIL.Image.NEAREST (use nearest neighbour), > PIL.Image.BILINEAR (linear interpolation), > PIL.Image.BICUBIC (cubic spline interpolation), > or PIL.Image.LANCZOS (a high-quality downsampling filter). > If omitted, or if the image has mode “1” or “P”, it is set PIL.Image.NEAREST.”

save(path: Union[str, pathlib.Path], optimize: bool = False) None[source]

save the image to the given path

show() None[source]

open an image viewer to display the array

property width: int

1st dimension of the underlying pixel array