matlab实现图片缩放

利用双线性插值实现
zoomNum为缩放系数
height和width的命名可能反了,不要在意这些细节…
一开始用subplot输出两幅图片,明明已经得到一个更大的矩阵了但就是死活看不出效果,后来求助于助教才知道subplot会让它们输出大小一致(吐血)…

    I=imread('tissue.png');
    figure(1);
    imshow(I)
    zoomNum=0.5;
    [fWidth fHeight]=size(I);
    fHeight=fHeight/3;
    cWidth=floor(fWidth*zoomNum);
    cHeight=floor(fHeight*zoomNum);
    res=zeros(cWidth,cHeight,3);
    %四个顶点
    res(1,1,:)=I(1,1,:);
    res(1,cHeight,:)=I(1,fHeight,:);
    res(cWidth,1,:)=I(fWidth,1,:);
    res(cWidth,cHeight,:)=I(fWidth,fHeight,:);
    %四条边界
    for dstX=2:cWidth-1
        srcX=dstX/zoomNum;
        i=floor(srcX);u=srcX-i;
        res(dstX,1,:)=u*I(i,1,:)+(1-u)*I(i+1,1,:);
        res(dstX,cHeight,:)=u*I(i,fHeight,:)+(1-u)*I(i+1,fHeight,:);
    end
    for dstY=2:cHeight-1
        srcY=dstY/zoomNum;
        i=floor(srcY);u=srcY-i;
        res(cWidth,dstY,:)=u*I(fWidth,i,:)+(1-u)*I(fWidth,i+1,:);
        res(1,dstY,:)=u*I(1,i,:)+(1-u)*I(1,i+1,:);
    end
    %中间
    for dstX=2:cWidth-1
        for dstY=2:cHeight-1
            srcX=dstX/zoomNum;
            srcY=dstY/zoomNum;
            i=floor(srcX);u=srcX-i;
            j=floor(srcY);v=srcY-j;
            res(dstX,dstY,:)=(1-u)*(1-v)*I(i,j,:)+(1-u)*v*I(i,j+1,:)+u*(1-v)*I(i+1,j,:)+u*v*I(i+1,j+1,:);
        end
    end
    figure(2);
    imshow(uint8(res));
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值