dithering: catch NaN's in input image so they don't flood the whole output