Prevent NaN and inf values from being recorded to the image.