Dot indexing is not supported for variables of this type.

4 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2021-6-23
编辑:Stephen23 2021-6-23
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);

请先登录,再进行评论。

采纳的回答

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

更多回答(2 个)

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

请先登录,再进行评论。


Image Analyst
Image Analyst 2021-6-23
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 个评论
Image Analyst
Image Analyst 2021-7-12
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by