实验要求:

Zooming and Shrinking Images by Bilinear Interpolation

Objective

To manipulate another technique of zooming and shrinking images by bilinear interpolation.

Main requirements:

Ability of programming with C, C++, or Matlab.

Instruction manual:

(a) Write a computer program capable of zooming and shrinking an image by bilinear interpolation. The input to your program is the desired size of the resulting image in the horizontal and vertical direction. You may ignore aliasing effects.

(b) Download Fig. 2.19(a) and use your program to shrink this image from 1024 x 1024 to 256 x 256 pixels.

(c) Use your program to zoom the image in (b) back to 1024 x 1024. Explain the reasons for their differences.

这次实验通过自己编写双线性内插法的程序来对图像进行缩放。

简要介绍一下双线性内插法的原理:



第一种情况:

  1. 点(i-b, j-a)与点(i-b, j+rate-a)插值得到点(1-b, j)处的灰度值;
  2. 点(i+rate-b, j-a)与点(i+rate-b, j+rate-a)插值得到点(i+rate-b, j)处的灰度值;
  3. 使用前面得到的结果,即点(i-b, j)与点(i+rate-b, j)进行插值得到点(i,j)处的灰度值。

第二种情况:

  1. 点(i-b, j-a)与点(i+rate-b, j-a)插值得到点(i, j-a)处的灰度值;
  2. 点(i-b, j+rate-a)与点(i+rate-b, j+rate-a)插值得到点(i, j+rate-a)处的灰度值;
  3. 使用前面得到的结果,即点(i, j-a)与点(i, j+rate-a)进行插值得到点(i,j)处的灰度值。

从示意图来看比较好理解了,详细的资料还可以参看下面的资料链接:

百度百科:双线性插值

双线性插值(Bilinear Interpolation)

代码部分:

matlab 函数文件名: Bilinear_Interpolation.m

%%

function img=Bilinear_Interpolation(a,rate)
[m,n]=size(a);
ratex=rate-1;
img=zeros(m+ratex*(m-1),n+ratex*(n-1));
for i=1:m
for j=1:n
img(i+ratex*(i-1),j+ratex*(j-1))=a(i,j);
end;
end;
img=double(img);
for i=1:m+ratex*(m-1)
for j=1:n+ratex*(n-1)
a=mod(j-1,rate);
b=mod(i-1,rate);
if a~=0 && b==0
img(i,j)=round((a*img(i,j+(rate-a))+(rate-a)*img(i,j-a))/rate);
end;
if a==0 && b~=0
img(i,j)=round((b*img(i+(rate-b),j)+(rate-b)*img(i-b,j))/rate);
end;
if a~=0 && b~=0
img(i,j)=round((b*(a*img(i-b,j+(rate-a))+(rate-a)*img(i-b,j-a))/rate+(rate-b)*(a*img(i+(rate-b),j+(rate-a))+(rate-a)*img(i+(rate-b),j-a))/rate)/rate);
end;
end;
end;
img=uint8(img);

程序中调用编写好的Bilinear_Interpolation函数,查看结果:

%%
clear all;
clc;
close all; %%
img_name = 'general_img_1024.jpg'
img = imread(img_name);
figure(1)
imshow(img)
title('原图像'); img1 = imresize(img, [256, 256]);
figure(2)
imshow(img1) img2 = Bilinear_Interpolation(img1, 4); figure(3)
imshow(img2)
title('双线性内插法放大') %%
[a, b] = size(img);
n = max(a, b);
c = 1024 / n;
img3 = Bilinear_Interpolation(img1, c);
figure(4)
imshow(img3)
title('双线性内插法缩小')

运行结果:

