在MATLAB中重命名图像文件的名称 [英] Rename image file name in matlab

查看:231
本文介绍了在MATLAB中重命名图像文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从网站加载10,000个图像文件,并将其保存在文件夹中以便在我的项目(图像检索系统)中使用它,现在我需要像(image1,image2,image3,...)这样的顺序名称重命名图像文件。 ... image10000),任何人都可以帮助我...
我想告诉你,我在我的工作中使用matlab

谢谢

解决方案

您需要牢记的一件事情是文件名的数字部分的格式如何,因为这有时会影响目录中文件的排序。例如,使用上面给出的命名约定有时会产生如下的排序顺序:

  image1.jpg 
image10.jpg
image11.jpg
image2.jpg
image3.jpg
...

这通常不是你想要的。如果你用零填充数字直到最大数字大小(在你的情况下是5位数字),排序顺序应该在目录中保持得更好:

  image00001.jpg 
image00002.jpg
image00003.jpg
....

要创建这样的文件名,您可以使用 SPRINTF 功能。这里有一些示例代码,以这种方式重命名目录中的所有.jpg文件:

  dirData = dir('*。jpg ); %#获取选定的文件数据
fileNames = {dirData.name}; %#为iFile = 1创建文件名
的单元格数组:文件名(fileNames)%#循环遍历文件名$ b $ newName = sprintf('image%05d.jpg',iFile); %#创建新名称
movefile(fileNames {iFile},newName); %#重命名文件
end

上面的代码也使用 DIR MOVEFILE 函数(如其他答案中所述)。

I Load 10,000 image files from internet site and i save it in the folder to use it in my project (image retrieval system ), now i need to rename image file in a sequential name like (image1,image2,image3,....image10000) , any one can help me... I would like to inform you that I used matlab in my work

thank

解决方案

One thing you'll want to keep in mind is exactly how the format of the number part of the file name will look, as this can sometimes affect the ordering of the files in the directory. For example, using the naming convention you give above will sometimes result in a sort order like this:

image1.jpg
image10.jpg
image11.jpg
image2.jpg
image3.jpg
...

This isn't generally what you would want. If you instead pad the number with zeroes up to the maximum number size (in your case 5 digits), the sort order should be maintained better in the directory:

image00001.jpg
image00002.jpg
image00003.jpg
....

To create file names like this, you can use the SPRINTF function. Here's some sample code that renames all the .jpg files in a directory in this way:

dirData = dir('*.jpg');         %# Get the selected file data
fileNames = {dirData.name};     %# Create a cell array of file names
for iFile = 1:numel(fileNames)  %# Loop over the file names
  newName = sprintf('image%05d.jpg',iFile);  %# Make the new name
  movefile(fileNames{iFile},newName);        %# Rename the file
end

The above code also uses the DIR and MOVEFILE functions (as mentioned in the other answers).

这篇关于在MATLAB中重命名图像文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