close all;
clc;
clear;
%原图的路径
List = zeros(60,2);
for i=1:60
save_path='C:\Users\Lenovo\Desktop\test2\';%循环目录
img_path_list = dir(strcat(save_path,'*.png'));%找出所有png图片信息
picture_name=img_path_list(i).name;%提出png图片的名字
A = imread(strcat(save_path,picture_name));%读入图片
Size=size(A);
S1=Size(1);
S2=Size(2);
nw=300;%裁剪图的宽
nh=300;%裁剪图的高
b=randperm(S1-nw,1);
a=randperm(S2-nh,1);
JA=imcrop(A,[a b nh-1 nw-1]);%imcrop 先高后宽
filepath=pwd; %保存当前工作目录
cd('C:\Users\Lenovo\Desktop\test1') %把当前工作目录切换到指定文件夹
new_name=strcat(num2str(i),'test_',picture_name);
imwrite(JA,new_name);
cd(filepath) %切回原工作目录
AA=[a+150,b+150];
List(i,:) = AA;
end