Skip to content

Problems with other data-types than uint8 #4887

@emilettele

Description

@emilettele

What did you do?

I was trying to create an Image from a numpy array using Image.fromarray(array, mode) and validate the created image by using the show() function. It did not create the right image.

What did you expect to happen?

Show a white image

What actually happened?

Showed an image with seperated colors.

What are your OS, Python and Pillow versions?

  • OS: Windows
  • Python: 3.6.8
  • Pillow: 7.2.0

What is the problem?

Pillow shows the right image if the dtype of the values in the array is uint8, but seems to have problems accepting other data types.

import numpy as np
from PIL import Image

array = np.full((32,32,3),255)
array[0].dtype
image = Image.fromarray(array, "RGB")
image.show()

wrong

It does however work if I first convert the array to uint8:

import numpy as np
from PIL import Image

array = np.full((32,32,3),255)
array = np.uint8(array)
array[0].dtype
image = Image.fromarray(array, "RGB")
image.show()

right

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions