def trim_bg(img, color=None):
    """Trim background rows/cols from an image-like object."""
    if color is None:
        color = img[0, 0]
    img = img[:, (img != color).any(0).any(-1)]
    img = img[(img != color).any(1).any(-1)]
    return img