本文實例講述了Python實現圖像幾何變換的方法。分享給大家供大家參考。具體實現方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import Image try : im = Image. open ( 'test.jpg' ) #out = im.resize((128, 128)) #改變大小 #out = im.rotate(45) #45°旋轉 #out = im.transpose(Image.FLIP_LEFT_RIGHT) #水平翻轉 #out = im.transpose(Image.FLIP_TOP_BOTTOM) #垂直翻轉 #out = im.transpose(Image.ROTATE_90) # 90 #out = im.transpose(Image.ROTATE_180) #180°順時針翻轉 out = im.transpose(Image.ROTATE_270) #270°順時針翻轉 out.save( 'test2.jpg' ) except IOError: print 'No File!' |
希望本文所述對大家的Python程序設計有所幫助。