import torch


def get_binary_kernel2d(window_size):
    """
        Creates a binary kernel to extract the patches. If the window size
        is HxW will create a (H*W)xHxW kernel.
    """
    window_range = window_size[0] * window_size[1]

    kernel = torch.zeros(window_range, window_range)

    for i in range(window_range):
        kernel[i, i] += 1.0
    return kernel.view(window_range, 1, window_size[0], window_size[1])