windows+ubuntu下文件批量命名ubuntu
在windows下能够采用matlab程序来对全部文件按顺序进行批量命名,以图片为例,代码以下:windows
path = 'C:\Users\Administrator\Desktop\select_img\';%全部图片存放的路径 D = dir([path '*.jpg']);%将该路径下的全部文件读取成一个结构体 for i = 1:length(D)%遍历每一张图片 image_name = D(i).name;%每一张图片的名字 I = imread(strcat(path,image_name));%读取每一张图片 nz = strcat('%0',num2str(6),'d');%给该图片重命名名字的位数 temp_id = sprintf(nz,i);%按序数给全部图片命名,前面补0 name2 = strcat(temp_id,'.jpg'); imwrite(I,name2);%以新名字保存图片 end
在ubuntu下能够采用在文件夹下的终端输入脚本程序的方式,对全部文件按照顺序进行批量命名,脚本程序以下:spa
# 先输入下面两行指令,按序号为全部文件命名,并且为了不与以前的名字冲突(好比以前的名字中有数字的状况),全部名字后面加上字母a declare -i num=0; for name in `ls`;do mv -f $name `echo $num"a.jpg"`; num=num+1; done # 再输入下面两行指令,按照序号从新给全部文件命名 declare -i num=0; for name in `ls`;do mv -f $name `echo $num".jpg"`; num=num+1; done
根据ground truth在原图中分割子图code
base_path = 'D:\image\people'; %全部原图路径 bb = importdata('output.txt');%全部原图对应的ground truth文件 output_img = cell(100);%这里假设原图有100张 for i = 1:100 nz = strcat('%0',num2str(4),'d'); temp_id = sprintf(nz,i); id = strcat(temp_id,'.jpg'); img_path = fullfile(base_path,id); temp_img = imread(img_path); output_img = temp_img(bb.data(i,2):bb.data(i,4),bb.data(i,1):bb.data(i,3),:); filename = strcat('D:\image\output\',temp_id,'.jpg');%分割出的子图保存路径 imwrite(output_img,filename); end