www.gusucode.com > matlab编写的图像几何变换的程序源码 > main.m
%This is the main program. %The original paper works only for scaling s_x=s_y, so does the program. %clc clear close all tic ref=imread('校正后的图像.png'); %ref=rgb2gray(ref); % ref=rgb2gray(ref); ref=im2double(ref); %figure,imshow(ref); fprintf('Image loading completed!\n'); %test parameter setting x_o=0; %vertical displacement y_o=0; %horizontal displacement s=1/0.5; %scaling factor theta=55.094; %rotation in degrees (positive for counterclockwise, negative for clockwise) %perform the changes to both ref and test, keep them same size %[ref, test]=imtrans(ref, ref, x_o, y_o); %display the changed pictures %figure, %subplot(2,2,1),imshow(ref); r_1=ref; %subplot(2,3,2),imshow(test); [ref, test]=imtrans(ref, ref, x_o, y_o); %平移变换 [ref1, test1]=imscale(test, test, s); %缩放变换 %subplot(2,3,3),imshow(ref); %subplot(2,3,4),imshow(test); [ref2, test2]=imrot(test1, test1, theta); %旋转变换 %subplot(2,3,5),imshow(ref); %subplot(2,2,2),imshow(test); % ref=imcrop(ref,[20 20 110 102]); % test=imcrop(test,[30 30 150 150]); % ref1=imcrop(ref1,[30 30 150 150]); % test1=imcrop(test1,[30 30 150 150]); % ref2=imcrop(ref2,[30 30 150 150]); test2=imcrop(test2,[215 215 146 149]); fprintf('Image transform completed!\n'); % imwrite(test2,'校正后的图像.png','png'); figure(1); imshow(ref); % figure(2); % imshow('平移后的图像.png'); % figure(3); % imshow('平移后缩放前的图像.png'); % figure(4); % imshow('平移后缩放后的图像.png'); % figure(5); % imshow('平移后缩放后旋转前的图像.png'); figure(6); imshow('校正后的图像.png'); figure(1); ref=imcrop(ref); figure(2); test=imcrop(test); figure(3); ref1=imcrop(ref1); figure(4); test1=imcrop(test1); figure(5); ref2=imcrop(ref2); figure(6); test2=imcrop(test2); imwrite(ref,'平移前的图像.png','png'); imwrite(test,'平移后的图像.png','png'); imwrite(ref1,'平移后缩放前的图像.png','png'); imwrite(test1,'平移后缩放后的图像.png','png'); imwrite(ref2,'平移后缩放后旋转前的图像.png','png'); figure(7); subplot(2,4,1),Imshow(r_1),title('(a) 原图像(256X256 pixels)'); %%一页显示4个图 subplot(2,4,2),imshow(ref),title('(c)平移前的图像'); subplot(2,4,6),imshow(test),title('(c)平移后的图像'); subplot(2,4,3),imshow(ref1),title('(e) 平移后缩放前的图像'); subplot(2,4,7),imshow(test1),title('(e) 平移后缩放后的图像'); subplot(2,4,4),imshow(ref2),title('(b) 平移后缩放后旋转前的图像'); subplot(2,4,8),imshow(test2),title('(b) 平移缩放旋转后的图像'); subplot(2,3,5),imshow(r_4),title('(d)图(b)的对数极坐标图像 '); subplot(2,3,6), surf(abs(g)), shading flat %% 用mesh和surf这两个函数显示效果一样的 title('(f) FFT反变换曲线显示角度与比例系数');% figure,mesh(abs(g)); grid on toc