浅谈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 time模块
Apr 29 Python
Python做文本按行去重的实现方法
Oct 19 Python
Python中进程和线程的区别详解
Oct 29 Python
Python装饰器用法实例总结
Feb 07 Python
Laravel+Dingo/Api 自定义响应的实现
Feb 17 Python
Python数据类型之Number数字操作实例详解
May 08 Python
python os.fork() 循环输出方法
Aug 08 Python
Python如何调用JS文件中的函数
Aug 16 Python
python实现视频读取和转化图片
Dec 10 Python
python机器学习库xgboost的使用
Jan 20 Python
Python之关于类变量的两种赋值区别详解
Mar 12 Python
python 实现关联规则算法Apriori的示例
Sep 30 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实现活动人选抽奖功能
2017/04/19 PHP
PHP学习笔记之session
2018/05/06 PHP
用js脚本控制asp.net下treeview的NodeCheck的实现代码
2010/03/02 Javascript
JS实现仿百度输入框自动匹配功能的示例代码
2014/02/19 Javascript
JavaScript中的函数重载深入理解
2014/08/04 Javascript
使用jquery.qrcode生成彩色二维码实例
2014/08/08 Javascript
详解从angular-cli:1.0.0-beta.28.3升级到@angular/cli:1.0.0
2017/05/22 Javascript
在vscode中统一vue编码风格的方法
2018/02/22 Javascript
postman+json+springmvc测试批量添加实例
2018/03/31 Javascript
vue.js使用v-pre与v-html输出HTML操作示例
2018/07/07 Javascript
JavaScript判断对象和数组的两种方法
2019/05/31 Javascript
Vue 前端实现登陆拦截及axios 拦截器的使用
2019/07/17 Javascript
Node.js 实现抢票小工具 & 短信通知提醒功能
2019/10/22 Javascript
JS常用正则表达式超全集(密码强度校验,金额校验,IE版本,IPv4,IPv6校验)
2020/02/03 Javascript
Vue登录拦截 登录后继续跳转指定页面的操作
2020/08/04 Javascript
python中异常捕获方法详解
2017/03/03 Python
python制作小说爬虫实录
2017/08/14 Python
python微信跳一跳游戏辅助代码解析
2018/01/29 Python
Python全栈之列表数据类型详解
2019/10/01 Python
Django框架HttpRequest对象用法实例分析
2019/11/01 Python
Django后端发送小程序微信模板消息示例(服务通知)
2019/12/17 Python
python+gdal+遥感图像拼接(mosaic)的实例
2020/03/10 Python
Python的logging模块基本用法
2020/12/24 Python
css3加js做一个简单的3D行星运转效果实例代码
2017/01/18 HTML / CSS
CSS3实现莲花绽放的动画效果
2020/11/06 HTML / CSS
html5借用repeating-linear-gradient实现一把刻度尺(ruler)
2019/09/09 HTML / CSS
茶叶生产计划书
2014/01/10 职场文书
护士自我评价范文
2014/01/25 职场文书
2014大学生全国两会学习心得体会
2014/03/13 职场文书
利群广告词
2014/03/20 职场文书
小区的门卫岗位职责
2014/10/01 职场文书
社区活动总结范文
2015/05/07 职场文书
Python实现socket库网络通信套接字
2021/06/04 Python
Python获取江苏疫情实时数据及爬虫分析
2021/08/02 Python
vue3获取当前路由地址
2022/02/18 Vue.js
Tomcat项目启动失败的原因和解决办法
2022/04/20 Servers