caffe学习笔记(13):python cv2.imread()读取图片和matlab读取图像的区别

来源:互联网 发布:linux tomcat调试模式 编辑:程序博客网 时间:2024/05/16 15:04

利用cv2读取图像和使用matlab读取图像在每个channel的值不同,cv2读入的形式为BGR,matlab读入的形式为RGB。

原始图像:
这里写图片描述

Python 利用 cv2.imread() 读取图片,并显示

读入图像后需要再对其进行处理,才能被网络使用,具体方法参见我上一篇文章:
http://blog.csdn.net/qq_30401249/article/details/71429895

import osimport cv2import matplotlib.pyplot as pltim_name = '000456.jpg'print 'Demo for data/demo/{}'.format(im_name)# go into def demo(net, image_name):im_file = os.path.join('data/demo', im_name)im_o = cv2.imread(im_file)print im_oim = im_o[:, :, (2, 1, 0)] # change channelfig, ax = plt.subplots(figsize=(12, 12))ax.imshow(im, aspect='equal')plt.axis('off')plt.tight_layout()plt.draw()plt.show()

这里写图片描述

这里写图片描述

Matlab读取图像

>> b=imread('000456.jpg');>> x = b(:,:,1); # channel R>> y = b(:,:,2); # channel G>> z = b(:,:,3); # channel B

这里写图片描述

这里写图片描述

这里写图片描述

0 0