How can I make the code work for any format, not just .jpg?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello - I found this code from http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F and although it says that any format should work, it will not read any .tif files. Instead it results in the following errors -
- Error using imread>get_format_info (line 491)Unable to determine the file format.
- Error in imread (line 354) fmt_s = get_format_info(fullname);
- Error in Line (line 16) imageArray = imread(fullFileName);
There are no errors when the code is used with .jpg files. Here is the code
% function Line(~,~)
% Specify the folder where the files live.
myFolder = 'C:\Users\Vicki\Documents';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.tif'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
end
end
end
Any help is much appreciated.
3 件のコメント
OCDER
2018 年 6 月 27 日
For debug, do this:
try
imageArray = imread(fullFileName);
catch
warning('Could not open: %s', fullFileName);
end
Which files are failing to open?
採用された回答
Victoria
2018 年 6 月 27 日
編集済み: Image Analyst
2018 年 6 月 28 日
6 件のコメント
Image Analyst
2018 年 6 月 29 日
No, mixing file types would not cause the problem.
Some things to try if you want,or are curious and want to avoid the problem in the future:
- If you move the files back into the folder of the same name (if you still have it), does the problem reoccur?
- If you make a folder with that name on a different drive, or as a subfolder of another folder, do you see the problem with that image file?
- I could try to reproduce with the same image file (if you attach it) and a folder of the same name on my computer.
Otherwise, I guess it will have to remain a mystery.
その他の回答 (1 件)
Image Analyst
2018 年 6 月 27 日
My guess is that you really did . or * instead of *.tif and then you tried to read a non-image file. Or else the file has a .tif extension but is really NOT a tiff file. See if you can open the file in Photoshop or GIMP.
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!