You can convert an image from BGR to LAB using OpenCV Python by following the given steps. I highly recommend you get the “Computer Vision: Models, Learning, and Inference Book” to learn Computer Vision.
Import the OpenCV library. If OpenCV is not installed in your system then first install it using This Method.
import cv2 #cv2 is used for OpenCV library
Now read the image from the location. In my case “F:\\AiHints” is the location and “apple.jpg” is the name of the image. Change it according to your image location and name.
image = cv2.imread("C://AiHints//apple.jpg") #imread is use to read an image from a location
Now convert the BGR image to Lab.
lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2Lab)
Now display the original, and Lab image using the following code.
cv2.imshow("Original Image", image) cv2.imshow("LAB Image", lab_image)
waitKey() open the image for a specific time in milliseconds until you press any key. The function cv2.destroyAllWindows() will destroy all the windows that we created.