wsipipe.utils package

Utility functions that are used throughout the package.

convert module

Functionality for converting between formats.

invert(d)[source]
Parameters:

d (Dict) –

Return type:

Dict

np_to_pil(arr)[source]

Convert a Numpy array into a PIL image

Parameters:

arr (numpy.ndarray) – a Numpy array

Returns:

the PIL image

Return type:

Image

pil_to_np(image)[source]

Convert a PIL image into a Numpy array

Parameters:

image (Image) – the PIL image

Returns:

a Numpy array

Return type:

numpy.ndarray

remove_item_from_dict(dict_in, key_to_remove)[source]

remove one key value pair from a dictionary by specifying the key to remove :param dict_in: dictionary to remove an item from :param key_to_remove: the key of the key value pair to be removed

Returns:

the dictionary without the specified item

Parameters:
  • dict_in (dict) –

  • key_to_remove (str) –

Return type:

dict

to_frame_with_locations(array, value_name='value')[source]

Create a data frame with row and column locations for every value in the 2D array :param array: a Numpy array :param value_name: a string with the column name for the array values to be output in

Returns:

a pandas data frame of row, column, value where each value is the value of np array at row, column

Parameters:
  • array (numpy.ndarray) –

  • value_name (str) –

Return type:

pandas.DataFrame

filters module

pool2d(A, kernel_size, stride, padding, pool_mode='max')[source]

2D Pooling Taken from https://stackoverflow.com/questions/54962004/implement-max-mean-poolingwith-stride-with-numpy :param A: input 2D array :param kernel_size: int, the size of the window :param stride: int, the stride of the window :param padding: int, implicit zero paddings on both sides of the input :param pool_mode: string, ‘max’ or ‘avg’

geometry module

class Address(row, col)[source]

Bases: tuple

a row and column point

Parameters:
  • row (int) –

  • col (int) –

property col

Alias for field number 1

property row

Alias for field number 0

class Point(x, y)[source]

Bases: tuple

an x y point in integers

Parameters:
  • x (int) –

  • y (int) –

property x

Alias for field number 0

property y

Alias for field number 1

class PointF(x, y)[source]

Bases: tuple

an x y point in floating numbers

Parameters:
  • x (float) –

  • y (float) –

property x

Alias for field number 0

property y

Alias for field number 1

class Shape(num_rows, num_cols)[source]

Bases: tuple

chape given by rows and columns

Parameters:
  • num_rows (int) –

  • num_cols (int) –

as_size()[source]
property num_cols

Alias for field number 1

property num_rows

Alias for field number 0

class Size(width, height)[source]

Bases: tuple

size given by width and height

Parameters:
  • width (int) –

  • height (int) –

as_shape()[source]
property height

Alias for field number 1

property width

Alias for field number 0