programme phyton pour realiser un programme qui transforme une image en niveau de gris 1

programme phyton pour realiser un programme qui transforme une image en niveau de gris

from matplotlib import pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread('test.jpg')

R, G, B = img[:,:,0], img[:,:,1], img[:,:,2]
imgGray = 0.2989 * R + 0.5870 * G + 0.1140 * B
plt.imshow(imgGray, cmap='gray')
plt.show()

Here is what the above code is Doing:
1. Read the image using mpimg.imread()
2. Split the image into its R, G, B channels
3. Convert the image to grayscale using the formula:
0.2989 * R + 0.5870 * G + 0.1140 * B
4. Display the image using plt.imshow()

Similar Posts