fixed a few bugs in image utils (problems when used with grayscale images)