How to load and process multiple images

13 ビュー (過去 30 日間)
Anon
Anon 2020 年 2 月 3 日
回答済み: Image Analyst 2020 年 2 月 4 日
Hi everyone,
I came across the matlab wiki and found this code for loading up multiple images to process them, which I have slightly edited.
However, I am getting the following error
Error using load
Unknown text on line number 1 of ASCII file paganin_000001.tif
"II*"
I am not sure how to edit this code to read these files, I have 100 of these images. Do I need to convert these images from tif to png or jpeg? As I cannot upload .tif files onto here either too.
Any help would be appreciated, thanks.
for k = 1:20
matFilename = sprintf('paganin_00000%d.tif', k);
matData = load(matFilename);
jpgFilename = strcat('image', num2str(k), '.jpg');
imageData = imread(jpgFilename);
textFilename = ['file' num2str(k) '.txt'];
fid = fopen(textFilename, 'rt');
textData = fread(fid);
fclose(fid);
end
  2 件のコメント
Image Analyst
Image Analyst 2020 年 2 月 3 日
Are your original images TIFF or JPG? You don't have any .mat files do you? If not, you shouldn't be using load() to read image files. And I don't think you need both but I can't figure out what your filenames are. Some are tiff files that start with "paganin" and some of JPG that start with "image"??????? Do you have two sets of images? Half are TIFF files and half are JPG files???
Anon
Anon 2020 年 2 月 3 日
Original images are all tiff. I don't have any .mat files. No all files are tiff, please ignore the jpg files.

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

採用された回答

Image Analyst
Image Analyst 2020 年 2 月 4 日
Try this:
for k = 1:20
fileName = sprintf('paganin_00000%d.tif', k);
if isfile(fileName)
% If the file exists, display it.
imageData = imread(fileName);
imshow(imageData);
drawnow;
else
% Print alert for those files that don't exist.
fprintf('File not found: "%s".\n', fileName)
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by