updated to support grayscale images