0

I get the prediction results from the model I trained. But while I can easily show the predicted image with matplotlib, I cannot display it with PIL Image. The image's shape is 256,256,3 in size and float32 type. Image shown with matplotlib: Image and Image shown with PIL Image: Image

I use below code for matplotlib:

# gen_image is a list of predicted images
gen_image = (gen_image + 1) / 2.0
gen_image_convert = gen_image[0]
pyplot.imshow(gen_image_convert)
pyplot.axis('off')
pyplot.show()

and for PIL Image I used below code:

gen_image_convert = gen_image[0]
image = Image.fromarray((gen_image_convert * 255).astype(np.uint8)).convert('RGB')
image.show()
Zirveda
  • 1
  • 2
  • Probably `PIL` shows the values as they are, while `pyplot` assigns black to the lowest value seen and white to the largest. You'll need the same transformation if you want to see the same result using `PIL`. – JohanC Oct 04 '21 at 11:25
  • Thanks for the comment! It worked when normalize image to [0, 1]. – Zirveda Oct 05 '21 at 06:06

0 Answers0