图像放大并用双线性插值

本文介绍了图像放大的基本原理,并通过线性插值公式展示了如何在x0和x1之间进行插值计算。同时,给出了两种放大图像的方法:一种是对坐标直接取整,另一种则是采用双线性插值技术,对比了两者的差异,结果显示双线性插值能提供更平滑的放大效果。
摘要由CSDN通过智能技术生成

设x0处的函数值为f(x0), x1处的函数值为f(x1),  设x0 < x < x1,对f(x)进行线性插值可得:

f(x) = f(x0)*(x1-x)/(x1-x0) + f(x1)*(x-x0)/(x1-x0)

 

实现代码:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cmath>

using namespace cv;
using namespace std;

#define PI 3.14159265

void MyScale(Mat& src, Mat& dst, float TransMat[3][3]);

/**
 * @function main
 */
int main( int argc, char** argv )
{
  // load image
  char* imageName = "images/Lenna_256.png";

  Mat image;
  image = imread(imageName,1);
  if(!image.data)
  {
	  cout << "No image data" << endl;
	  return -1;
  }

  // show image
  namedWindow("image", CV_WINDOW_AUTOSIZE);
  imshow("image", image);
  
  
  Mat dst;
  float transMat[3][3] = { {2.0, 0, 0}, {0, 2.0, 0}, {0, 0, 1} };
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值