dgs.utils.image

Utility for handling images in pytorch.

Loading, saving, manipulating of RGB-images.

Within pytorch an image is a Byte-, Uint8-, or Float-Tensor with a shape of [C x h x w]. Within torchvision an image is a tv_tensor.Image object with the same shape. A Batch of torch images therefore has a shape of [B x C x h x w]. Within pytorch and torchvision, the images have channels in order of RGB. The size / shape of an image is given as tuple (and sometimes list) of ints in the form of (h, w).

RGB Images in cv2 have a shape of [h x w x C] and the channels are in order GBR. Grayscale Images in cv2 have a shape of [h x w].

Module Functions

combine_images_to_video(imgs, video_file[, fps])

Combine multiple images into a single video.

compute_padding(old_w, old_h, target_aspect)

Given the width and height of an old and image, compute the size of a padding around the old image such that the aspect ratio matches a target.

create_mask_from_polygons(img_size, ...[, ...])

Given the x- and y- coordinates of one or multiple polygons, create a Mask.

load_image(filepath[, force_reshape, dtype, ...])

Load an image or multiple images given a single or multiple filepaths.

load_image_list(filepath[, dtype, device, ...])

Load multiple images with possibly different sizes as a list of tv_tensor images.

load_video(filepath, **kwargs)

Load a video from a given filepath.

Module Classes

CustomCropResize(*args, **kwargs)

Extract all bounding boxes of a single torch tensor image as new image crops then resize the result to the given output shape, which makes the results stackable again.

CustomResize(*args, **kwargs)

Resize image, bbox and key points with this custom transform.

CustomToAspect(*args, **kwargs)

Custom torchvision Transform that modifies the image, bboxes, and coordinates simultaneously to match a target aspect ratio.

CustomTransformValidator()

All the custom transforms need to extract and validate values from args and kwargs.