import matplotlib.pyplot as plt
I tried to imread a png photo among many other png photos in the same folder. Some photos read with no errors using the following line, and some returns "ValueError: invalid PNG header". What could be the cause? They all look like normal photos to me.
plt.imread(filename)
As @MichM has already stated that somehow the header of your image has changed and it is not a valid png image. Read the image as
plt.imread(filename, 0)
If you read the Matplotlib imread's doc at https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imread.html?highlight=imread#matplotlib.pyplot.imread
--> If format is provided, will try to read file of that type, otherwise the format is deduced from the filename. If nothing can be deduced, PNG is tried. <--
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With