使用 matlab 数字图像处理(三)—— 实现图像的旋转(不使用 imrotate)

                       
 

图像的旋转是不改变图像的灰度值的,这是将原始位置映射到新的位置。

[x 1  y 1  1 ]=[x 0  y 0  1 ]⎡ ⎣ ⎢ cosθsinθ0 sinθcosθ0 001 ⎤ ⎦ ⎥  [x1y11]=[x0y01]⋅[cos⁡θsin⁡θ0−sin⁡θcos⁡θ0001]

Image = imread('pout.tif');[X,Y]=size(Image); imshow(Image); Angle = pi/6;%计算四个角点的新坐标,确定旋转后的显示区域 LeftTop(1,1)=-(Y-1)*sin(Angle); LeftTop(1,2)=(Y-1)*cos(Angle); LeftBottom(1,1)=0; LeftBottom(1,2)=0; RightTop(1,1)=(X-1)*cos(Angle)-(Y-1)*sin(Angle); RightTop(1,2)=(X-1)*sin(Angle)+(Y-1)*cos(Angle); RightBottom(1,1)=(X-1)*cos(Angle); RightBottom(1,2)=(X-1)*sin(Angle); %计算显示区域的行列数 Xnew=max([LeftTop(1,1),LeftBottom(1,1),RightTop(1,1),RightBottom(1,1)])-min([LeftTop(1,1),LeftBottom(1,1),RightTop(1,1),RightBottom(1,1)]); Ynew=max([LeftTop(1,2),LeftBottom(1,2),RightTop(1,2),RightBottom(1,2)])-min([LeftTop(1,2),LeftBottom(1,2),RightTop(1,2),RightBottom(1,2)]); % 分配新显示区域矩阵 ImageNew=zeros(round(Xnew),round(Ynew)); %计算原图像各像素的新坐标 for indexX=0:(X-1)     for indexY=0:(Y-1)       ImageNew(round(indexX*cos(Angle)-indexY*sin(Angle))+ ...               round(abs(min([LeftTop(1,1),LeftBottom(1,1),          RightTop(1,1),RightBottom(1,1)])))+1,1+round(indexX*sin(Angle)+indexY*cos(Angle))+round(abs(min([LeftTop(1,2),LeftBottom(1,2),RightTop(1,2),RightBottom(1,2)]))))=Image(indexX+1,indexY+1);   end  end h=(ImageNew)/255; h=medfilt2(h); figure,imshow(h) imwrite(h,'rotate.jpg','quality',100);
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/hftytf/article/details/87711938
今日推荐