How to rotate an image using interpolation?

11 views (last 30 days)
Behrad kiani
Behrad kiani on 31 Mar 2012
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);
  1 Comment
Image Analyst
Image Analyst on 16 May 2012
Why don't you "use the provided functions" such as imrotate?

Sign in to comment.

Answers (3)

sepideh tork
sepideh tork on 15 Feb 2013
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 on 1 Apr 2012
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 Comment
sepideh tork
sepideh tork on 14 Feb 2013
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?

Sign in to comment.


Alex Taylor
Alex Taylor on 16 May 2012
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.

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!