Matlab Processing Sequentially Numbered Images -
this question has answer here:
- how process images in order in matlab 3 answers
i have 1000 images started img0.png, img1.png, img3.png, ..., img1000.png. using matlab , code following:
imagenames = dir(fullfile(workingdir,'*.png')); so imagenames struct contains following
img0.png
img1.png
img10.png
img100.png .......
but want
img0.png
img1.png
img2.png .......
is possible programmatically in matlab?
regards
if you're trying convert filenames you've said in comment. can use regexprep list of new filenames corresponding old filenames.
newnames = regexprep({imagenames.name},'(img)(\d*)(\.png)','$1${sprintf(''%04d'', $2)}$3') essentially, pulls out numeric part of each filename, , runs through sprintf 0 pad suggested (4 digit zero-padding).
if want re-save images these new names, can in loop.
for k = 1:numel(imagenames); movefile(imagenames(k).name, newnames{k}); end if want, can sort newnames variable , sort naturally now.
[values, sortinds] = sort(newnames); sortednames = imagenames(sortinds);
Comments
Post a Comment