如何使用Matlab通过最近邻插值旋转图像

Mea*_*ins 12 matlab image-processing nearest-neighbor image-rotation

我的普通代码没有插值:

im1 = imread('lena.jpg');imshow(im1);    
[m,n,p]=size(im1);
thet = rand(1);
m1=m*cos(thet)+n*sin(thet);
n1=m*sin(thet)+n*cos(thet);    

for i=1:m
    for j=1:n
       t = uint16((i-m/2)*cos(thet)-(j-n/2)*sin(thet)+m1/2);
       s = uint16((i-m/2)*sin(thet)+(j-n/2)*cos(thet)+n1/2);
       if t~=0 && s~=0           
        im2(t,s,:)=im1(i,j,:);
       end
    end
end
figure;
imshow(im2);
Run Code Online (Sandbox Code Playgroud)

这段代码会产生黑点,问题是如何进行插值?谢谢大家的任何照明.PS不要求内置函数:imrotate(im1,1/thet,'nearest');

sjc*_*hoi 11

要旋转没有黑点的图像,您需要反方向.

旋转矩阵的倒数是它的转置.此外,旋转的图像总是更大,最大是45度旋转.因此,sqrt(2)因素

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);
Run Code Online (Sandbox Code Playgroud)


Amr*_*mro 6

我记得有一个先前的问题上,这样也有类似的问题.

我的想法是以相反的方向映射像素; 对于旋转图像中的每个像素,找到在原始图像中映射到它的像素,然后问题变得更加简单.

我目前无法访问MATLAB,但我认为这是可行的.这里的困难是循环旋转的图像像素.