数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation 标签: 图像处理MATLAB的更多相关文章

  1. 数字图像处理实验(3):PROJECT 02-03, Zooming and Shrinking Images by Pixel Replication 标签: 图像处理matlab 20

    实验要求: Zooming and Shrinking Images by Pixel Replication Objective To manipulate a technique of zoomi ...

  2. 数字图像处理实验(总计23个)汇总 标签: 图像处理MATLAB 2017-05-31 10:30 175人阅读 评论(0)

    以下这些实验中的代码全部是我自己编写调试通过的,到此,最后进行一下汇总. 数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Half ...

  3. 数字图像处理实验(10):PROJECT 05-01 [Multiple Uses],Noise Generators 标签: 图像处理MATLAB 2017-05-26 23:36

    实验要求: Objective: To know how to generate noise images with different probability density functions ( ...

  4. 数字图像处理实验(5):PROJECT 04-01 [Multiple Uses],Two-Dimensional Fast Fourier Transform 标签: 图像处理MATLAB数字图像处理

    实验要求: Objective: To further understand the well-known algorithm Fast Fourier Transform (FFT) and ver ...

  5. 数字图像处理实验(16):PROJECT 06-03,Color Image Enhancement by Histogram Processing 标签: 图像处理MATLAB 2017

    实验要求: Objective: To know how to implement image enhancement for color images by histogram processing ...

  6. 数字图像处理实验(15):PROJECT 06-02,Pseudo-Color Image Processing 标签: 图像处理MATLAB 2017-05-27 20:53

    实验要求: 上面的实验要求中Objective(实验目的)部分是错误的. 然而在我拿到的大纲中就是这么写的,所以请忽视那部分,其余部分是没有问题的. 本实验是使用伪彩色强调突出我们感兴趣的灰度范围,在 ...

  7. 数字图像处理实验(14):PROJECT 06-01,Web-Safe Colors 标签: 图像处理MATLAB 2017-05-27 20:45 116人阅读

    实验要求: Objective: To know what are Web-safe colors, how to generate the RGB components for a given jp ...

  8. 数字图像处理实验(12):PROJECT 05-03,Periodic Noise Reduction Using a Notch Filter 标签: 图像处理MATLAB 2017-0

    实验要求: Objective: To understand the principle of the notch filter and its periodic noise reducing abi ...

  9. 数字图像处理实验(11):PROJECT 05-02,Noise Reduction Using a Median Filter 标签: 图像处理MATLAB 2017-05-26 23:

    实验要求: Objective: To understand the non-linearity of median filtering and its noise suppressing abili ...

随机推荐

  1. Java_脚本引擎_00_资源帖

    一.精选资料 1.w3cschool—Java 脚本引擎 2.Riding the Nashorn 二.参考资料

  2. SQL使用指南(2)—— 约束的使用

    主键约束 (1)创建表时添加主键约束 primary key<column_name> (2) 修改表时添加主键约束 ALTER TABLE table_name ADD CONSTRAI ...

  3. 巧用padding让图片宽高比固定并自适应布局

    1.从上图知道原始图片大小是 800 * 250,即宽高比为 3.2: 2.html 及 css 代码如下, 可以知道就只是在一个div里面放了一张图片,那么如何让这张图片的宽高比固定呢,看了css之 ...

  4. visualvm-profile以及远程访问

    使用visualvm的Profiler功能,可以提供两方面的性能跟踪功能: Profile 一个是CPU,可以跟踪每个方法占用CPU的时长:比如你在发现CPU持续走高的时候可以通过Profile的CP ...

  5. bzoj 2655 calc——拉格朗日插值

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2655 先考虑DP.dp[ i ][ j ]表示值域为 i .选 j 个值的答案,则 dp[ ...

  6. Redis 分布式锁 - 分布式锁的正确实现方式

    前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的分布式锁.本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上已经有各种介 ...

  7. ubuntu lts install licode tag pre-v5.4

    1. Requirements Ubuntu 14.04 LTS 2. Clone Licode codeYou first need to clone our code from github.Yo ...

  8. MYSQLdump参数详解(转)

    mysqldump客户端可用来转储数据库或搜集数据库进行备份或将数据转移到另一个SQL服务器(不一定是一个MySQL服务器).转储包含创建表和/或装载表的SQL语句. 如果你在服务器上进行备份,并且表 ...

  9. 一般处理程序+html 的CRUD

    using Console_Core.BLL; using Console_Core.Common; using Console_Core.Model; using System; using Sys ...

  10. 蓝桥杯 基础练习 BASIC-25 回形取数

    基础练习 回形取数   时间限制:1.0s   内存限制:512.0MB 问题描述 回形取数就是沿矩阵的边取数,若当前方向上无数可取或已经取过,则左转90度.一开始位于矩阵左上角,方向向下. 输入格式 ...