matlab 读取图片的格式
2016-07-17 18:19
309 查看
在matlab中读取图像数据用imread函数:img = imread(‘******png’)
其中img的格式为:height x width x channels x num ; 3通道的顺序为RGB
所以如果需要在matlab中对图像数据做一些转换,转换成caffe或者C所支持的格式,可以用如下代码:
附上deep-metric里面的一段代码:
另外,python中 cv2.imread读取的图像的存储格式为H W K,且三通道的顺序为BGR ;
PIL.Image.open读取图片的存储格式为:W H K ,且三通道顺序为RGB
其中img的格式为:height x width x channels x num ; 3通道的顺序为RGB
所以如果需要在matlab中对图像数据做一些转换,转换成caffe或者C所支持的格式,可以用如下代码:
% Convert to BGR images = images(:,:,[3 2 1],:); % Switch width and height images = permute(images, [2 1 3 4]);
附上deep-metric里面的一段代码:
%% Pick image pairs
assert(mod(batch_size, 2)==0);
[image_id_pairs, labels] = get_training_examples_multilabel(mode, batch_size); % get_training_examples_multilabel只是针对class id和image id进行一系列的操作,并未涉及到真正的图像数据
%% Prep dataset for C and Caffe conventions
images = cat(4, images.img); %%Concatenate arrays along specified dimension
assert(max(image_id_pairs(:)) <= length(images));
% images must be (height x width x channels x num)
assert(ndims(images) == 4);
% assume square images
assert(size(images, 1) == size(images, 2));
% images must have 3 channels
assert(size(images, 3) == 3);
% Convert to BGR images = images(:,:,[3 2 1],:); % Switch width and height images = permute(images, [2 1 3 4]);
% Caffe likes 0-1 labels
labels = int32(labels);
labels(labels == -1) = 0;
labels_cont = 1:11318;
assert(isequal(double(unique(labels)), labels_cont'));
% Subtract 1 for C indexing
image_id_pairs = int32(image_id_pairs - 1);
% check the number of paired data is divisible
另外,python中 cv2.imread读取的图像的存储格式为H W K,且三通道的顺序为BGR ;
PIL.Image.open读取图片的存储格式为:W H K ,且三通道顺序为RGB
相关文章推荐
- matlab绘制 三维剖面图
- 用matlab画正弦平滑曲线而不是锯齿线
- matlab GUI
- Matlab基本数学应用
- Create uint8/char/uchar buffer for storing the structure into matlab memory
- matlab显示并保存RGB图像的单个通道图像
- 如何保存Matlab/Simulink中示波器显示的图像
- 家里没人怎么防火防盗?装上这段自动看家程序
- 如何修改Matlab默认启动目录?
- Matlab的exe实现
- matlab调用VS生成的DLL
- MATLAB机器人工具箱Matlab_Robotic_Toolbox_v9.10的安装详解
- MATLAB_reshape函数
- 取模(mod)与取余(rem)的区别——Matlab学习笔记
- matlab 读取WAV文件
- [万能解决问题]MATLAB has encountered an internal problem and needs to close.
- Matlab GUI之permute()函数与msdbox()函数
- 最常用的10个Matlab快捷键,助你编程更高效
- Ubuntu 16.04 安装 Matlab2016a
- MATLAB学习记录