用matlab批量修改图片名称

前言:在网上看了一些修改图片名称的代码,发现很多都没有达到预期的结果,所以在这里把我的代码贴出来,仅供大家参考,
也希望帮到大家少走一些弯路。

file_path1='G:\VOC2012dataset\imageDataset\tvmonitor\';
file_path2='G:\VOC2012dataset\train\tvmonitor\';
img_path_list = dir(strcat(file_path1,'*.jpg'));%获取该文件夹中所有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),'.jpg');
            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),'.jpg');
            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),'.jpg');
            image = imread(strcat(file_path1,image_name_old));
            imwrite(image,strcat(file_path2,image_name_new))
        end

    end 
end 

图片以0001,0002,…xxxx格式存储。

  • 12
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值