Don't attempt to preserve the colorspace of greyscale images - convert them to RGB instead so that they have the expected structure for the pixel comparison.
Fail gracefully when conversion fails.