def crop_psf_shape(imgs, kernels):
    """
    Function to crop a batch of 2D images, expanded by boundaries, corresponding to PSF size.

    Parameters
    ----------
    imgs: (torch.(cuda.)Tensor) Padded images of shape B x C x H + Hk -1 x W + Wk -1
    kernels: (torch.(cuda.)Tensor) PSFs of shape B x C x Hk x Wk
    returns: (torch.(cuda.)Tensor) Cropped images of shape B x C x H x W
    """
    crop_updown, crop_leftright = [(i - 1) // 2 for i in kernels.shape[-2:]]
    
    cropped = imgs[:, :, crop_updown:-crop_updown, crop_leftright:-crop_leftright]
    
    return cropped