码迷,mamicode.com
首页 > 编程语言 > 详细

『Python』PIL图像处理_矩阵转化

时间:2017-05-16 21:40:45      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:tom   numpy   xen   from   scale   rom   转化   截取   .com   

应师兄要求改图,因为使用了PIL包把图片对象转化为numpy的矩阵,截取以及处理很好玩且方便,特此记录:

 1 import numpy as np
 2 from PIL import Image
 3 import matplotlib.pyplot as plt
 4 
 5 img = Image.open(./7b6021ef9e6892dcf14dc5dd269afaada763fedc13b29-iHXENu_fw658.jpeg)
 6 plt.imshow(img)
 7 plt.show()
 8 # 转化为数组
 9 img = np.asarray(img)
10 print(图像矩阵尺寸:,img.shape)
11 
12 # 截取上面的图片,舍弃下面20行
13 bottom = 50
14 img = img[:-bottom,:]
15 
16 # 刻度数
17 xscale = 5
18 yscale = 6
19 
20 fig = plt.figure(Image)
21 plt.imshow(img)
22 # 按照师兄的要求生成坐标
23 plt.xticks([img.shape[1]/xscale*w for w in range(xscale+1)], [%.1f % (87.3-(87.3-82.2)/xscale*w) for w in range(xscale+1)])
24 plt.yticks([(img.shape[0]-bottom)/yscale*w for w in range(yscale+1)], [%.1f % (-3.5-(-3.5-(-(img.shape[1]-bottom)/img.shape[1]*(-3.5-1.5)-3.5))/yscale*w) for w in range(yscale+1)])
25 plt.xlabel("Galactic Longitude")
26 plt.ylabel("Galactic Latitude")
27 plt.show()
28 fig.savefig(result.eps,format=eps)
29 fig.savefig(result.png,format=png)
/home/hellcat/anaconda2/envs/python3_6/bin/python /home/hellcat/PycharmProjects/data_analysis/帮师兄修图/handle_piecture.py
图像矩阵尺寸: (924, 658, 3)

Process finished with exit code 0

技术分享技术分享

 

顺便一提:

plt.xticks([img.shape[1]/xscale*w for w in range(xscale+1)], [%.1f‘ % (87.3-(87.3-82.2)/xscale*w) for w in range(xscale+1)])

这一句也超级好用的,虽然是matplotlib.pyplot包的,不过numpy.asarray()也不是PIL包的呀~~

『Python』PIL图像处理_矩阵转化

标签:tom   numpy   xen   from   scale   rom   转化   截取   .com   

原文地址:http://www.cnblogs.com/hellcat/p/6863552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!