How to rotate an image using interpolation?

12 次查看(过去 30 天)
I am using the code below to rotate an image . but I don’t know how to write interpolation function by myself and don't use the provided functions . I think for interpolation I have to use 4 equation and find 4 variable but I don’t know how to implement it.
Trotation=[cos(pi/4) sin(pi/4) 0 -sin(pi/4) cos(pi/4) 0 0 0 1];
Tpic=imread('D:\projects\University\Image proccessing\Rotation\1.jpg');
tform=maketform('affine' , Trotation);
g=imtransform(Tpic , tform);
imshow(g);

回答(3 个)

sepideh tork
sepideh tork 2013-2-15
im1 = imread('lena.jpg');imshow(im1);
[m,n,p]=size(im1);
thet = rand(1);
mm = m*sqrt(2);
nn = n*sqrt(2);
for t=1:mm
for s=1:nn
i = uint16((t-mm/2)*cos(thet)+(s-nn/2)*sin(thet)+m/2);
j = uint16(-(t-mm/2)*sin(thet)+(s-nn/2)*cos(thet)+n/2);
if i>0 && j>0 && i<=m && j<=n
im2(t,s,:)=im1(i,j,:);
end
end
end
figure;
imshow(im2);code
end

Aaditya Kalsi
Aaditya Kalsi 2012-4-1
The idea is to find out the mapping of each pixel in the rotated image w.r.t the original image. Instead of saying (1, 1) in the original image is now at (3.4, 6.1), do the opposite. (1, 1) in the new image is (.4, 1.4) in the original one. You can now use Bilinear Interpolation to figure out the value. You can google Bilinear Interpolation for more details. Go through each (i, j) in the new image and bilinearly interpolate.
  1 个评论
sepideh tork
sepideh tork 2013-2-14
i think its a good way to rotate image without using provide function, but how can writte the code? i mean finding the spatial of each pixel and make new oriention?

请先登录,再进行评论。


Alex Taylor
Alex Taylor 2012-5-16
If you want to apply pure rotation to an image, there is a specific Image Processing Toolbox function imrotate that will do this without the need to construct a transform matrix.
I = fitsread('solarspectra.fts');
I = mat2gray(I);
J = imrotate(I,-1,'bilinear','crop');
figure, imshow(I)
figure, imshow(J)
Imrotate provides three interpolation options: bicubic, bilinear, and nearest neighbor. I'm not clear from your question whether you need to implement some sort of custom interpolation routine to use in the resampling step. If you are happy with these interpolation options, imrotate is the way to go.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by