数字图像处理实验(4):PROJECT 02-04 [Multiple Uses],Zooming and Shrinking Images by Bilinear Interpolation 标签: 图像处理MATLAB
实验要求:
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.
这次实验通过自己编写双线性内插法的程序来对图像进行缩放。
简要介绍一下双线性内插法的原理:
第一种情况:
- 点(i-b, j-a)与点(i-b, j+rate-a)插值得到点(1-b, j)处的灰度值;
- 点(i+rate-b, j-a)与点(i+rate-b, j+rate-a)插值得到点(i+rate-b, j)处的灰度值;
- 使用前面得到的结果,即点(i-b, j)与点(i+rate-b, j)进行插值得到点(i,j)处的灰度值。
第二种情况:
- 点(i-b, j-a)与点(i+rate-b, j-a)插值得到点(i, j-a)处的灰度值;
- 点(i-b, j+rate-a)与点(i+rate-b, j+rate-a)插值得到点(i, j+rate-a)处的灰度值;
- 使用前面得到的结果,即点(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的更多相关文章
- 数字图像处理实验(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 ...
- 数字图像处理实验(总计23个)汇总 标签: 图像处理MATLAB 2017-05-31 10:30 175人阅读 评论(0)
以下这些实验中的代码全部是我自己编写调试通过的,到此,最后进行一下汇总. 数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Half ...
- 数字图像处理实验(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 ( ...
- 数字图像处理实验(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 ...
- 数字图像处理实验(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 ...
- 数字图像处理实验(15):PROJECT 06-02,Pseudo-Color Image Processing 标签: 图像处理MATLAB 2017-05-27 20:53
实验要求: 上面的实验要求中Objective(实验目的)部分是错误的. 然而在我拿到的大纲中就是这么写的,所以请忽视那部分,其余部分是没有问题的. 本实验是使用伪彩色强调突出我们感兴趣的灰度范围,在 ...
- 数字图像处理实验(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 ...
- 数字图像处理实验(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 ...
- 数字图像处理实验(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 ...
随机推荐
- mysql 完整约束
一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...
- git教程3-添加远程库与从远程库拷贝
一.添加到github 1.github上创建新的库learngit.git 2.git remote add origin git@github.com:moisiet/learngit.git ...
- C++中声明和定义的区别
声明 这有一个与这个名字相关的东西,并且它是这个类型的,告诉编译器我要使用它,并期待它定义在某一个地方. 定义 定义是指提供所有必要的信息(占用内存大小),使其能够创建整个实体. 我们必须明白的: 一 ...
- HDU - 2294: Pendant(矩阵优化DP&前缀和)
On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend made by K ki ...
- 【LeetCode】029. Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, retu ...
- windbg调试实例(4)--句柄泄露
同事介绍了一篇调试句柄泄露的blog文章,今天有空看了一下,这家伙用视频的方式录下整个调试的过程,学习一目了然,真是有心.鉴于学习的过程总结一下能加深记忆,所以我这里做个记录,感兴趣的朋友可以看这里: ...
- YARN的ACL
修改完了资源池的权限之后,发现无法查看日志了.报错: User [dr.who] is not authorized to view the logs for... 即使把资源池的权限设置为了*(所有 ...
- 洛谷【P1616】疯狂的采药
浅谈\(DP\):https://www.cnblogs.com/AKMer/p/10437525.html 题目传送门:https://www.luogu.org/problemnew/show/P ...
- Python 函数之迭代器和生成器
1.迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,迭代器仅仅在迭代到某个元素时才计算该元素,而在这之前或之后,元素可 ...
- liferay-ui:search-container reset cur page 当点列排序时,把当前页号重置为1.
问题描述: liferay里面要用liferay-ui:search-container 来展示结果集.并要求点列时,可以排序.然后,如果当前页数不为1时,点列排序,自动设置为1. 解决: // 列排 ...