utilities.transform_utils.image_cutting module#

This modules contains functions to manipulate images in the form of numpy arrays.

cut_ims_in_directory(path_ims: str, path_target_dir: str, target_dims: tuple[int, int] = (512, 512), mask=False, preprocess: bool = False, batch_size: int = 100, format: str = 'tiff', preprocess_function=<function __preprocess_mask_image>) None[source]#

Finds images at “Path_ims” cuts them into dimension “target_dims”, and then saves them as png files to “path_target_dir”. Note currently only supports rgb images.

Arguments#

str path_ims:

Path to directory where images are stored.

str path_target_dir:

path to directory where cut images should be placed

tuple[int], optional target_dims:

target dimensons of image. Defaults to (512,512).

bool, optional mask:

If true assumes images are masks. Defaults to False.

bool, optional preprocess:

If true preprocesses images. Defaults to False.

image_cut(image: ndarray[Any, dtype[Any]], cut_dims: tuple[int, int], num_bands: int = 1, pad: bool = True) ndarray[Any, dtype[Any]][source]#

Takes an input image “image” and cuts into many images each of dimensions “cut_dims”. Assumed input image shape

Note, image are cut in row major order.

Note, if image dimensions arent a multiple of cut_dims, then the input image is padded at the right, and left edge with black pixels. So some images will contain black areas.

Arguments#

NDArray[Any] image:

Numpy array representing image to cut [H,W,C].

tuple[int, int] cut_dims:

desired dimensions to cut images to.

int, optional num_bands:

Number of bands of input image. Defaults to 1.

Returns#

return NDArray[Any]:

an array of multiple rgb images that represent input image

image_stich(ims: ndarray[Any, dtype[int16]], num_ims_x: int, num_ims_y: int, edge_space: tuple[int, int]) ndarray[Any, dtype[int16]][source]#

Stiches input images “ims”, into a single returned image. assumed layout of input images is [B, H, W, C].

Note It is also assumed that the images in Ims are stored in row major order.

Note edge_space = im_dims-black_space. i.e. edge space is the amount of image that is not black.

Arguments#

NDArray[np.int16] ims:

Images tensor to combine in shape [B, H, W, C].

int num_ims_x:

Specfies how many small images to stack in the x direction to make big image.

int num_ims_y:

Specfies how many small images to stack in the y direction to make big image.

tuple[int] edge_space:

The number of pixels in each direction that are not black space,

of the most bottom left image.

Returns#

return NDArray[np.int16]:

1 large image as a numpy array in shape [H, W, C]