资源简介
鉴于普通截图工具的局限性,也是由于自己实验的需求,自己编写了MATLAB的一个可以实现图像旋转并能截图的代码(本代码裁剪的是真彩图像,做相应改动即可旋转裁剪灰度图像),自动读取文件夹里的图像裁剪后保存到指定的文件夹,由于是自己原创,积分较高,相信物有所值!说明:首先在显示的图像里鼠标左击两个点,图像会根据这个角度进行旋转,旋转后再依次左击左右上下四个点,这是就能截取这之间的图像了
代码片段和文件信息
Files = dir(‘D:\李磊\实验视频\可见光图像\ship11\*.jpg‘);
LengthFiles = length(Files);
for i = 1:LengthFiles;
a= imread(strcat(‘D:\李磊\实验视频\可见光图像\ship11\‘Files(i).name));
%a=imread(‘6496.jpg‘);
%a=rgb2gray(a);
figure;imshow(a);
[p1 q1]=size(a);
% disp(p1);disp(q1);
R=a(::1);%R(::[2 3])=0;
G=a(::2);%G(::[1 3])=0;
B=a(::3);%B(::[1 2])=0;
x=input(‘please input a number:‘);
if x==1
R1= fliplr(R);
G1= fliplr(G);
B1= fliplr(B);
fanzhuan=cat(3R1G1B1);
figure;imshow(fanzhuan);
else
fanzhuan=a;
figure;imshow(fanzhuan);
end
R_fanzhuan=fanzhuan(::1);%R(::[2 3])=0;
G_fanzhuan=fanzhuan(::2);%G(::[1 3])=0;
B_fanzhuan=fanzhuan(::3);%B(::[1 2])=0;
[colrow] = ginput(2);
%disp(col);
[mn]=size(a);
xielv=(col(11)-col(21))/((m-row(11))-(m-row(21)));
jiaodu=180*atan(xielv)/3.14;
%disp(jiaodu);
%it1 = imrotate(a90+jiaodu‘nearest‘‘crop‘);
if jiaodu<0
it1=ImageRotate(R_fanzhuan90+jiaodu);it2=ImageRotate(G_fanzhuan90+jiaodu);it3=ImageRotate(B_fanzhuan90+jiaodu);
hecheng=cat(3it1it2it3);
figure imshow(hecheng);
[row_it1col_it1] = ginput(4);
cut_ph= imcrop(hecheng[row_it1(11) col_it1(31) (row_it1(21)-row_it1(11)) (col_it1(41)-col_it1(31))]);
hecheng2=hecheng;
hecheng2(col_it1(31):col_it1(41)row_it1(11):row_it1(21))=0;
figure imshow(hecheng2);
%figure imshow(cut_ph);
end
if jiaodu>0
it1=ImageRotate(R_fanzhuan-(90-jiaodu));it2=ImageRotate(G_fanzhuan-(90-jiaodu));it3=ImageRotate(B_fanzhuan-(90-jiaodu));
hecheng=cat(3it1it2it3);
figure imshow(hecheng);
[row_it1col_it1] = ginput(4);
cut_ph=imcrop(hecheng[row_it1(11) col_it1(31) (row_it1(21)-row_it1(11)) (col_it1(41)-col_it1(31))]);
hecheng2=hecheng;
hecheng2(col_it1(31):col_it1(41)row_it1(11):row_it1(21))=0;
%figure imshow(cut_ph);
end
if jiaodu==0
it3=a;
[row_it1col_it1] = ginput(4);
cut_ph=imcrop(it3[row_it1(11) col_it1(31) (row_it1(21)-row_it1(11)) (col_it1(41)-col_it1(31))]);
hecheng2=it3;
hecheng2(col_it1(31):col_it1(41)row_it1(11):row_it1(21))=0;
%figureimshow(cut_ph);
end
s1=strcat(‘D:\gezhongruanjian\study\MATLAB\anzhuang\bin\cut\第二次\样本\ship11\‘num2str(i+126+137+205+148));
s1=strcat(s1‘.jpg‘);
imwrite(cut_phs1);
s2=strcat(‘D:\gezhongruanjian\study\MATLAB\anzhuang\bin\cut\第二次\剩余结果\ship11剩余结果\‘num2str(i+126+137+205+148));
s2=strcat(s2‘.jpg‘);
imwrite(hecheng2s2);
close all;
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3102 2014-01-25 11:36 ImageRotate.m
文件 2558 2014-02-26 15:35 cut.m
----------- --------- ---------- ----- ----
5660 2
- 上一篇:最好用的串口调试助手_MATLAB
- 下一篇:雷达系统仿真
评论
共有 条评论