您的位置:首页 > 编程语言 > MATLAB

Matlab截图小工具

2016-05-11 20:02 531 查看
代码:

%%
%img_path:图像所在文件夹
%save_path:裁剪后的图像保存文件夹
%双击左键不截图,跳到下一张
%%
img_path='E:\image\';
save_path='E:\image\';
name_beg=0;%截取的图像保存名字从0开始

Files = dir(img_path);
for j=1:length(Files)
if strcmp(Files(j).name,'.') || strcmp(Files(j).name,'..') || ~strcmp(Files(j).name(end-3:end),'.jpg')
continue;
end
I=imread(strcat(img_path,Files(j).name));
imshow(I);
[x,y] = ginput(2);
if x(1)==x(2) && y(1)==y(2)
continue;
end
rect=[x(1),y(1),x(2)-x(1),y(2)-y(1)];
J=imcrop(I,rect);
name=strcat(num2str(name_beg),'.jpg');
imwrite(J,strcat(save_path,name));
name_beg=name_beg+1;
end


(默认图像为jpg格式,可修改)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: