0

I have this image and following python code. black and white

import numpy as np
from PIL import Image
image = Image.open("File.png")
image = image.convert("1")
image.show()
bw = np.asarray(image).copy()
im01 = np.where(bw, 0, 1)
new_img = Image.fromarray(im01)
new_img.show()   

new image

Since the image is black and white, I could see the im01 as a 2D ndarray with 0s and 1 as white and black pixels in 184x184 matrix.

Why didn't Image.fromarray() work? Is there something that I am missing?

impossible
  • 2,380
  • 8
  • 36
  • 60
  • The image isn't black and white (bilevel), rather its RGBA!! See if that helps you solve the problem – Vasu Deo.S Jul 24 '19 at 15:57
  • I have converted the image to bilevel, and it still doesn't work? (updated the code) – impossible Jul 24 '19 at 16:16
  • 1
    I think you are running in a similar problem to this one: https://stackoverflow.com/questions/47290668/image-fromarray-just-produces-black-image This should be checkable by multiplying your array with 255. – Alexander Mayer Jul 24 '19 at 16:29
  • Thanks, @AlexanderMayer, I think your hint should work for me. Let me try out that! – impossible Jul 24 '19 at 16:34

0 Answers0