Effacer les filtres
Effacer les filtres

Imwrite() problem with saving sequence images

4 vues (au cours des 30 derniers jours)
Tossawon Ngamnet
Tossawon Ngamnet le 25 Mai 2018
Commenté : Guillaume le 29 Mai 2018
First, i try to load .mat file into my workspace files = dir('*.mat'); for i = 1:numel(files) load(files(i).name);
Second, i want to read the images in work space and save it as following for k=0:10 output_folder = 'C:\Users\Tossaworn\Desktop'; outputFileName = fullfile(output_folder, ['test' num2str(k) '.tif']);
imwrite(IR0000__,outputFileName); end
IR0000__ is 1 image, but i want IR0001__,IR0002__, ...and output test0,1,2,... . Now output can run, but i have no idea to read the input images. please suggest, Thank you.

Réponse acceptée

Guillaume
Guillaume le 25 Mai 2018
Here is how I would do it:
output_folder = 'C:\Users\Tossaworn\Desktop';
files = dir('*.mat');
for fidx = 1:numel(files)
matcontent = load(files(fidx).name); %load into structure
filenumber = regexp(files(fidx).name, '\d+', 'match', 'once'); %get numeric part of filename
imagename = sprintf('IR%s__', filenumber); %build variable name
assert(isfield(matcontent, imagename), 'mat file %s does not contain image %s', files(fidx).name, imagename);
outputfilename = fullfile(output_folder, sprintf('test%s.tif', filenumber));
imwrite(matcontent.(imagename), outputfilename);
end
  5 commentaires
Tossawon Ngamnet
Tossawon Ngamnet le 29 Mai 2018
Modifié(e) : Guillaume le 29 Mai 2018
Sorry for my careless. I did the code follow your suggestion. Its work, but the avi file cannot open. Code below:
outputVideo = VideoWriter('newvideo.avi');
outputVideo.FrameRate = 30;
outputVideo.Quality = 100;
open(outputVideo);
srcFiles = dir('C:\Users\Tossaworn\Desktop\testTIFfiles\*.tif');
for k = 1 : length(srcFiles)
filename = strcat('C:\Users\Tossaworn\Desktop\testTIFfiles\',srcFiles(k).name);
I = imread(filename);
writeVideo(outputVideo, im2double(I));
end
Is that due to unspecified size?
Guillaume
Guillaume le 29 Mai 2018
You're missing a
close(outputVideo);
at the end. If that's not the reason for the problem, then I don't know. Try a different video player which may give more insight.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by