caffe的matlab和python接口数据的处理

来源:互联网 发布:battlelog网络连接错误 编辑:程序博客网 时间:2024/05/19 18:44

Python:

arr = np.load('ilsvrc_2012_mean.npy')print arr.shape # (3,256,256) channel * height * width########## 数据的转置 ###############arr = np.transpose(arr,[1,2,0]) # height * width * channelprint arr.shape########## 通道的交换 ###############arr = arr[:,:,[2,1,0]]print arr.shape################## test lena ##########img = imread('lena.jpg')img = img[:,:,(2,1,0)] # change from rgb to gbrimg = img[:,:,(2,1,0)] # change backplt.imshow(arr)plt.show()

Matlab:

img = imread('lena.jpg'); % height * width * channel[rgb]%%%%%%%%%%%%%%%%% [h,w,c] to [w,h,c] %%%%%%%%%%%%%%%%%%%%%%%%% 因为matlab是按列存储的,caffe和python是按行存储的imgforwd = permute(img,[2 1 3]);%%%%%%%%%%%%%%% rgb to bgr %%%%%%%%%%%%%%%%%%%%%%%%%因为caffe利用了opencv,opencv图像的存储就是bgrimgforwd = imgforwd(:,:,[3 2 1]);%%%%%%%%%%% 逆向回来 %%%%%%%%%%%%imgback = permute(imgforwd,[2,1,3]);imgback = imgback(:,:,[3,2,1]);figure;subplot(121),imshow(imgforwd);subplot(122),imshow(imgback);

这里写图片描述

0 0