matlab制作UCMerced_LandUse数据集

将UCMerced_LandUse中的图像展平成一行,并将图像一行一行地存储到一个矩阵X中,y中每行保存一个标签。

由于图像较多,在读取图像制作矩阵时,最后会读取地越来越慢,猜想是matlab动态链表增长产生的问题,所以将其分为两次读取,然后合并,经测试确实比原来快了很多。故在这里保存一下。

clc;clear;

class_names = {'agricultural', 'airplane', 'baseballdiamond', 'beach', 'buildings', 'chaparral', 'denseresidential', 'forest', 'freeway', 'golfcourse', 'harbor', 'intersection', 'mediumresidential', 'mobilehomepark', 'overpass', 'parkinglot', 'river', 'runway', 'sparseresidential', 'storagetanks', 'tenniscourt'};

path = 'E:/pythonFiles/UCMerced_LandUse/test_set1/';
savePath = 'E:/datasets/UCMerced/';
 
files =textread('E:/code/testfileNames.txt','%s');
shape = size(files);
nums = shape(1);

X1 = [];
y1 = [];
X2 = [];
y2 = [];
X = [];
y = [];

for i=1:(nums/2)
    fileName = files{i,1};
    sp1 = strsplit(fileName, '.');
    name = sp1{1};
    sp2 = strsplit(name, '_');
    label = sp2{2};
    category = str2num(label);
    
    imageName = strcat(path, fileName);
    img = imread(imageName);
    img1 = img(:)';
    
    X1 = [X1;img1];
    y1 = [y1;category];
    disp(i);
end

for i=(nums/2+1):nums
    fileName = files{i,1};
    sp1 = strsplit(fileName, '.');
    name = sp1{1};
    sp2 = strsplit(name, '_');
    label = sp2{2};
    category = str2num(label);
    
    imageName = strcat(path, fileName);
    img = imread(imageName);
    img1 = img(:)';
    
    X2 = [X2;img1];
    y2 = [y2;category];
    disp(i);
end

X = [X1;X2];
y = [y1;y2];

 


版权声明:本文为qq_23847773原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。