'Strange looking images when converting numpy array to Pillow Image

I am converting a numpy array to a pillow Image using the following line of code

pil_image = Image.fromarray(image_array, 'RGB')

Numpy array has a shape of (512,960) and can only ever contain 2 values. Those values are 0.00000 or 255.00000.

The images that I am expecting to get should look something like this with it only being black and white:

enter image description here

But instead it looks like this:

enter image description here

How can I resolve this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source