now handling grayscale images! yes, I know, I should have done that first..