def view_as_windows(padded, patch_size, stride=None):
    """
    cut image in sliding windows
    first patch starts at 0, ends at patch_size
    second patch starts at stride, ends at stride + patch_size
    :param padded: padded image, padded according to get_padded_patches
    :param patch_size: size of output patches
    :param stride: stride between patches
    :return: patches
    """
    if stride is None:
        stride = patch_size
    patches = []
    pad = int(patch_size - stride)
    n_cols = int((padded.shape[0] - pad) / stride)
    n_rows = int((padded.shape[1] - pad) / stride)
    for i in range(n_cols):
        for j in range(n_rows):
            patches.append(padded[i * stride:i * stride + patch_size, j *
                stride:j * stride + patch_size])
    return patches
