我有一个二进制图像lu,当我旋转图像时,图像的大小会改变,但我需要保留图像的大小:
m=2048;
n=3072;
ODcenter =1.0e+03 *[2.0345 0.9985]
OD=ODcenter ;
X=zeros(m,n); %% m,n is size of image
t = 0:.1:2*pi;
ODradius = norm(ODcenter(2) - ODcenter(1)) / 2;
xm2 = round(2*ODradius*cos(t)+OD(1));
ym2 = round(2*ODradius*sin(t)+OD(2));
imCircleAlphaData2 = roipoly(X,xm2,ym2);
figure; imshow(imCircleAlphaData2);
lu=imCircleAlphaData2;
mask1 = true(size(lu)); %# Create a matrix of true values the same size
mask1(ODcenter(2):end,:) = false; %# Set the lower half to false
lu(~mask1) = 0; %# Set all elements in lu corresponding to mask 1==0
mask2 = true(size(lu));
mask2(:,ODcenter(1):end) = false; %# Set the right of the upper half to false
lu(~mask2) = 0; %# Set all elements in lu corresponding mask 2==0
figure;
imshow(lu); % shows left upper
lurot= imrotate(lu,45);
figure,imshow(lurot)
lurot和lu的大小不同。即使旋转后裁剪图像的某些部分
,如何保留图像的大小答案 0 :(得分:0)
基本上,Matlab imrotate
有两个选项:
crop
将输出图像与输入图像尺寸相同,裁剪旋转后的图像以使其适合loose
可使输出图像足够大,以包含整个原始旋转图像。通常,这会使输出图像大于输入图像。lurot= imrotate(lu,45,'nearest','crop');