added an if statement so that we can use both grayscale and rgb images