def compute_pad(input_shape, region_shape, region_stride):
    """
    Determines the padding that has to be applied in any dimension

    :rtype: tuple
    :returns: tuple (padded_input_shape, paddings)
        * padded_input_shape (tuple): the new (height, width) input shape
        * paddings (tuple): how many pixels must be added to the (left, right, top, bottom)
    """

    in_h, in_w = input_shape
    stride_y, stride_x = region_stride
    reg_h, reg_w = region_shape

    new_w = (in_w - 1) * stride_x + reg_w
    new_h = (in_h - 1) * stride_y + reg_h

    pad_r = (new_w - in_w) // 2
    pad_l = new_w - (in_w + pad_r)
    pad_b = (new_h - in_h) // 2
    pad_t = new_h - (in_h + pad_b)
    return (new_h, new_w), (pad_l, pad_r, pad_t, pad_b)