[数字图像处理]最近邻插值和双线性插值(nearest neighbor interpolation and bilinear interpolation)实验报告

Introduction:

Through this LAB, I have known the principle and formula of nearest neighbor interpolation and bilinear interpolation, and Use nearest neighbor interpolation and bilinear interpolation to interpolate a grey scale image. At the same time, I find some aspects that can be optimized in these two methods.

Lab results & Analysis:

  1. Use nearest neighbor interpolation to interpolate a grey scale image:
  1. Introduction of the nearest neighbor interpolation algorithm:

Figure 1 the area of pixels

 

Let i + u, j + v (i, j is a positive integer, u, v is a decimal greater than zero and less than 1) be the pixel coordinate we want to get, then the greyscale we want to know is f (i + u, j + v).

If (i + u, j + v) falls in area A, that is u<0.5 and v<0.5, the greyscale of the upper-left pixel will be assigned to the pixel we want to get. Similarly, if it falls in area B, the greyscale of the upper-right pixel will be assigned; if it falls in area C, the greyscale of the lower-left pixel will be assigned; if it falls in area D, the greyscale of the lower-right pixel will be assigned.

This algorithm is simple and easy to understand and program, so that I will not write the pseudo code for this algorithm. I will give detailed comments in the program.

 

  1. Matlab codes:
clear;

close all;

clc;

img = imread('rice.tif');

[ input_img,new_img ] = Nearest_11711118(img,[.8,.8]);

show(img,new_img);



function show(img,new_img)%print the figure

[height,width] = size(img);

figure;imshow(img);

axis on

title(['Input Figure with Size(',num2str(height),'*',num2str(width),'):']);

[new_height,new_width,] =size(new_img);

figure;imshow(new_img);

axis on

title(['Output Figure with Size( ',num2str(new_height),'*',num2str(new_width),'):']);

end



function[ input_img,new_img ]= Nearest_11711118(input_img, dim)





input_img=double(input_img);

swh=size(input_img); %Get the width and height of the original image



inputWidth=swh(:,2); %Get the width  of the original image

inputHigh=swh(:,1); %Get the  height of the original image

r=dim(:,1);

c=dim(:,2);

outputHigh=ceil(inputHigh * c);

outputWidth=ceil(inputWidth * r);

new_img=zeros(outputHigh,outputWidth);

orignalx = [1:outputHigh];

orignaly = [1:outputWidth];

for i=1:outputHigh

    orignalx(i)=round(i/r);

end

for j=1:outputWidth

    orignaly(j)=round(j/c);

end

for i=1:outputHigh

    for j=1:outputWidth

      

        if(orignalx(i) < 1) %If the coordinates cross the border, make adjustments

                        orignalx(i) = 1;

        end

        if(orignalx(i) > inputHigh)

            orignalx(i) = swh;

        end

        if(orignaly(j) < 1)

            orignaly(j) = 1;

    
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值