MATLAB imrotate函数的用法2010-12-21 13:17:31
Imrotate 函数用来实现图像旋转: B=imrotate(A,angle, method,bbox);
angle 绕图形中心逆时针旋转的角度(deg)(angle为负值时为顺时针旋转角度)。
method就是你实现旋转用的是什么方法。有三种:最邻近插值法'nearest',双线性插值法'bilinear',三次卷积插值法'bicubic'。不同的插值方法得到的旋转图像有细微的差别。如不选,则matlab默认最邻近插值法。图像旋转后会有一定的失真(因计算每个点的新坐标的时候得到的数值不是整数,要取整造成的)。
Bbox指定输出图像属性。2选择:‘loose’或‘crop’。前者(Matlab默认),图像旋转后系统给予一个‘宽松’的环境去匹配它,得到的图片是完整的(Make output image large enough to contain the entire rotated image. Image B is generally larger than A)。‘crop’(剪切),超过图片原来大小的部分被crop了(Make output image B the same size as the input image A, cropping the rotated image to fit)。
例1:
A=imread('J:\EC_System.jpg'); % A, <325x464 uint8>
subplot(1,3,1)
imshow(A);
B=imrotate(A,30,'bilinear'); % 反时针旋转30 ,默认‘loose’。
subplot(1,3,2) %B, <517x565 uint8>
imshow(B);
C=imrotate(A,30,'bilinear','crop'); % C, <325x464 uint8>
subplot(1,3,3)
imshow(C);
例2:使用imrotate函数在matlab中产生一个斜矩形:
clear; clc;
w = 640;
h = 640;
A=zeros(h, w);
% create a oblique(45) rectangle in the matrix
x1 = int32(w / 5 * 2); x2 = int32(w / 5 * 3);
y1 = int32(h / 7); y2 = int32(h / 7 * 6);
% 下面这句代码产生一个常规矩形
A(y1:y2, x1:x2) = 1; A