Reducing the Number of Gray Levels,Zoming and Shrinking Images
2015-05-22 17:55
441 查看
摘 要:本实验主要是对图像进行灰度级数减小的操作以及对图像进行放大和缩小。本实验主要编写了三个程序来对图像进行处理。首先,编写了一个以2的幂次方将给定图像的灰度级数从256减少到2的程序;其次,编写了一个基于像素复制方式进行图像缩放的程序;最后,编写了一个以双线性插值技术进行图像缩放的程序。
(1)实验目的
(1.a) 编写一个以2的幂次方将给定图像的灰度级数从256减少到2的程序。图像的灰度级数以参数变量的形式传递到所编写的程序中。
(1.b) 使用图2.21(a) 以(1.a)中编写的程序生成图2.21所示的各个结果。
(2.a) 编写一个基于像素复制方式进行图像缩放的程序,假设缩放因子为整数。忽略混叠效应。
(2.b) 用编写的程序将图2.19 (a)从1024 x 1024 缩小到256 x 256。
(2.c) 用编写的程序将(2.b)中的结果图像放大到1024 x 1024. 并解释与原图产生差异的原因。
(3.a) 编写一个以双线性插值技术进行图像缩放的程序,程序的输入参数为结果图像的水平和垂直方向的像素数。忽略混叠效应。
(3.b) 用编写的程序将图2.19 (a)从1024 x 1024 缩小到256 x 256。
(3.c) 用编写的程序将(3.b)中的结果图像放大到1024 x 1024. 并解释与原图产生差异的原因。
(2)实验过程与结果
针对题(1.a)和题(1.b)所编写的程序见代码块,其结果如图1-1所示。
图1-1
分析:该程序是基于像素复制方式进行图像缩放,本程序直接采用了imresize函数进行缩放,imresize缩放的默认方式是最邻近插值法,也就是一种像素复制方式的。为了展示图像处理的效果,本文以图像查看器查看的形式来展示图像结果。其中原始图像如图1-2(a)所示,其尺寸为1024*1024。图1-2(b)所示为缩小为256*256大小的图像。图1-2(c)所示为将缩小后的图像再放大到尺寸1024*1024大小的图像。
图1-2(a)
图1-2(b)
图1-2(c)
对比图1-2(a)与图1-2(c),可以看到,虽然尺寸一样,但图1-2(c)的清晰度却远不如原图。这是因为采用最近邻插值在缩小图片时已经丢失了图想的一些信息,所以再放大时就不可能达到原来的清晰度。
针对题(3.a),题(3.b),题(3.c)所编写的程序见代码块。
图1-3(a)所示为采用双线性插值将图像缩小到256*256大小后的图像。图1-2(b)所示为将缩小后的图像再放大到尺寸1024*1024大小的图像。
图1-3(a)
图1-3(b)
同样对比图1-3(b)和原图图1-2(a),缩小后再放大的图像不如原图像清晰,双线性插值法虽然比最近邻插值在灰度估计上精准一些,但在缩小和放大的过程一样会丢失图像的信息,在估计灰度值时也存在误差,所以再放大时就不如原图清晰。
(1)实验目的
(1.a) 编写一个以2的幂次方将给定图像的灰度级数从256减少到2的程序。图像的灰度级数以参数变量的形式传递到所编写的程序中。
(1.b) 使用图2.21(a) 以(1.a)中编写的程序生成图2.21所示的各个结果。
(2.a) 编写一个基于像素复制方式进行图像缩放的程序,假设缩放因子为整数。忽略混叠效应。
(2.b) 用编写的程序将图2.19 (a)从1024 x 1024 缩小到256 x 256。
(2.c) 用编写的程序将(2.b)中的结果图像放大到1024 x 1024. 并解释与原图产生差异的原因。
(3.a) 编写一个以双线性插值技术进行图像缩放的程序,程序的输入参数为结果图像的水平和垂直方向的像素数。忽略混叠效应。
(3.b) 用编写的程序将图2.19 (a)从1024 x 1024 缩小到256 x 256。
(3.c) 用编写的程序将(3.b)中的结果图像放大到1024 x 1024. 并解释与原图产生差异的原因。
(2)实验过程与结果
针对题(1.a)和题(1.b)所编写的程序见代码块,其结果如图1-1所示。
图1-1
分析:该程序是基于像素复制方式进行图像缩放,本程序直接采用了imresize函数进行缩放,imresize缩放的默认方式是最邻近插值法,也就是一种像素复制方式的。为了展示图像处理的效果,本文以图像查看器查看的形式来展示图像结果。其中原始图像如图1-2(a)所示,其尺寸为1024*1024。图1-2(b)所示为缩小为256*256大小的图像。图1-2(c)所示为将缩小后的图像再放大到尺寸1024*1024大小的图像。
图1-2(a)
图1-2(b)
图1-2(c)
对比图1-2(a)与图1-2(c),可以看到,虽然尺寸一样,但图1-2(c)的清晰度却远不如原图。这是因为采用最近邻插值在缩小图片时已经丢失了图想的一些信息,所以再放大时就不可能达到原来的清晰度。
针对题(3.a),题(3.b),题(3.c)所编写的程序见代码块。
图1-3(a)所示为采用双线性插值将图像缩小到256*256大小后的图像。图1-2(b)所示为将缩小后的图像再放大到尺寸1024*1024大小的图像。
图1-3(a)
图1-3(b)
同样对比图1-3(b)和原图图1-2(a),缩小后再放大的图像不如原图像清晰,双线性插值法虽然比最近邻插值在灰度估计上精准一些,但在缩小和放大的过程一样会丢失图像的信息,在估计灰度值时也存在误差,所以再放大时就不如原图清晰。
%---------------------------------------------------------- function regraylevels %功能: 灰度级减少实验 %输入参数:无 %输出参数:无 wH=2; wL=4; ima=imread('fig2.21(a).jpg'); subplot(wH,wL,1) imshow(ima); title('原图像'); for (n=1:7) imt = grayleveldec(ima,n); subplot(wH,wL,n+1) imshow(imt); m=256/(power(2,n)); title([num2str(m),'级灰度图像']); end end %---------------------------------------------------------- function imt = grayleveldec(ima,factor) %功能: 将原图像的灰度级按照2的foctor次幂减少 %输入参数: % ima 输入的 8 bits灰度图像矩阵 % factor 灰度级减小因子 %输出参数: % imt 输出的灰度图像 if factor < 0 factor = 0; end if factor > 8 factor = 8 end dfact = uint8(power(2, factor)); imt =((ima -rem(ima,dfact))/ dfact) * dfact; return; %---------------------------------------------------------- function imt=near(ima,k,s) %ima为原始图像 %k为缩放因子 %s=1时进行缩小,否则进行放大 if (s= =1) imt=imresize(ima,1/k) else imt=imresize(ima,k); end return; %---------------------------------------------------------- function flower1 ima=imread('Fig2.19(a).jpg'); imt=near(ima,4,1); imwrite(imt,'shrinking.jpg'); imtt=near(imt,4,0); imwrite(imtt,'zooming.jpg'); end %---------------------------------------------------------- function imt=bilinearity(ima,width,height) %双线性插值法对图像进行缩放 %ima为原始尺寸图像 %输入参数width,height为结果图像的水平和垂直方向的像素数 %imt为输出图像 [r,c]=size(ima); imt=uint8(zeros(width,height)); widthScale=r/width; heightScale=c/height; for x=6:width-6; for y=6:height-6; oldX=x*widthScale; oldY=y*heightScale; if(oldX/double(uint16(oldX))==1.0)&(oldY/double(uint16(oldY))==1.0) imt(x,y)=ima(int16(oldX),int16(oldY)); else a=double(uint16(oldX)); b=double(uint16(oldY)); x11=double(ima(a,b)); x12=double(ima(a,b+1)); x21=double(ima(a+1,b)); x22=double(ima(a+1,b+1)); imt(x,y)=uint8((b+1-oldY)*((oldX-a)*x21+(a+1-oldX)*x11)+(oldY-b)*((oldX-a)*x22+(a+1-oldX)*x12)); end end end
相关文章推荐
- Reducing the Number of Gray Levels, Zooming and Shrinking Images
- 图像灰度级减少及基本缩放(Reducing the Number of Gray Levels, Zooming and Shrinking Images)
- 数字图像处理实验(2):PROJECT 02-02, Reducing the Number of Gray Levels in an Image 标签: 图像处理MATLAB 2017-
- Reducing the Number of Gray Levels in an Image
- 数字图像处理实验(2):PROJECT 02-02, Reducing the Number of Gray Levels in an Image
- error -27257: Pending web_reg_save_param/reg_find/create_html_param[_ex] request(s) detected and reset at the end of iteration number 1
- A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi
- Kettle解析JSON错误,We MUST have the same number of values for all paths,We can not find and data with path [$.
- Counting positive and negative number and computing the average of numbers
- Count the number of alphabets, spaces, digits and other characters in one line character
- 数据结构与算法分析:第一章:Finding the kth largest number and The four basic rules of recursion
- State of the "Art": A Taxonomy of Artistic Stylization Techniques for Images and Video(二)
- We are already in the process of making 11 connections and the number of simultaneous builds has be
- We are already in the process of making 6 connections and the number of simultan
- Row index must be greater than or equal to zero and less than the number of rows.
- LINUX AND THE MAXIMUM NUMBER OF PROCESSES (THREADS)
- Given constant integers x and t, write a function that takes no argument and returns true if the function has been called x number of times in last t secs.
- Counting the active session number and tune up concurrent performance of MapGuide/AIMS
- ruby merge array of hashes based on the key and order it by number of key/value pair
- The balance between the number of specs and the rate of coverage