0

I am trying to open images (.png) using PIL. However, It only shows images only in two colours.

Original image (i.e. 3.24 MB). I reduced the size since system only allows us to upload below 2MB:

Original image

When I run image = Image.open('path/image') , it gives this:

enter image description here

when I run the same but with convert, image = Image.open('path/image').convert('L') I get this:

enter image description here

Here is the way how i plot images:

fig,ax = plt.subplots()
ax.imshow(image)
ax.grid(False)

I have tried dozens of images. No change. I strongly guess the problem caused by the image channels. Function somehow reads the 3-channels as single-channel or the other way around. Any ideas how to fix???


Edit: So I got closer to the result i want. I convert the iamge into an array first. But it still is not enough. enter image description here

here is the code:

image = Image.open(df['Path'][0])
image = np.asarray(image)
plt.imshow(image)
vagitus
  • 264
  • 2
  • 10

1 Answers1

0

Finally solved it. Transformed the image to array and read the values by cmap. Here is the full code and the result:

image = Image.open('/path/image')
image = np.asarray(image)
plt.imshow(np.abs(image), cmap = 'gray')

enter image description here

vagitus
  • 264
  • 2
  • 10