Updated script to handle grayscale images