資源簡介
matlab實現圖像的旋轉變換,源代碼。。。。。。
代碼片段和文件信息
function?Y?=?rotate(figure_namedegbox)
%figure_name??為要旋轉的圖像名稱
%deg?為要旋轉的角度
%box?為旋轉的類型:
%如果box?為‘crop‘則保持圖像大小不變,旋轉后超出原圖像邊界的部分不予顯示;
%如果box?為‘loose‘則保持圖像的完整性,旋轉后圖像可以看到完整的圖像;
%程序默認為‘loose‘類型;
if?nargin<3
????box?=?‘loose‘;
end
I?=?imread(figure_name);%讀入圖像信息;若為彩色圖像,則將其轉換為灰度圖
if?size(I3)==3
????I?=?rgb2gray(I);
end
deg?=?deg*pi/180;
Row?=?size(I1);?Col?=?size(I2);
A?=?[cos(deg)?-sin(deg);sin(deg)?cos(deg)];%?A?為旋轉變換矩陣;
AA?=?[cos(deg)?sin(deg);-sin(deg)?cos(deg)];%?AA?為旋轉變化的逆過程的矩陣;
new(1:)?=?[11]*A;
new(2:)?=?[1Col]*A;
new(3:)?=?[Row1]*A;
new(4:)?=?[RowCol]*A;
offset?=?min(new);??%
評論
共有 條評論