xxxxxxxxxx
from PIL import Image
img = Image.open('image.png').convert('LA')
img.save('greyscale.png')
xxxxxxxxxx
import cv2
image = cv2.imread('C:/Users/N/Desktop/Test.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Original image',image)
cv2.imshow('Gray image', gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
xxxxxxxxxx
# Convert image to grayscale
grayscale_image = my_image.convert("L")
# Save the image
grayscale_image.save("gray_lenna.png")
# Show grayscale image
grayscale_image.show()
# Alternative approach
plt.imshow(grayscale_image, cmap='gray')
# See format
print(grayscale_image.format)
# See dimension
print(grayscale_image.size)
# See mode
print(grayscale_image.mode)