Dot indexing is not supported for variables of this type.

3 vues (au cours des 30 derniers jours)
sun rise
sun rise le 22 Juin 2021
Commenté : Image Analyst le 12 Juil 2021
sad1 = 'D:\Project\DB\train\';
sad = dir(sad1); % Returns both folders and files
% sad = dir(pwd); % Returns both folders and files
cell_array_of_folder_names = setdiff({sad([sad.isdir]).name},{'..','.'}); % Select folder names
% cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
FileList = sort_nat( cell_array_of_folder_names );
% sorted_cell_array_of_folder_names = cell_array_of_folder_names; % if you don't have sort_nat
whos sorted_cell_array_of_folder_names
%Folder = 'D:\Project\DB\train\';
%FileList1 = dir(fullfile(Folder, '**', '*.tif'));
%FileList = sort_nat( FileList1 );
Feature = cell(1, numel(FileList)); % Pre-allocation
for iFile = 1:numel(FileList)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
Img = imread(File);
Img = imresize(Img, [200, 50]);
Feature{iFile} = hog_feature_vector(Img);
end
% Maybe:
Feat1 = cat(1, Feature{:}); % Or cat(2, ...) ?!
save('featurs_T.mat', 'Feat1');
%------------------
sad2 = 'D:\Project\DB\test\';
sad22 = dir(sad); % Returns both folders and files
% sad = dir(pwd); % Returns both folders and files
cell_array_of_folder_names2 = setdiff({sad22([sad22.isdir]).name},{'..','.'}); % Select folder names
% cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
FileList2 = sort_nat( cell_array_of_folder_names2 );
% sorted_cell_array_of_folder_names = cell_array_of_folder_names; % if you don't have sort_nat
whos sorted_cell_array_of_folder_names
%Folder2 = 'D:\Project\DB\test\';
%FileList22 = dir(fullfile(Folder2, '**', '*.tif'));
%FileList2 = sort_nat( FileList22 );
Feature2 = cell(1, numel(FileList2)); % Pre-allocation
for iFile2 = 1:numel(FileList2)
File2 = fullfile(FileList2(iFile2).folder, FileList2(iFile2).name);
Img2 = imread(File2);
Img2 = imresize(Img2, [200, 50]);
Feature2{iFile2} = hog_feature_vector(Img2);
end
% Maybe:
Feat2 = cat(1, Feature2{:}); % Or cat(2, ...) ?!
save('featurs_S.mat', 'Feat2');
Dot indexing is not supported for variables of this type.
Error in Untitled4 (line 18)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
  1 commentaire
Stephen23
Stephen23 le 23 Juin 2021
Modifié(e) : Stephen23 le 23 Juin 2021
Why are you specifically filtering so that cell_array_of_folder_names contains only folder names, but then trying to read those folders as if they were image files?
You should certainly simplify a lot of that code, e.g.:
P = 'D:\Project\DB\train\';
S = dir(fullfile(P,'*.tif'));
S = natsortfiles(S);
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
I = imread(F);
..
S(k).feature = ..
end
Feat1 = cat(1, S.feature);

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 22 Juin 2021
Modifié(e) : Matt J le 22 Juin 2021
In line 18, you clearly epect FileList to be a structure variable, but it isn't. You should check what it actually is.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 23 Juin 2021
cell_array_of_folder_names2 = setdiff({sad22([sad22.isdir]).name},{'..','.'}); % Select folder names
Those are file names
FileList2 = sort_nat( cell_array_of_folder_names2 );
sort_nat takes in a cell array of character vectors and returns a cell array of character vectors -- that is, FileList2 will be file names (just in sorted order)
File2 = fullfile(FileList2(iFile2).folder, FileList2(iFile2).name);
but there you expect FileList2 to be the output of dir()
cell_array_of_folder_names2 = setdiff({sad22([sad22.isdir]).name},{'..','.'}); % Select folder names
Like the variable name says, those are folder names, so when you then
FileList2 = sort_nat( cell_array_of_folder_names2 );
then what you get out is not a list of files but rather a list of folders
File2 = fullfile(FileList2(iFile2).folder, FileList2(iFile2).name);
Img2 = imread(File2);
but there you are expecting it to refer to image files, not to folders.
If you need to sort by folder name, and then you need to sort by file name, then you will need to sort_nat() the folder names, and then for each folder, dir() the folder to find file names, and sort_nat() the file names.
  1 commentaire
sun rise
sun rise le 8 Juil 2021
I need to sort by folder name only, then access the images inside those folders to extract the features

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 23 Juin 2021
Feature2 = cell(1, numel(FileList2)); % Pre-allocation
for iFile2 = 1:numel(FileList2)
fullFileName = fullfile(sad2, FileList2{iFile2});
Img2 = imread(fullFileName);
Img2 = imresize(Img2, [200, 50]);
title(fullFileName)
drawnow;
Feature2{iFile2} = hog_feature_vector(Img2);
end
  4 commentaires
sun rise
sun rise le 11 Juil 2021
m-file.
Image Analyst
Image Analyst le 12 Juil 2021
Evidently you have an image called 1. I'm not sure you it found it since it does not have a .tif extension, but that seems to be the problem. imread() might not know how to read in "1" unless it's called "1.tif". Try adding extensions to all your tif images.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by