how to use cv2.COLOR_BGR2GRAY 1

how to use cv2.COLOR_BGR2GRAY

def main():
	imagePath = "img.jpg"
	
	img = cv2.imread(imagePath)
	gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
	
	generate_histogram(gray)
	
	cv2.imwrite("before.jpg", gray)

	gray = cv2.equalizeHist(gray)
	
	generate_histogram(gray)
	
	cv2.imwrite("after.jpg",gray)
	
	return 0 

Here is what the above code is Doing:
1. Read the image
2. Convert the image to grayscale
3. Generate the histogram of the image
4. Apply histogram equalization
5. Generate the histogram of the image after equalization
6. Save the image

Similar Posts