Effacer les filtres
Effacer les filtres

Copy/rename cell array and then rename all images again

1 vue (au cours des 30 derniers jours)
Marcel Liphardt
Marcel Liphardt le 21 Août 2017
Commenté : Stephen23 le 21 Août 2017
Hello,
currently my code to rename images in general looks like this:
function left(~)
[filenames, pathname] = uigetfile({'*.jpg'}, 'MultiSelect', 'on', 'Please select the left images');
fullFilenames1 = cellfun( @(x) fullfile( pathname, x ), filenames, 'UniformOutput', false );
for iFile = 1:numel(fullFilenames1)
newName = sprintf('left%03d.jpg',iFile);
movefile(fullFilenames1{iFile},newName);
end
All my images are called e.g.: left01 078, left01 079, left01 80.......
Now that we have two cameras, we also get these right images:
right01 078, right01 079, right01 80......
This means that the right images have to be renamed automatically, so that it would be easier for the user.
So just before the loop starts, my 'filenames' cell array needs to be duplicated, then the names inside need to be renamed from left01... to right01 but still containing the numbers at the end mentioned above.
Then the user has to choose: folder = uigetdir(); the directory where the right images are stored, so that it can add the path to the fullfile?????
And last but not least, another loop then renames the right images just like the loop before:
for iFile = 1:numel(fullFilenames2)
newName = sprintf('right%03d.jpg',iFile);
movefile(fullFilenames2{iFile},newName);
end
I tried to search for these things but I couldn't find any suitable answer as of yet.
  2 commentaires
Adam
Adam le 21 Août 2017
Which aspect of it is causing the problem?
Marcel Liphardt
Marcel Liphardt le 21 Août 2017
What do you mean by causing the problem?
I just would like to get some help to achieve all this.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 21 Août 2017
Modifié(e) : Stephen23 le 21 Août 2017
Use regexprep or strrep, e.g.:
[filenames, pathname] = uigetfile({'*.jpg'}, 'MultiSelect', 'on', 'Please select the left images');
LNames = cellfun( @(x) fullfile( pathname, x ), filenames, 'UniformOutput', false );
RNames = strrep(LNames,'left','right');
It might be even simpler to use dir to get all of the filenames, then you do not force the user to select them all:
D = dir(fullfile(pathname,'left*.jpg'));
LNames = {D.name};
  5 commentaires
Marcel Liphardt
Marcel Liphardt le 21 Août 2017
Yeah ok, sorry that I didn't tell you.
So all my left images are stored in their own folder.
And all my right images are stored in their oe´wn folder as well.
Stephen23
Stephen23 le 21 Août 2017
Then you could do something like this:
txt = 'Please select the left images';
[Lnames, Lpath] = uigetfile({'*.jpg'}, 'MultiSelect','on', txt);
Rnames = strrep(Lnames,'left','right'); % or regexprep for more control
Rpath = uigetdir();
for k = 1:numel(Lnames)
movefile(fullfile(Lpath,Lnames{k}), sprintf('left%03d.jpg',k));
movefile(fullfile(RPath,Rnames{k}), sprintf('right%03d.jpg',k)),
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by