matlab 将.jpg文件处理为.mat数据

来源:互联网 发布:竹纤维毛巾知乎 编辑:程序博客网 时间:2024/05/22 16:52
clear all; close all; clc; % addpath('./Roi3');srcDir = 'E:\Matlab\Deep Learning\code\CAVIAR_Data\';trialsperclass = [303 333 148 367 322 439 238 503 509 178 521 398 329 482 402];Trialsperclass = [0 303 636 784 1151 1473 1912 2150 2653 3162 3340 3861 4259 4588 5070 5472];% train_trialsperclass = floor(0.05 * trialsperclass(2 : end));% test_trialsperclass = trialsperclass(2 : end) - train_trialsperclass;Height = 80; Width = 40;  %固定图像大小data_x(1,:) = uint8(zeros(1,Height * Width));data_y(1) = uint8(zeros(1));%%%提取所有图像num_data = 1;  %记录图像总数class = 1;  %记录图像分类数目% for idx = test_trialsperclass    % for jdx = train_trialsperclass(class) + Trialsperclass(class) + (1:idx)  for idx = trialsperclass    for jdx = Trialsperclass(class) + (1:idx)        % 加载图像        im_name = [srcDir num2str(jdx) '.jpg']; % im_name = strcat(int2str(jdx),'.jpg')        image = imresize(imread(im_name),[Height Width],'bicubic'); %R2013a默认使用'bicubic'双三次插值算法改变图像尺寸        data_x(num_data,:) = reshape(image,1,Height * Width);         data_y(num_data) = class;        num_data =num_data+1;    end        class = class+1;    end    % permute data 打乱图像permut = randperm(size(data_x,1));data_x = double(data_x(permut,:))/255;data_y = double(data_y(permut))';save CAVIAR_Data.mat data_x data_y permut;
0 0