pad#

Functions#

remove_padding(arr, c)

Remove padding by c

add_padding(arr, c, val)

Remove padding by c

pad_by_visual_size(img, padding, ppd[, ...])

Pad image by specified degrees of visual angle

pad_to_visual_size(img, visual_size, ppd[, ...])

Pad image to specified visual size in degrees visual angle

pad_by_shape(img, padding[, pad_value])

Pad image by specified amount(s) of pixels

pad_to_shape(img, shape[, pad_value])

Pad image to a resulting specified shape in pixels

pad_dict_by_visual_size(dct, padding, ppd[, ...])

Pad images in dictionary by specified degrees of visual angle

pad_dict_to_visual_size(dct, visual_size, ppd)

Pad images in dictionary to specified visual size in degrees visual angle

pad_dict_by_shape(dct, padding[, pad_value, ...])

Pad images in dictionary by specified amount(s) of pixels Can specify different amount (before, after) each axis.

pad_dict_to_shape(dct, shape[, pad_value, keys])

Pad images in dictionary to a resulting specified shape in pixels

stimupy.utils.pad.remove_padding(arr, c)[source]#

Remove padding by c

Parameters:
Returns:

arr – reduced array

Return type:

numpy.ndarray

stimupy.utils.pad.add_padding(arr, c, val)[source]#

Remove padding by c

Parameters:
Returns:

arr – padded array

Return type:

numpy.ndarray

stimupy.utils.pad.pad_by_visual_size(img, padding, ppd, pad_value=0.0)[source]#

Pad image by specified degrees of visual angle

Can specify different amount (before, after) each axis.

Parameters:
  • img (numpy.ndarray) – image-array to be padded

  • padding (float, or Sequence[float, float], or Sequence[Sequence[float, float], ...]) – amount of padding, in degrees visual angle, in each direction: ((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis (float,) or float is a shortcut for before = after = pad width for all axes.

  • ppd (Sequence[Number] or Sequence[Number, Number]) – pixels per degree

  • pad_value (Numeric, optional) – value to pad with, by default 0.0

Returns:

img padded by the specified amount(s)

Return type:

numpy.ndarray

stimupy.utils.pad.pad_to_visual_size(img, visual_size, ppd, pad_value=0)[source]#

Pad image to specified visual size in degrees visual angle

Parameters:
  • img (numpy.ndarray) – image-array to be padded

  • visual_size (Sequence[int, int, ...]) – desired visual size (in degrees visual angle) of img after padding

  • ppd (Sequence[Number] or Sequence[Number, Number]) – pixels per degree

  • pad_value (Numeric, optional) – value to pad with, by default 0.0

Returns:

img padded by the specified amount(s)

Return type:

numpy.ndarray

stimupy.utils.pad.pad_by_shape(img, padding, pad_value=0)[source]#

Pad image by specified amount(s) of pixels

Can specify different amount (before, after) each axis.

Parameters:
  • img (numpy.ndarray) – image-array to be padded

  • padding (int, or Sequence[int, int], or Sequence[Sequence[int, int], ...]) – amount of padding, in pixels, in each direction: ((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis (int,) or int is a shortcut for before = after = pad width for all axes.

  • pad_val (float, optional) – value to pad with, by default 0.0

Returns:

img padded by the specified amount(s)

Return type:

numpy.ndarray

stimupy.utils.pad.pad_to_shape(img, shape, pad_value=0)[source]#

Pad image to a resulting specified shape in pixels

Parameters:
  • img (numpy.ndarray) – image-array to be padded

  • shape (Sequence[int, int, ...]) – desired shape of img after padding

  • pad_value (float, optional) – value to pad with, by default 0.0

Returns:

img padded to specified shape

Return type:

numpy.ndarray

Raises:

ValueError – if img.shape already exceeds shape

stimupy.utils.pad.pad_dict_by_visual_size(dct, padding, ppd, pad_value=0.0, keys=('img', '*mask'))[source]#

Pad images in dictionary by specified degrees of visual angle

Can specify different amount (before, after) each axis.

Parameters:
  • dct (dict) – dict containing image-arrays to be padded

  • padding (float, or Sequence[float, float], or Sequence[Sequence[float, float], ...]) – amount of padding, in degrees visual angle, in each direction: ((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis (float,) or float is a shortcut for before = after = pad width for all axes.

  • ppd (Sequence[Number] or Sequence[Number, Number]) – pixels per degree

  • pad_value (Numeric, optional) – value to pad with, by default 0.0

  • keys (Sequence[String, String] or String) – keys in dict for images to be padded

Returns:

same as input dict but with larger key-arrays and updated keys for “visual_size” and “shape”

Return type:

dict[str, Any]

stimupy.utils.pad.pad_dict_to_visual_size(dct, visual_size, ppd, pad_value=0, keys=('img', '*mask'))[source]#

Pad images in dictionary to specified visual size in degrees visual angle

Parameters:
  • dct (dict) – dict containing image-arrays to be padded

  • visual_size (Sequence[int, int, ...]) – desired visual size (in degrees visual angle) of img after padding

  • ppd (Sequence[Number] or Sequence[Number, Number]) – pixels per degree

  • pad_value (Numeric, optional) – value to pad with, by default 0.0

  • keys (Sequence[String, String] or String) – keys in dict for images to be padded

Returns:

same as input dict but with larger key-arrays and updated keys for “visual_size” and “shape”

Return type:

dict[str, Any]

stimupy.utils.pad.pad_dict_by_shape(dct, padding, pad_value=0, keys=('img', '*mask'))[source]#

Pad images in dictionary by specified amount(s) of pixels Can specify different amount (before, after) each axis.

Parameters:
  • dct (dict) – dict containing image-arrays to be padded

  • padding (int, or Sequence[int, int], or Sequence[Sequence[int, int], ...]) – amount of padding, in pixels, in each direction: ((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis (int,) or int is a shortcut for before = after = pad width for all axes.

  • pad_val (float, optional) – value to pad with, by default 0.0

  • keys (Sequence[String, String] or String) – keys in dict for images to be padded

Returns:

same as input dict but with larger key-arrays and updated keys for “visual_size” and “shape”

Return type:

dict[str, Any]

stimupy.utils.pad.pad_dict_to_shape(dct, shape, pad_value=0, keys=('img', '*mask'))[source]#

Pad images in dictionary to a resulting specified shape in pixels

Parameters:
  • dct (dict) – dict containing image-arrays to be padded

  • shape (Sequence[int, int, ...]) – desired shape of img after padding

  • pad_value (float, optional) – value to pad with, by default 0.0

  • keys (Sequence[String, String] or String) – keys in dict for images to be padded

Returns:

same as input dict but with larger key-arrays and updated keys for “visual_size” and “shape”

Return type:

dict[str, Any]

Raises:

ValueError – if img.shape already exceeds shape