TransWikia.com

TyperError When trying to show an image in grayscale on Python

Stack Overflow Asked by Andrew Vo on February 14, 2021

I keep getting a TypeError: Invalid shape (825,) for image data when trying to display the image in grayscale.

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import os
plt.rcParams['figure.figsize'] = [16, 8]

A = mpimg.imread('image4.jpg')
X = np.mean(A, -1)

img = plt.imshow(X)
img.set_cmap('gray')
plt.axis('off')
plt.show()

One Answer

(Moving my comment to answer)

There may be a problem with your image file. I tested with pygame.org/docs/_static/pygame_tiny.png. I converted to jpg and it worked with your code.

PyGame Image

Answered by Mike67 on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP