How to rotate an image using interpolation?

조회 수: 17 (최근 30일)
Behrad kiani
Behrad kiani 2012년 3월 31일
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
Image Analyst
Image Analyst 2012년 5월 16일
Why don't you "use the provided functions" such as imrotate?

댓글을 달려면 로그인하십시오.

답변 (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에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by