Python圖像處理之圖像的讀取、顯示與保存操作【測試可用】
本文實例講述了Python圖像處理之圖像的讀取、顯示與保存操作。分享給大家供大家參考,具體如下:
python作為機器學習和圖像處理的利器,收到越來越多的推崇,特別是在圖像處理領域,越來越多的研究和開發(fā)開始轉向使用python語言,下面就介紹python圖像處理中最基本的操作,即圖像的讀取顯示與保存。
1、使用PIL模塊
代碼如下:
# -*- coding:utf-8 -*-
from PIL import Image
import numpy as np
def test_pil():
#讀取圖像
im = Image.open("lena.jpg")
#顯示圖像
im.show()
#轉換成灰度圖像
im_gray = im.convert("L")
im_gray.show()
#保存圖像
im_gray.save("image_gray.jpg")
return
test_pil()
顯示結果如下:

2、使用scipy和matplotlib模塊
代碼如下:
# -*- coding:utf-8 -*-
import numpy as np
from scipy import misc
import matplotlib.pyplot as plt
def test_misc():
#讀取圖像
im = misc.imread("lena.jpg")
#顯示圖像
plt.figure(0)
plt.imshow(im)
#旋轉圖像
im_rotate = misc.imrotate(im, 90)
plt.figure(1)
plt.imshow(im_rotate)
#保存圖像
misc.imsave("lena_rotate.jpg", im_rotate)
plt.show()
return
test_misc()
顯示結果如下:

更多關于Python相關內容可查看本站專題:《Python數學運算技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
相關文章
python+mediapipe+opencv實現手部關鍵點檢測功能(手勢識別)
這篇文章主要介紹了python+mediapipe+opencv實現手部關鍵點檢測功能(手勢識別),本文僅僅簡單介紹了mediapipe的使用,而mediapipe提供了大量關于圖像識別等的方法,需要的朋友可以參考下2022-01-01

