Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何使用Matlab通过最近邻插值旋转图像

我的不带插值的纯代码:

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((im/2)*cos(thet)-(jn/2)*sin(thet)+m1/2); s = uint16((im/2)*sin(thet)+(jn/2)*cos(thet)+n1/2); if t~=0 && s~=0 im2(t,s,:)=im1(i,j,:); end end end figure; imshow(im2); 这段代码会产生黑点,问题是怎么做插值?谢谢大家的照亮。 PS不要求内置功能:imrotate(im1,1 / thet,'nearest');


回答:
要旋转没有黑点的图像,您需要反向旋转。

旋转矩阵的逆是它的转置。同样,旋转的图像始终更大,最大旋转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
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 12:17


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.