本文實例講述了Python使用matplotlib實現(xiàn)的圖像讀取、切割裁剪功能。分享給大家供大家參考,具體如下:
# -*- coding:utf-8 -*-import sysreload(sys)sys.setdefaultencoding('utf-8')import matplotlib.pylab as plt# 加載圖像im = plt.imread("C:/4.png")print(im.shape)# (y軸像素點數(shù), x軸像素點數(shù),圖像通道數(shù))def plti(im, **kwargs): """ 畫圖的輔助函數(shù) """ plt.imshow(im, interpolation="none", **kwargs) plt.axis('off') # 去掉坐標(biāo)軸 plt.show() # 彈窗顯示圖像im = im[50:380,:250,:] # 直接切片對圖像進(jìn)行裁剪plti(im)處理前的圖像:

運行后的效果:

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python數(shù)學(xué)運算技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對大家Python程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選