kaishi.image.util

Image utilities and helper functions.

Module Contents

kaishi.image.util.swap_channel_dimension(tensor)

Swap between channels_first and channels_last.

If ‘tensor’ has 4 elements, it’s assumed to be the shape vector. Otherwise, it’s assumed that it’s the actual tensor. Returns the edited shape vector or tensor.

Parameters

tensor (numpy.array) – shape vector or tensor to have channel dimensions swapped

Returns

altered input with the channel dimensions swapped

Return type

numpy.array

kaishi.image.util.validate_image_header(filename: str)

Validate that an image has a valid header.

Returns True if valid, False if invalid.

Parameters

filename (str) – name of file to analyze

Returns

flag indicating whether header is valid (by using imghdr.what())

Return type

bool

kaishi.image.util.get_batch_dimensions(self, batch_size: int, channels_first: bool = True, image_type: str = 'small_image')

Get dimensions of the batch tensor. Note that the ‘batch_size’ argument can be the full data set.

Parameters
  • self (kaishi.image.dataset.ImageDataset) – image dataset object

  • batch_size (int) – batch size

  • channels_first (bool) – flag indicating whether channels are first or last dimension in each image

  • image_type (str) – one of “small_image”, “thumbnail”, or “patch”

Returns

batch dimesions (4D tuple)

Return type

tuple