Workaround for matplotlib bug with flipped RGB image

For some matplotlib versions and file formats, RGB images are flipped. Is there a way we can automatically figure out the orientation?