【转载】 opencv, PIL.Image的彩色图片维度 && caffe和pytorch的矩阵维度

原文地址:

https://blog.csdn.net/u011668104/article/details/82718375

---------------------------------------------------------------------------------------------

opencv读取彩色图片:BGR,(h,w,c)
例如:
cv2.imread(‘test.jpg’)

Skimage读彩色图片:RGB,(h,w,c)
例如:
from skimage import io
io.imread(‘test.jpg’,as_grey=False)

PIL.Image读取彩色图片:RGB, size:(w,h),转成numpy后变成(h,w,c)
例如:
image=Image.open(‘test.jpg’)
image = np.array(image,dtype=np.float32)

pytorch tensor matrix: (N, C, H, W)


caffe中imagedata layer彩色图片:BGR
caffe matrix: (N, C, H, W)

参考文献:OpenCV、Skimage、PIL图像处理的细节差异

常用:
from PIL import Image
Image.open(img_path).convert(‘RGB’)

注:有时候用别人的模型需要根据作者对彩色图三个通道的顺序要求
例如,VGG Face 2 中要求“Please note that the input mean vector is in BGR order.”,用它的模型做初始化就只能用BGR顺序。

原文地址:https://www.cnblogs.com/devilmaycry812839668/p/10631432.html