幽灵资源网 Design By www.bzswh.com

做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,Image,skimage

幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。