浅谈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 相关文章推荐
初步讲解Python中的元组概念
May 21 Python
举例详解Python中yield生成器的用法
Aug 05 Python
使用Python判断质数(素数)的简单方法讲解
May 05 Python
Python基础教程之浅拷贝和深拷贝实例详解
Jul 15 Python
详解Django之auth模块(用户认证)
Apr 17 Python
python 与服务器的共享文件夹交互方法
Dec 27 Python
Python实现钉钉发送报警消息的方法
Feb 20 Python
Python中Subprocess的不同函数解析
Dec 10 Python
django多种支付、并发订单处理实例代码
Dec 13 Python
基于spring boot 日志(logback)报错的解决方式
Feb 20 Python
利用pyecharts读取csv并进行数据统计可视化的实现
Apr 17 Python
浅谈Python协程
Jun 17 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 删除一个数组中的某个值.兼容多维数组!
2012/02/18 PHP
PHP实现简单实用的验证码类
2015/07/29 PHP
解决php的“It is not safe to rely on the system’s timezone settings”问题
2015/10/08 PHP
PHP编程计算文件或数组中单词出现频率的方法
2017/05/22 PHP
繁简字转换功能
2006/07/19 Javascript
自动完成JS类(纯JS, Ajax模式)
2009/03/12 Javascript
thinkphp 表名 大小写 窍门
2015/02/01 Javascript
JavaScript中误用/g导致的正则test()无法正确重复执行的解决方案
2016/07/27 Javascript
js判断数组key是否存在(不用循环)的简单实例
2016/08/03 Javascript
jquery插件bootstrapValidator数据验证详解
2016/11/09 Javascript
基于js实现的限制文本框只可以输入数字
2016/12/05 Javascript
Bootstrap table使用方法记录
2017/08/23 Javascript
node文字生成图片的示例代码
2017/10/26 Javascript
通过vue提供的keep-alive减少对服务器的请求次数
2018/04/01 Javascript
vue todo-list组件发布到npm上的方法
2018/04/04 Javascript
bootstrap模态框弹出和隐藏,动态改变中间内容的实例
2018/08/10 Javascript
vue的style绑定background-image的方式和其他变量数据的区别详解
2018/09/03 Javascript
详解mpvue中小程序自定义导航组件开发指南
2019/02/11 Javascript
VUE解决微信签名及SPA微信invalid signature问题(完美处理)
2019/03/29 Javascript
JS判断数组四种实现方法详解
2020/06/29 Javascript
python中遍历文件的3个方法
2014/09/02 Python
Python中DJANGO简单测试实例
2015/05/11 Python
Python时间模块datetime、time、calendar的使用方法
2016/01/13 Python
Python 修改列表中的元素方法
2018/06/26 Python
python接口自动化如何封装获取常量的类
2019/12/24 Python
Python安装whl文件过程图解
2020/02/18 Python
MCAKE蛋糕官方网站:一直都是巴黎的味道
2018/02/06 全球购物
美容师的职业规划书
2013/12/27 职场文书
工作过失检讨书
2014/02/23 职场文书
80后职场人的职业生涯规划
2014/03/08 职场文书
医院院务公开实施方案
2014/05/03 职场文书
学校安全教育月活动总结
2014/07/07 职场文书
企业优秀团员事迹材料
2014/08/20 职场文书
2014大学生党员评议个人总结
2014/09/22 职场文书
学校扫黄打非工作总结
2015/10/15 职场文书
阿里云服务器搭建Php+Apache运行环境的详细过程
2021/05/15 PHP