dir_struct = dir(inputpath);
[names,index] = sortrows({dir_struct.name}');
outputpath='E:\FaceTrain\negpic';
len = length(names);
for i=1:len
[path0,name,ext] = fileparts(names{i});
switch ext;
case {'.bmp','.jpg'}
filename=strcat(inputpath,'\',names{i});
img=imread(filename);
hold on;
imshow(img);
[m,n]=size(img);
rect=getrect;
x = round(rect(1));
y = round(rect(2));
w = round(rect(3));
h = round(rect(4));
rect=[x,y,w,h];
rectangle('Position',rect,'facecolor',[0,0,0]);
img(y:(y+h),x:(x+w),:)=0;
num=num2str(i);
negpicname = strcat('neg_',num,'.jpg');
negfilename=strcat(outputpath,'\',negpicname);
imwrite(img,negfilename);
hold off;
break;
end;
end;