更换文件夹中图像的名字

更换一个文件夹中图像的名字。

 clc;
 clear;
 close all;
 file_path =  'images\'; %被更换名字的图像文件夹路径
 savepath = 'out\';%更换名字后保存在该文件夹
 img_path_list = dir([file_path,'*.png']);  
 img_num = length(img_path_list); %该文件夹中图像数量 
 if img_num > 0  
      for j = 1:img_num  
            image_name = img_path_list(j).name;% 输入图像名 
            image_name2Temp = sprintf('%05d',j);
            image_name2 = strcat(image_name2Temp,'.png');% 输出图像名
            image =  imread([file_path,image_name]);  
            fprintf('%d %s\n',j,strcat(file_path,image_name));% 显示正在处理的路径和图像名  
            imwrite(image,strcat(savepath,image_name2));
     end  
 end  

猜你喜欢

转载自blog.csdn.net/u013925378/article/details/82792322