yapocis.utils.basic

Module Contents

Classes

Stage

Shaper

Functions

byte_scale(data: Array, cmin: Optional[float] = None, cmax: Optional[float] = None, high: int = 255, low: int = 0) → Array

Byte scales an array (image).

from_image(im: PILImage, flatten: bool = False) → Array

Return a copy of a PIL image as a numpy array.

to_image(arr: Array, high: int = 255, low: int = 0, cmin: Optional[float] = None, cmax: Optional[float] = None, pal: Optional[Array] = None, mode: Optional[str] = None, channel_axis: Optional[int] = None, newaxis: Optional[int] = None) → PILImage

Takes a numpy array and returns a PIL image. The mode of the

newsize(img: PILImage, width: int, height: int, longest: int) → Tuple[(bool, int, int)]

imread(filename: str, longest: Optional[int] = None) → Array

sign(title: str, img: Union[(Array, PILImage)]) → PIL.Image

_show_array(*args)

show_array(*args)

show_arraygrad(title: str, image: Array, theta: Array, grad: Optional[Array] = None) → None

Show an array with gradient orientation and optional magnitude

histeq_large(im: Array, nbr_bins=2**16) → Array

histeq(im: Array, nbr_bins: int = 256) → Tuple[(Array, Array)]

Histogram equalization quantized to 8 bits. Appropriate for 8 bit images.

align_image(image: Array, alignment: int = ALIGNMENT) → Array

OpenCL really seems to prefer data that is aligned on quadfloat boundaries.

normalize(a: Array) → Array

Ensures that array contents are in range 0 <= elem < 1.0

set_margin(a: Array, margin: int, value: Optional[float] = 0.0) → None

Set the edges of a 2D array to a constant value

set_frame(a: Array, width: int, frame: Optional[float] = 1.0, margin: Optional[float] = 0.0) → None

chunker(data: Iterable, chunk_size: int = 100)

yapocis.utils.basic.DEBUG = False[source]
yapocis.utils.basic.byte_scale(data: Array, cmin: Optional[float] = None, cmax: Optional[float] = None, high: int = 255, low: int = 0)Array[source]

Byte scales an array (image).

Parameters
  • data (ndarray) – PIL image data array.

  • cmin (Scalar) – Bias scaling of small values, Default is data.min().

  • cmax (scalar) – Bias scaling of large values, Default is data.max().

  • high (scalar) – Scale max value to high.

  • low (scalar) – Scale min value to low.

Returns

img_array – Bytescaled array.

Return type

ndarray

Examples

>>> img = array([[ 91.06794177,   3.39058326,  84.4221549 ],
                 [ 73.88003259,  80.91433048,   4.88878881],
                 [ 51.53875334,  34.45808177,  27.5873488 ]])
>>> byte_scale(img)
array([[255,   0, 236],
       [205, 225,   4],
       [140,  90,  70]], dtype=uint8)
>>> byte_scale(img, high=200, low=100)
array([[200, 100, 192],
       [180, 188, 102],
       [155, 135, 128]], dtype=uint8)
>>> byte_scale(img, cmin=0, cmax=255)
array([[91,  3, 84],
       [74, 81,  5],
       [52, 34, 28]], dtype=uint8)
yapocis.utils.basic.from_image(im: PILImage, flatten: bool = False)Array[source]

Return a copy of a PIL image as a numpy array.

Parameters
  • im (PIL image) – Input image.

  • flatten (bool) – If true, convert the output to grey-scale.

Returns

fromimage – The different colour bands/channels are stored in the third dimension, such that a grey-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.

Return type

ndarray

yapocis.utils.basic._errstr = Mode is unknown or incompatible with input array shape.[source]
yapocis.utils.basic.to_image(arr: Array, high: int = 255, low: int = 0, cmin: Optional[float] = None, cmax: Optional[float] = None, pal: Optional[Array] = None, mode: Optional[str] = None, channel_axis: Optional[int] = None, newaxis: Optional[int] = None)PILImage[source]

Takes a numpy array and returns a PIL image. The mode of the PIL image depends on the array shape, the pal keyword, and the mode keyword.

For 2-D arrays, if pal is a valid (N,3) byte-array giving the RGB values (from 0 to 255) then mode=’P’, otherwise mode=’L’, unless mode is given as ‘F’ or ‘I’ in which case a float and/or integer array is made

For 3-D arrays, the channel_axis argument tells which dimension of the

array holds the channel data.

For 3-D arrays if one of the dimensions is 3, the mode is ‘RGB’

by default or ‘YCbCr’ if selected.

if the

The numpy array must be either 2 dimensional or 3 dimensional.

yapocis.utils.basic.newsize(img: PILImage, width: int, height: int, longest: int)Tuple[bool, int, int][source]
yapocis.utils.basic.imread(filename: str, longest: Optional[int] = None)Array[source]
class yapocis.utils.basic.Stage[source]
__call__(self, *args)[source]
yapocis.utils.basic.stage[source]
yapocis.utils.basic.sign(title: str, img: Union[Array, PILImage])PIL.Image[source]
yapocis.utils.basic._showArrayCounter = 0[source]
yapocis.utils.basic._show_array(*args)[source]
yapocis.utils.basic.show_array(*args)[source]
yapocis.utils.basic.show_arraygrad(title: str, image: Array, theta: Array, grad: Optional[Array] = None)None[source]

Show an array with gradient orientation and optional magnitude :param title: a useful title :param image: image to annotate :param theta: array of pi=1.0 angles :param grad: optional array of gradients, defaults to something visible

Returns: None

class yapocis.utils.basic.Shaper(data)[source]
update(self, data)[source]
asimage(self)[source]
asrows(self)[source]
ascols(self)[source]
yapocis.utils.basic.histeq_large(im: Array, nbr_bins=2 ** 16)Array[source]
yapocis.utils.basic.histeq(im: Array, nbr_bins: int = 256)Tuple[Array, Array][source]

Histogram equalization quantized to 8 bits. Appropriate for 8 bit images. :param im: 2d array of pixels :param nbr_bins: defaults to 256

Returns: array like im, and the cumulative density table

yapocis.utils.basic.ALIGNMENT = 4[source]
yapocis.utils.basic.align_image(image: Array, alignment: int = ALIGNMENT)Array[source]

OpenCL really seems to prefer data that is aligned on quadfloat boundaries. :param image: 2d or 3d arrau :param alignment: defaults to 4

Returns: an array whose dimensions are a multiple of alignment.

yapocis.utils.basic.normalize(a: Array)Array[source]

Ensures that array contents are in range 0 <= elem < 1.0 :param a: an array to be normalized

Returns: an array whose min and max values are 0.0 and really close to 1.0

yapocis.utils.basic.set_margin(a: Array, margin: int, value: Optional[float] = 0.0)None[source]

Set the edges of a 2D array to a constant value :param a: a 2D array :param margin: width of margin :param value: value to set, defaults to 0.0

Returns: None

yapocis.utils.basic.set_frame(a: Array, width: int, frame: Optional[float] = 1.0, margin: Optional[float] = 0.0)None[source]
yapocis.utils.basic.chunker(data: Iterable, chunk_size: int = 100)[source]