1. 程式人生 > >jpg,png,txt等檔案的讀取 matlab

jpg,png,txt等檔案的讀取 matlab

第一個程式碼解決問題, jpg,png,txt等檔案的讀取 

第二個程式碼除了解決上述問題,還要從更多的圖片中找到與上面對應的圖片,選取出來

namelist = dir('C:\Users\DELL\Desktop\data\helen\train\train_res\*.jpg');
namelist1 = dir('C:\Users\DELL\Desktop\data\helen\train\train_res\*.txt');

% 讀取後namelist 的格式為
% name -- filename
% date -- modification date
% bytes -- number of bytes allocated to the file
% isdir -- 1 if name is a directory and 0 if not
img = cell(1954,1);
text = cell(1954,1);
len = length(namelist);
for i = 1:len
    file_name{i}=namelist(i).name;
    file_name1{i}=namelist1(i).name;
    img{i}= imread(strcat('C:\Users\DELL\Desktop\data\helen\train\train_res\',file_name{i}));
    text{i} = load(strcat('C:\Users\DELL\Desktop\data\helen\train\train_res\',file_name1{i}));
end
namelist = dir('C:\Users\DELL\Desktop\data\helen\train\train_res\*.jpg');
namelist1 = dir('C:\Users\DELL\Desktop\data\helen\train\train_res\*.txt');
namelist2 = dir('C:\Users\DELL\Desktop\helen\helen\trainset\*.jpg');
% 讀取後namelist 的格式為
% name -- filename
% date -- modification date
% bytes -- number of bytes allocated to the file
% isdir -- 1 if name is a directory and 0 if not
img = cell(1954,1);
img1 = cell(1954,1);
text = cell(1954,1);
len = length(namelist);
for i = 1:len
    file_name{i}=namelist(i).name;
    file_name1{i}=namelist1(i).name;
    img{i}= imread(strcat('C:\Users\DELL\Desktop\data\helen\train\train_res\',file_name{i}));
    img1{i} = imread(strcat('C:\Users\DELL\Desktop\helen\helen\trainset\',file_name{i}));
    text{i} = load(strcat('C:\Users\DELL\Desktop\data\helen\train\train_res\',file_name1{i}));
end