PIL.Image convert to numpy array
生活随笔
收集整理的這篇文章主要介紹了
PIL.Image convert to numpy array
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當使用PIL.Image讀取圖像時,如果直接使用numpy.array()轉換會出現錯誤:
lst = list() for file_name in os.listdir(dir_image):image = PIL.Image.open(file_name)lst.append(image) arr = numpy.array(lst)此時,上述最后一行在執行時會出現錯誤:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Image'解決辦法如下:
lst = list() for file_name in os.listdir(dir_image):image = PIL.Image.open(file_name)lst.append(np.array(image)) arr = numpy.array(lst)即,在list中的元素都已轉化為numpy.array,而非直接的Image對象。
總結
以上是生活随笔為你收集整理的PIL.Image convert to numpy array的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pajek的net文件格式
- 下一篇: 数字图像处理入门(冈萨雷斯第三版)