matplotlib: ValueError: invalid PNG header

前端 未结 2 2076
一整个雨季
一整个雨季 2021-01-04 19:52

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

2条回答
  •  没有蜡笔的小新
    2021-01-04 20:01

    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. <--

提交回复
热议问题