import random


def random_patch(lr, hr, lr_patch_size=48):
    """ Get random patches from the lr and hr images

    Args:
        lr (np.ndarray): low-res image
        hr (np.ndarray): high-res image
        lr_patch_size (int, optional): low-res patch size. Defaults to 48.
    """
    # sanity check
    lps = lr_patch_size
    lrh, lrw = lr.shape[:2]
    hrh, hrw = hr.shape[:2]
    assert hrh % lrh == 0 and hrw % lrw == 0
    scale = hrh // lrh

    # top-left point in the low-res image
    ly = random.randint(0, lrh - lps)
    lx = random.randint(0, lrw - lps)
    # top-left point in the high-res image
    hy, hx = scale * ly, scale * lx
    # get windows
    lrwindow = lr[ly:ly+lps, lx:lx+lps, :]
    hrwindow = hr[hy:hy+lps*scale, hx:hx+lps*scale, :]

    return lrwindow, hrwindow