Borrar filtros
Borrar filtros

Imread list image from file text

5 visualizaciones (últimos 30 días)
jacky huynh
jacky huynh el 31 de Mzo. de 2021
Respondida: Akhilesh Yadav el 20 de Mayo de 2021
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!

Respuestas (1)

Akhilesh Yadav
Akhilesh Yadav el 20 de Mayo de 2021
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.

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by