Liron Lavi
Liron Lavi

Reputation: 431

How can I convert an image to grayscale without losing any transparency?

This is my code:

img = cv2.imread(some_path, 0)

Original image:

PNG image

After running the code:

PNG image grayscale

Obviously losing a lot of transparency.

Upvotes: 0

Views: 661

Answers (1)

adapap
adapap

Reputation: 665

You can use PILLOW:

from PIL import Image
img = Image.open('image_to_grayscale.png').convert('LA')
img.save('greyscale.png')

Result:

Result

Upvotes: 4

Related Questions