博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数字图像处理--空间变换
阅读量:4201 次
发布时间:2019-05-26

本文共 3271 字,大约阅读时间需要 10 分钟。

上次讲了数字图像处理的一题,今天再贴一题

Geometric transform (test image: fig3.tif)

Develope geometric transform program that will rotate, translate, and scale an imageby specified amounts, using the nearest neighbor and bilinear interpolationmethods, respectively.

 

背景

在对图像进行空间变换的过程中,典型的情况是在对图像进行放大,旋转处理的时候,图像会出现失真的现象。这是由于在变换之后的图像中,存在着一些变换之前的图像中没有的像素位置。处理这一问题的方法被称为图像灰度级插值。常用的插值方式有三种:最近邻域插值、双线性插值、双三次插值。理论上来讲,最近邻域插值的效果最差,双三次插值的效果最好,双线性插值的效果介于两者之间。不过对于要求不是非常严格的图像插值而言,使用双线性插值通常就足够了。

最近领域算法Matlab代码

sourcePic=imread('fig3.tif');%以下为了彩色图像%[m,n,o]=size(sourcePic);%grayPic=rgb2gray(sourcePic);grayPic=sourcePic;[m,n]=size(grayPic);%比例系数为0.2-5.0K = str2double(inputdlg('请输入比例系数(0.2 - 5.0)', '输入比例系数', 1, {'0.5'}));%验证范围if (K < 0.2) && (K > 5.0)    errordlg('比例系数不在0.2 - 5.0范围内', '错误');    error('请输入比例系数(0.2 - 5.0)');endfigure;imshow(grayPic);width = K * m;                     height = K * n;resultPic = uint8(zeros(width,height));widthScale = m/width;heightScale = n/height;for x = 5:width - 5                              for y = 5:height - 5       xx = x * widthScale;                           yy = y * heightScale;       if (xx/double(uint16(xx)) == 1.0) && (yy/double(uint16(yy)) == 1.0)       % if xx and yy is integer,then J(x,y) <- I(x,y)           resultPic(x,y) = grayPic(int16(xx),int16(yy));       else                                     % xx or yy is not integer           a = double(round(xx));               % (a,b) is the base-dot           b = double(round(yy));           resultPic(x,y) = grayPic(a,b);                     % calculate J(x,y)       end    endendfigure;rotate(resultPic,-20);imshow(resultPic);

双线性插值Matlab算法

sourcePic=imread('fig3.tif');%以下为了彩色图像%[m,n,o]=size(sourcePic);%grayPic=rgb2gray(sourcePic);grayPic=sourcePic;[m,n]=size(grayPic);%比例系数为0.2-5.0K = str2double(inputdlg('请输入比例系数(0.2 - 5.0)', '输入比例系数', 1, {'0.5'}));%验证范围if (K < 0.2) or (K > 5.0)    errordlg('比例系数不在0.2 - 5.0范围内', '错误');    error('请输入比例系数(0.2 - 5.0)');endfigure;imshow(grayPic);%输出图片长宽width = K * m;                          height = K * n;resultPic = uint8(zeros(width,height));widthScale = n/width;heightScale = m/height;for x = 5:width-5                                for y = 5:height-5       xx = x * widthScale;                           yy = y * heightScale;       if (xx/double(uint16(xx)) == 1.0) && (yy/double(uint16(yy)) == 1.0)       % if xx and yy is integer,then J(x,y) <- I(x,y)           resultPic(x,y) = grayPic(int16(xx),int16(yy));       else                                           % xx or yy is not integer           a = double(uint16(xx));                    % (a,b) is the base-dot           b = double(uint16(yy));           x11 = double(grayPic(a,b));                % x11 <- I(a,b)           x12 = double(grayPic(a,b+1));              % x12 <- I(a,b+1)           x21 = double(grayPic(a+1,b));              % x21 <- I(a+1,b)           x22 = double(grayPic(a+1,b+1));            % x22 <- I(a+1,b+1)                     resultPic(x,y) = uint8( (b+1-yy) * ((xx-a)*x21 + (a+1-xx)*x11) + (yy-b) * ((xx-a)*x22 +(a+1-xx) * x12) );       end    endendfigure;resultPic = imrotate(resultPic,-20);imshow(resultPic);
效果如下

最近领域算法放大2倍并顺时针旋转20度

双线性插值算法放大2倍并顺时针旋转20度

体会

该实验表明双线性插值得到的图像效果是比较好的。能够避免采用最近领域插值方式时可能存在的图像模糊、块状失真等问题。但双线性插值也存在问题,在放大倍数比较高的时候,图像失真将会比较严重,此时应该考虑使用更高阶的插值算法。

转载地址:http://xxbli.baihongyu.com/

你可能感兴趣的文章
java - mysql连接
查看>>
java - properties read write
查看>>
折腾sparkR
查看>>
Install Python 2/3 on CentOS 6.5 Server
查看>>
PySpark in PyCharm on a remote server
查看>>
virtualbox增强功能-VBoxGuestAdditions安装
查看>>
Linux下安装MySql(版本5.5以上)
查看>>
Virtualbox中Linux添加一个新磁盘
查看>>
胜景之地
查看>>
jar 独立运行文件制作(于windows平台)
查看>>
使用selenium动态爬取
查看>>
在SAS中进行关联规则分析
查看>>
互联网金融产品如何利用大数据做风控
查看>>
数据库基础问答Q&A
查看>>
DeepCopy
查看>>
R语言问题——连接数据库乱码问题解决方案
查看>>
json读取+对象转换+csv读写
查看>>
加密算法比较3DES AES RSA ECC MD5 SHA1等
查看>>
[Python]Anaconda(python数据分析工具箱版)安装
查看>>
CentOS安装glibc-2.14
查看>>