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 Center および File ExchangeGeometric 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