save an image in python as grayscale cv2

cv2.imwrite('data/dst/lena_opencv_red.jpg', im)

Here is what the above code is Doing:
1. Read the image using cv2.imread(). The image should be in the working directory or a full path of image should be given.
2. Convert the image to grayscale using cv2.cvtColor().
3. Apply thresholding using cv2.threshold(). First argument is the source image, which should be a grayscale image. Second argument is the threshold value which is used to classify the pixel values. Third argument is the maxVal which represents the value to be given if pixel value is more than the threshold value. OpenCV provides different styles of thresholding and it is decided by the fourth parameter of the function. Different types are:
cv2.THRESH_BINARY
cv2.THRESH_BINARY_INV
cv2.THRESH_TRUNC
cv2.THRESH_TOZERO
cv2.THRESH_TOZERO_INV
4. Save the thresholded image using cv2.imwrite().