Reading an image sequence: "Error: The filename or url argument must be a string."

11 ビュー (過去 30 日間)
Fer
Fer 2015 年 10 月 4 日
回答済み: hossam mahmoud 2021 年 2 月 7 日
Hello, I'm trying to work over a sequence of images, I have used dir to obtain a list of all the files:
dirData = dir([dirName, '\*.png']); %# Get the data for the current directory
dirIndex = [dirData.isdir]; %# Find the index for directories
fileList = {dirData(~dirIndex).name}'; %'# Get a list of the files
if ~isempty(fileList)
imgList = cellfun(@(x) fullfile(dirName,x),... %# Prepend path to files
fileList,'UniformOutput',false);
end
imgst=cellstr(imgList);
I tried looping over the list but I got an error so I then tried imread over only one member of the array: imread(imgst(1))
and again I got the error saying argument wasn't a string.
I thought cellstr would convert the members in the list to strings? If they're not strings what are they? how can I reference each file in my list so I can work with them over a loop? I know similar questions have been asked before but I didn't find an answer for an error like mine.
Thanks a lot
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 7 月 8 日
The line
imgList = cellfun(@(x) fullfile(dirName,x),... %# Prepend path to files
fileList,'UniformOutput',false);
can be replaced with
imgList = fullfile(dirName, fileList);
fullfile() is happy to take a cell array of character vectors as the second argument.

サインインしてコメントする。

回答 (3 件)

Fer
Fer 2015 年 10 月 4 日
Okay, so I found the answer to my own question. Not deleting in case someone has the same problem. The only thing I had to so was calling
imread(imgst{1})
so basically just using {} instead of ().
I had not used cells before so, my bad.
  2 件のコメント
Virgil of the Matrix
Virgil of the Matrix 2018 年 6 月 26 日
THANK YOU! YOU ARE A S A I N T!
Nathaniel Conrad
Nathaniel Conrad 2020 年 7 月 8 日
Thank you for pointing this out! I was using a cell data container to hold a string character for a file path for the first time and having the same issue, too.
I do find it odd that if a cell only has one element in it, then you must index the container variable with {1} in order to extract the string that is labeling the relevant image file path.
For example, if you store the string in a structure array, then you don't need to index the structure array data container variable at all. Weird!

サインインしてコメントする。


Tess Meier
Tess Meier 2019 年 1 月 22 日
Yes thank you!!!!!!

hossam mahmoud
hossam mahmoud 2021 年 2 月 7 日
I found the solution
just try this
s=convertStringsToChars(s);

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by