浅谈python图片处理Image和skimage的区别


Posted in Python onAugust 04, 2019

做cnn的难免要做大量的图片处理。由于接手项目时间不长,且是新项目,前段时间写代码都很赶,现在稍微总结(恩,总结是个好习惯)。

1,首先安装python-Image和python-skimage、python-matplotlib。

  简单代码:

import Image as img
import os
from matplotlib import pyplot as plot
from skimage import io,transform
import argparse
 
def show_data(data):
  fig = plot.figure()
  ax = fig.add_subplot(121)
  ax.imshow(data, cmap='gray')
  ax2 = fig.add_subplot(122)
  ax2.imshow(data)
  plot.show()
if __name__ == "__main__":
  parse = argparse.ArgumentParser()
  parse.add_argument('--picpath', help = "the picture' path")
  args = parse.parse_args()
  img_file1 = img.open(args.picpath)#Image读图片
  one_pixel = img_file1.getpixel((0,0))[0]
  print "picture's first pixe: ",one_pixel 
  print "the picture's size: ", img_file1.size#Image读出来的size是高宽
  show_data(img_file1)
  img_file2 = io.imread(args.picpath)#skimage读图片
  show_data(img_file2)
  print "picture's first pixel: ", img_file2[0][0][0]
  print "the picture's shape: ", img_file2.shape#skimage读出来的shape是高,宽, 通道

调用及输出:

浅谈python图片处理Image和skimage的区别

其实Image读出来的是PIL什么的类型,而skimage.io读出来的数据是numpy格式的。如果想直接看Image和skimage读出来图片的区别,可以直接输出它们读图片以后的返回结果。

2.Image和skimage读图片:

img_file1 = img.open(args.picpath)
img_file2 = io.imread(args.picpath)

3.读图片后数据的大小:

print "the picture's size: ", img_file1.size
print "the picture's shape: ", img_file2.shape

4.得到像素:

one_pixel = img_file1.getpixel((0,0))[0]
img_file2[0][0][0]

分析:

1.从3的输出可以看出img读图片的大小是图片的(height,width);

skimage的是(height,width, channel)[这也是为什么caffe在单独测试时要要在代码中设置:transformer.set_transpose('data',(2,0,1)),因为caffe可以处理的图片的数据格式是(channel,height,width),所以要转换数据啊]

2.img读出来的图片获得某点像素用getpixel((h,w))可以直接返回这个点三个通道的像素值

skimage读出来的图片可以直接img_file2[0][0][0]获得,但是一定记住它的格式,并不是你想的(channel,height,width)

关于matplotlib简单的画图请关注下篇~

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
pyqt4教程之messagebox使用示例分享
Mar 07 Python
python单线程实现多个定时器示例
Mar 30 Python
Python实现类似jQuery使用中的链式调用的示例
Jun 16 Python
python 3利用BeautifulSoup抓取div标签的方法示例
May 28 Python
python 处理dataframe中的时间字段方法
Apr 10 Python
解决nohup重定向python输出到文件不成功的问题
May 11 Python
Numpy 将二维图像矩阵转换为一维向量的方法
Jun 05 Python
Python PIL图片添加字体的例子
Aug 22 Python
np.random.seed() 的使用详解
Jan 14 Python
python读写文件write和flush的实现方式
Feb 21 Python
Win10下配置tensorflow-gpu的详细教程(无VS2015/2017)
Jul 14 Python
python时间time模块处理大全
Oct 25 Python
Python下opencv图像阈值处理的使用笔记
Aug 04 #Python
python opencv 简单阈值算法的实现
Aug 04 #Python
Python pandas用法最全整理
Aug 04 #Python
python匿名函数用法实例分析
Aug 03 #Python
pycharm编写spark程序,导入pyspark包的3中实现方法
Aug 02 #Python
Python适配器模式代码实现解析
Aug 02 #Python
Python3网络爬虫开发实战之极验滑动验证码的识别
Aug 02 #Python
You might like
php 论坛采集程序 模拟登陆,抓取页面 实现代码
2009/07/09 PHP
php学习之简单计算器实现代码
2011/06/09 PHP
PHP计算一年多少个星期和每周的开始和结束日期
2014/07/01 PHP
php对象在内存中的存在形式分析
2015/02/03 PHP
php遍历目录方法小结
2015/03/10 PHP
PHP标准库(PHP SPL)详解
2019/03/16 PHP
JQuery,Extjs,YUI,Prototype,Dojo 等JS框架的区别和应用场景简述
2010/04/15 Javascript
解决js数据包含加号+通过ajax传到后台时出现连接错误
2013/08/01 Javascript
javascript如何判断输入的url是否正确
2014/04/11 Javascript
jQuery学习笔记之 Ajax操作篇(一) - 数据加载
2014/06/23 Javascript
jQuery下拉菜单的实现代码
2016/11/03 Javascript
smartupload实现文件上传时获取表单数据(推荐)
2016/12/12 Javascript
微信小程序实战之轮播图(3)
2017/04/17 Javascript
Vue.js中组件中的slot实例详解
2017/07/17 Javascript
vue页面切换到滚动页面显示顶部的实例
2018/03/13 Javascript
swiper.js插件实现pc端文本上下滑动功能示例
2018/12/03 Javascript
原生js实现下拉选项卡
2019/11/27 Javascript
javascript的hashCode函数实现代码小结
2020/08/11 Javascript
[04:09]显微镜下的DOTA2第十二期—NaVi美如画的团战
2014/06/23 DOTA
[04:19]DOTA2亚洲邀请赛 现场花絮
2015/03/11 DOTA
python urllib urlopen()对象方法/代理的补充说明
2017/06/29 Python
分析python切片原理和方法
2017/12/19 Python
pandas重新生成索引的方法
2018/11/06 Python
详解Numpy中的数组拼接、合并操作(concatenate, append, stack, hstack, vstack, r_, c_等)
2019/05/27 Python
基于python进行抽样分布描述及实践详解
2019/09/02 Python
Python list与NumPy array 区分详解
2019/11/06 Python
tensorflow 获取checkpoint中的变量列表实例
2020/02/11 Python
关于matplotlib-legend 位置属性 loc 使用说明
2020/05/16 Python
婴儿地球:Baby Earth
2018/12/25 全球购物
2014全国两会学习心得体会2000字
2014/03/10 职场文书
团队精神的演讲稿
2014/05/14 职场文书
职业道德模范事迹材料
2014/08/24 职场文书
爱护环境卫生倡议书
2015/04/29 职场文书
网络舆情信息简报
2015/07/21 职场文书
react合成事件与原生事件的相关理解
2021/05/13 Javascript
postgresql中如何执行sql文件
2023/05/08 PostgreSQL