Reputation: 388
I have PIL Image in binary and I need to convert it in RGB. I did this diskew image
binary image
I need this way:
I already tried this which is not working
from PIL import Image as im
img = im.fromarray((255 * Image).astype("uint8")).convert("RGB")
Upvotes: 3
Views: 6156
Reputation: 207873
I still don't understand why you convert to RGBA if you want RGB, but this code converts your image to RGB as you ask:
#!/usr/local/bin/python3
import numpy as np
from PIL import Image
# Open input image
im = Image.open('text.png').convert('RGB')
# Invert
npim = 255 - np.array(im)
# Save
Image.fromarray(npim).save('result.png')
Upvotes: 3