def center_crop(img, new_width, new_height):
    """Code similar to `center_crop` in TorchVision, with changes.

    Changes from TorchVision:
        - Works on 2D and 3D frames, instead of 2D only
        - Works on numpy ndarray frames, instead of PIL Image frames.
    """
    width, height = img.shape[0], img.shape[1]  # Get dimensions

    left = int(round((width - new_width) / 2))
    right = int(round((width + new_width) / 2))
    top = int(round((height - new_height) / 2))
    bottom = int(round((height + new_height) / 2))
    if len(img.shape) == 2:
        return img[left:right, top:bottom]
    if len(img.shape) == 3:
        return img[left:right, top:bottom, :]
    raise ValueError(f"image shape {img.shape} can only have 2 or 3 dimensions")