1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| I=handles.myimage; button = questdlg('请选择复合变换方式第一步','请选择','平移','旋转','平移'); switch button case '平移' [m,n]=size(I); size1=size(I); dimension=numel(size1) if dimension==3 I=rgb2gray(I); end I2=zeros(m,n);%初始化的是double类型的 defaulta={'20'}; defaultb={'50'}; tmpx=inputdlg('请输入x轴平移距离:','',1,defaulta); tmpy=inputdlg('请输入y轴平移距离:','',1,defaultb); dx=str2double(tmpx); dy=str2double(tmpy); I2(dx+1:m,dy+1:n)=I(1:m-dx,1:n-dy); axes(findobj('tag','axes2')); imshow(uint8(I2)); I2=uint8(I2); button1 = questdlg('请选择复合变换方式第二步','请选择','仿射','旋转','缩放','仿射'); switch button1 case '旋转' [m n]=size(I2); defaulta={'45'}; tmpa=inputdlg('请输入旋转角度:','',1,defaulta); angle=str2double(tmpa); I3=imrotate(I2,angle); imshow(I3); case '仿射' I=I2; defaulta={'40'}; defaultb={'40'}; tmpa=inputdlg('请输入仿射变换矩阵的值一:','',1,defaulta); tmpb=inputdlg('请输入仿射变换矩阵的值二:','',1,defaultb); x1=str2double(tmpa); y1=str2double(tmpb); xform=[1,0,0;0,1,0;x1,y1,1]; tform_translate=maketform('affine',xform); res = imtransform(I, tform_translate,'XData', [1 (size(I,2)+ xform(3,1))],'YData', [1 (size(I,1)+ xform(3,2))]); axes(findobj('tag','axes2')); imshow(res); case '缩放' I=I2; defaulta={'0.05'}; times=inputdlg('请输入缩放倍数:','',1,defaulta); time=str2double(times); res=imresize(I,time); axes(findobj('tag','axes2')); imshow(res); end case '旋转' [m n]=size(I); defaulta={'45'}; tmpa=inputdlg('请输入旋转角度:','',1,defaulta); angle=str2double(tmpa); I2=imrotate(I,angle); axes(findobj('tag','axes2')); imshow(I2); button2 = questdlg('请选择复合变换方式第二步','请选择','仿射','投影','仿射'); switch button2 case '仿射' I=I2; defaulta={'40'}; defaultb={'40'}; tmpa=inputdlg('请输入仿射变换矩阵的值一:','',1,defaulta); tmpb=inputdlg('请输入仿射变换矩阵的值二:','',1,defaultb); x1=str2double(tmpa); y1=str2double(tmpb); xform=[1,0,0;0,1,0;x1,y1,1]; tform_translate=maketform('affine',xform); res = imtransform(I, tform_translate,'XData', [1 (size(I,2)+ xform(3,1))],'YData', [1 (size(I,1)+ xform(3,2))]); axes(findobj('tag','axes2')); imshow(res); case '投影' a=I2; button3 = questdlg('请选择投影方式','请选择','垂直','水平','垂直水平','垂直'); switch button3 case '垂直' [m,n]=size(a); i2(1:m,1:n)=a(m:-1:1,1:n); axes(findobj('tag','axes2')); imshow(i2); case '水平' [m,n]=size(a); i2(1:m,1:n)=a(1:m,n:-1:1); axes(findobj('tag','axes2')); imshow(i2); case '垂直水平' [m,n]=size(a); i2(1:m,1:n)=a(m:-1:1,n:-1:1); axes(findobj('tag','axes2')); imshow(i2); end end end
|