Function to convert a colored image to grayscale