Imread list image from file text

2 次查看(过去 30 天)
Dear everyone,
I'm new MM, i have code would like read list image from file txt .
my txt file as :
0010\0010_01_05_03_115.jpg 85.680000 90.720000 158.760000 95.760000 118.440000 128.520000
0010\0010_01_05_03_121.jpg 60.480000 98.280000 163.800000 93.240000 126.000000 123.480000
0010\0010_01_05_03_125.jpg 63.000000 88.200000 161.280000 85.680000 123.480000 115.920000
my code as below:
CTrain = importdata('./database/AA/ctrain.txt');
CTrainNo = size(CTrain, 1);
for i = 1 : CTrainNo
ClTrain = imread(['./database/AA/Client/' CTrain{i}]);
imwrite(ClTrain, ['.\database\AA\train\bb\' num2str(i-1, '%05d') '.png']);
end
But have error :
" Brace indexing is not supported for variables of this type." . From " ClTrain = imread(['./database/AA/Client/' CTrain{i}]);"
Pls help me,
thankyou so much!

回答(1 个)

Akhilesh Yadav
Akhilesh Yadav 2021-5-20
Hi Jacky,
It is my understanding that you are new to MATLAB and trying to read text file using ‘importdata’ function. As per your ‘ctrain.txt’ file content your first column contains text data(file name and location) and when you are reading this file using ‘importdata’ function, CTrain object of type struct is created with three fields(data,textdata,rowheaders). Where your file name stored in rowheaders and textdata of CTrain object and you can access those values using dot notation.
The following solution fix issue in your code
CTrain = importdata('./database/AA/ctrain.txt');
CTrainNo = size(CTrain.textdata, 1);
for i = 1 : CTrainNo
ClTrain = imread(['./database/AA/Client/' CTrain.textdata{i}]);
imwrite(ClTrain, ['.\database\AA\train\bb\' num2str(i-1, '%05d') '.png']);
end
Please refer to the importdata, readtable documentation for more information on how to work with text file.
Hope this will help you.

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by