def get_square_image()

in src/cloud/pipelines/semantic_segmentation/preprocessing.py [0:0]


def get_square_image(img, padding_color=(0, 0, 0)):
    """Returns a squared image by adding black padding"""
    width, height = img.size
    if width == height:
        return img
    elif width > height:
        result = Image.new(img.mode, (width, width), padding_color)
        result.paste(img, (0, (width - height) // 2))
        return result
    else:
        result = Image.new(img.mode, (height, height), padding_color)
        result.paste(img, ((height - width) // 2, 0))
        return result