Dot indexing is not supported for variables of this type.

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Stephen23
Stephen23 il 23 Giu 2021
Modificato: Stephen23 il 23 Giu 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);

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 22 Giu 2021
Modificato: Matt J il 22 Giu 2021
In line 18, you clearly epect FileList to be a structure variable, but it isn't. You should check what it actually is.

Più risposte (2)

Walter Roberson
Walter Roberson il 23 Giu 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 Commento
sun rise
sun rise il 8 Lug 2021
I need to sort by folder name only, then access the images inside those folders to extract the features

Accedi per commentare.


Image Analyst
Image Analyst il 23 Giu 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 Commenti
Image Analyst
Image Analyst il 12 Lug 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.

Accedi per commentare.

Categorie

Scopri di più su Deep Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by