当前位置:网站首页>matlab实现对图像批量重命名
matlab实现对图像批量重命名
2022-06-23 22:18:00 【HH~LL】
在实验过程中,图片命名不规范,可能会给我们后续处理数据带来很大的麻烦,因为一般程序从文件夹读取图像先按图片命名读取的,如果是1000张图像,从1开始命名,即1——1000,读取顺序并不是1 2 3…,而是1 10 11 12 …100会先读取1开头的 再读取2开头的,相当于乱序读取。所以有必要对图像规范命名。
如果图片总数大于1000,可以修改内层for循环里面的条件和0的个数
file_path1='待批量命名图像文件夹';
file_path2='命名之后图片保存的文件夹';
img_path_list = dir(strcat(file_path1,'*.png'));%获取该文件夹中所有jpg格式的图像
img_num = length(img_path_list);%获取图像总数量
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name_old = img_path_list(j).name;% 图像名
if j<10
image_name_new = strcat('000',num2str(j),'.png');
image = imread(strcat(file_path1,image_name_old));
imwrite(image,strcat(file_path2,image_name_new))
elseif j>=10 && j<100
image_name_new = strcat('00',num2str(j),'.png');
image = imread(strcat(file_path1,image_name_old));
imwrite(image,strcat(file_path2,image_name_new))
elseif j>=100
image_name_new = strcat('0',num2str(j),'.png');
image = imread(strcat(file_path1,image_name_old));
imwrite(image,strcat(file_path2,image_name_new))
end
end
end
边栏推荐
猜你喜欢

CVPR2019/图像翻译:TransGaGa: Geometry-Aware Unsupervised Image-to-Image Translation几何感知的无监督图像到图像的翻译

PyQt5_ Qtablewidget paging radio right-click menu control

6月25日PMP考试敏捷怎么考?替你分忧解难

STM32------ADC(电压检测)

【HackTheBox】Fawn

Golang type assertion

What is the production process of enterprise website? How long does it take to design and build a website?

AUTOCAD——总结CAD画圆角的三种方式

6 大完整开源项目,一次学个够
![入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式](/img/8c/b1535e03900d71b075f73f80030064.png)
入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式
随机推荐
6月25日PMP考试敏捷怎么考?替你分忧解难
MySQL索引底层为什么用B+树?看完这篇文章,轻松应对面试。
Thinking (87): Protocol encryption and compression
Bitmap load memory analysis
推荐4个Flutter重磅开源项目
Task queue of laravel
老龄化下背景下,综合能效管理平台为医院保驾护航
How to achieve the turning effect of wechat video recording?
Is the geTx status management in the flutter really so good to use?
Activity的onSaveInstanceState回调时机
NLog details
腾讯会议号设计的几种猜测
在OpenCloudOS使用snap安装.NET 6
Postman返回值中文乱码????
一个人竟然撸了一个微博 APP
PMP考试相关计算公式汇总!考前必看
Androidkotlin comprehensive and detailed class usage grammar learning guide
泰勒公式及常用展开
图论(树的直径)
图像分割-数据标注