better handling of nan and inf in image_as_uint8