Matlab学习 ---图像旋转(最邻近像素法)

function output = translate(input,angel);

H = 1;
W = 2;
%angel = 45;
img = imread(input);
%img = imread('C:\Users\anyka001\Desktop\Lena_1.png');
[row col] = size(img);
theta = angel/180 *pi;

rot = [cos(theta) -sin(theta) 0;sin(theta) cos(theta) 0;0 0 1];
inv_rot = inv(rot);
pix1 = [1 1 1]*rot;
pix2 = [1 col 1]*rot;
pix3 = [row 1 1]*rot;
pix4 = [row col 1]*rot;
Width =round(max([abs(pix1(W)-pix4(W)) abs(pix2(W)-pix3(W))]));
Hight =round(max([abs(pix1(H)-pix4(H)) abs(pix2(H)-pix3(H))]));


output = zeros(Hight,Width);

delte_x = abs(min([pix1(W) pix2(H) pix3(W) pix4(W)]));
delte_y = abs(min([pix1(H) pix2(H) pix3(H) pix4(H)]));

for y = 1-delte_y:Hight-delte_y
    for x = 1-delte_x:Width-delte_x
        pix=[y x 1]*inv_rot;

        if pix(H)>=0.5 && pix(W)>=0.5 && pix(H)<=row && pix(W)<=col
            output(y+delte_y,x+delte_x)=img(round(pix(H)),round(pix(W)));
        end
    end
end

output1= uint8(output);

imwrite(output1,'C:\Users\anyka001\Desktop\learn Matlcb\translate.png','png');

figure,imshow(output1);

函数实现图像任意角度反转。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值