Loop to open files / extract image data and save them in a matrix

3 ビュー (過去 30 日間)
Harizi Amira
Harizi Amira 2019 年 5 月 27 日
編集済み: Harizi Amira 2019 年 5 月 27 日
I have an image database as files (106 files and each file contains 48 images)
I want to generate a matrix for the database (db.mat)
I want my program to open each folder (from 001 to 106) and take the data and save it to a db.mat file
here is my prog :
clear all;
clc;
cd D:\001\FT-2BU\FT-2BU
s = '';
str1 ='00';
str2 ='0';
for i=1:106
if i<10
s=strcat(str1,i);
bmpFiles = dir('*.bmp');
numfiles = length(bmpFiles);
mydata = cell(1, numfiles);
for k = 1:numfiles
mydata{k} = imread(bmpFiles(k).name);
end
save mydata;
elseif i<100
s=strcat(str2,i);
bmpFiles = dir('*.bmp');
numfiles = length(bmpFiles);
mydata = cell(1, numfiles);
for k = 1:numfiles
mydata{k} = imread(bmpFiles(k).name);
end
save mydata;
else
s=i;
bmpFiles = dir('*.bmp');
numfiles = length(bmpFiles);
mydata = cell(1, numfiles);
for k = 1:numfiles
mydata{k} = imread(bmpFiles(k).name);
end
save mydata; end
end
end
ffn.PNG

採用された回答

michael scheinfeild
michael scheinfeild 2019 年 5 月 27 日
you need take subfolder , create it use num2str(number)
dir(fullfile(folder,subfolder))
  1 件のコメント
Harizi Amira
Harizi Amira 2019 年 5 月 27 日
編集済み: Harizi Amira 2019 年 5 月 27 日
Can you explain to me why this error appears, despite the fact that the file 1_1.bmp exists in bmpFiles structure !

サインインしてコメントする。

その他の回答 (1 件)

michael scheinfeild
michael scheinfeild 2019 年 5 月 27 日
look your bmp files empty
  1 件のコメント
Harizi Amira
Harizi Amira 2019 年 5 月 27 日
編集済み: Harizi Amira 2019 年 5 月 27 日
the BMP file is empty because I can not open the files one by one
here is the little program for a single file what gave me, it works correctly.
now I want to generate the matrix for all files

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by