Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何重命名目录中的所有图像_Matlab_Image Processing - Fatal编程技术网

Matlab 如何重命名目录中的所有图像

Matlab 如何重命名目录中的所有图像,matlab,image-processing,Matlab,Image Processing,我有一个包含200个jpeg图像的目录。我想要的是重命名所有这些图像。那么,我怎样才能同时重命名我的所有图像呢。例如,我想将第一个图像重命名为“hello1”,第二个图像重命名为“hello2”,第三个图像重命名为“hello3”…>第200个图像重命名为“hello200” 您可以在下面找到我的代码: maximagesperdir = inf; directory='imagess'; dnames = {directory}; fprintf('Reading images...'); c

我有一个包含200个jpeg图像的目录。我想要的是重命名所有这些图像。那么,我怎样才能同时重命名我的所有图像呢。例如,我想将第一个图像重命名为“hello1”,第二个图像重命名为“hello2”,第三个图像重命名为“hello3”…>第200个图像重命名为“hello200”

您可以在下面找到我的代码:

maximagesperdir = inf;
directory='imagess';
dnames = {directory};
fprintf('Reading images...');
cI = cell(1,1);
  c{1} = dir(dnames{1});
  if length(c{1})>0,
    if c{1}(1).name == '.',
      c{1} = c{1}(4:end);
    end
  end
  if length(c{1})>maximagesperdir,
    c{1} = c{1}(1:maximagesperdir);
  end
  cI{1} = cell(length(c{1}),1);
  for j = 1:length(c{1}),
    cI{1}{j} = double(imread([dnames{1} '/' c{1}(j).name]))./255;
  end
fprintf('done.\n');

下面是一些重命名当前目录中所有文件的代码,您显示的代码看起来是读取的,而不是重命名的

fnames = dir('*.jpg');
for i = 1:length(fnames)
   old_name = fnames(i).name;
   new_name = sprintf('hello%d.jpg', i);
   movefile(old_name, new_name)
end

如果您只是希望重命名文件,而不是对图像执行操作,然后重命名,那么总有total commander程序,这是一个有用的小东西。选择所有文件,并使用ctrl+m选择重命名它们的方式(日期、名称等)。如果您希望执行重命名操作,则非常简单。我只是说…

试试看,也总是有选择的;)