C++ 双线性插值缩放图像
2017-07-26 21:31
155 查看
缩放灰度图
cv::Mat bilinear(cv::Mat src, int row, int col){ int rows = src.rows, cols = src.cols; cv::Mat dst(row, col, src.type()); for(int i = 0; i < row; ++i) { //以ptr的方式访问dst的数据 uchar *p = dst.ptr<uchar>(i); //使两个图像的几何中心重合,采样更合理 float x = (i+0.5)*rows/row-0.5; int fx = (int)x; //x为坐标的小数部分 x -= fx; //以整数计算速度更快 short x1 = (1.f-x)*2048; short x2 = 2048 - x1; for(int j = 0; j < col; ++j) { //trick float y = (j+0.5)*cols/col-0.5; int fy = (int)y; y -= fy; //trick short y1 = (1.f-y)*2048; short y2 = 2048 - y1; //结果右移22位抵消2048的平方 p[j] = (src.at<uchar>(fx,fy)*x1*y1 + src.at<uchar>(fx+1,fy)*x2*y1 +src.at<uchar>(fx,fy+1)*x1*y2 + src.at<uchar>(fx+1,fy+1)*x2*y2) >> 22; } } return dst; }
相关文章推荐
- opencl:C++实现双线性插值图像缩放
- 双线性插值(Bilinear interpolation)的图像旋转在mobile上面的C++实现
- C/C++ BMP(24位真彩色)图像处理(3)------图像の放大缩小(双线性插值)
- C++ 双线性插值缩放图像
- C++ 双线性插值缩放图像
- 双线性插值(Bilinear interpolation)的图像旋转在mobile上面的C++实现
- C/C++ BMP(24位真彩色)图像处理(3)------图像の放大缩小(双线性插值)
- C++类型转换
- 状态模式 C++实现
- c++书籍推荐
- C/C++字符串转换到数字的函数
- C和C++中的void*
- c/c++基础记录
- C++ STL Algorithm
- 学习C++的经验:如何成为一名C++程序员
- c++学习
- 【面向对象语言系列】关于C++数据结构,你需要知道的事
- c++与oc混编
- C++判断pe文件实例
- 数据结构学习(C++)续——查找(搜索)【1】