bmp 双线性插值_如何用MATLAB编写一个双线性插值的算法,用来放大缩小图象

2005-10-25 回答

由于很多人都在问彩色图像的双线性插值程序,这里就给出一个简陋的示例程序,根据具体需要稍做一些修改应该就可以用于其它情况了。完整源程序以及说明请下载附件bilinear_rgb.rar。 % this programme is written by rockins % the feature is bilinear-interpolate the souce-image to get a destinate-image % the maximum scalor == 9.0, the minimum scalor == 1.0 % copyright 2006-2007,all copyrights(c) reserved by rockins % you can redistibute this programme under the gnu less gpl license % if you have any question about this programme,please contact me via % ybc2084@163 com % read source image into memory,and get the primitive rows and cols rgb = imread('freebsd.jpg'); r = rgb(:,:,1); g = rgb(:,:,2); b = rgb(:,:,3); [nrows,ncols,ncoms]=size(rgb); % next line is the scale-factor,the range is 1.0-9.0 k = str2double(inputdlg('please input scale factor (must between 1.0 - 9.0)', 'input scale factor', 1, {'5.0'})); % validating if (k < 1.0) | (k > 9.0) errordlg('scale factor beyond permitted range(1.0 - 9.0)', 'error'); error('please input scale factor (must between 1.0 - 9.0)'); end % display source image imshow(rgb); % output image width and height are both scaled by factor k width = k * ncols; height = k * nrows; rr = uint8(zeros(height,width)); gg = uint8(zeros(height,width)); bb = uint8(zeros(height,width)); out = uint8(zeros(height,width,ncoms)); % width scalor and height scalor widthscale = 1/k; heightscale = 1/k; % bilinear interpolate for x = k:width-k % this index range is to avoid exceeding the permitted matrix index for y = k:height-k xx = x * widthscale; % xx and yy are the source ordinate,while x and y are the destinate ordinate yy = y * heightscale; if (xx <= 1.0e-8) xx = 1; end if (xx > ncols - 1) xx = ncols - 1; end if (yy <= 1.0e-8) yy = 1; end if (yy > nrows - 1) yy = nrows - 1; end if (xx/double(uint16(xx)) == 1.0) && (yy/double(uint16(yy)) == 1.0) % if a and b is integer,then j(x,y)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值