Rewrite read_image and add tests