OpenCV4.0入门(14)图像插值(Image Interpolation)
知识点:四种最常见的图像插值算法- INTER_NEAREST = 0- INTER_LINEAR = 1- INTER_CUBIC = 2- INTER_LANCZOS4 = 4相关APIvoid resize(InputArray src, OutputArray dst, Size dsize, double fx = 0, double fy = 0, int...
·
知识点:
四种最常见的图像插值算法
- INTER_NEAREST = 0
- INTER_LINEAR = 1
- INTER_CUBIC = 2
- INTER_LANCZOS4 = 4
相关API
void resize(InputArray src, OutputArray dst, Size dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR);
如果 Size 被设置的话,则根据 Size 做缩放插值;否则根据 fx 和 fy 做缩放插值。
应用场景
常被用于图像的几何变换、透视变换及插值计算新像素等。
在计算量方面,临近点插值计算量最小,双立方插值计算量最大;
在精度方面,临近点插值精度最低,具有明显的齿距效果,双立方插值的精度最高;
关于这四种插值算法的详细代码及理论解释可参考这位大神的博客
#ifndef DAY14
#define DAY14
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void day14() {
Mat src = imread("G:\\opencvTest\\small.png");
if (src.empty()) {
cout << "could not load image.." << endl;
return;
}
imshow("src", src);
int h = src.rows;
int w = src.cols;
float fx = 0.0, fy = 0.0;
Mat dst = Mat::zeros(src.size(), src.type());
resize(src, dst, Size(w * 2, h * 2), fx = 0, fy = 0, INTER_NEAREST);
imshow("INTER_NEAREST", dst);
resize(src, dst, Size(w * 2, h * 2), fx = 0, fy = 0, INTER_LINEAR);
imshow("INTER_LINEAR", dst);
resize(src, dst, Size(w * 2, h * 2), fx = 0, fy = 0, INTER_CUBIC);
imshow("INTER_CUBIC", dst);
resize(src, dst, Size(w * 2, h * 2), fx = 0, fy = 0, INTER_LANCZOS4);
imshow("INTER_LANCZOS4", dst);
waitKey();
}
#endif // !DAY14
更多推荐
已为社区贡献3条内容
所有评论(0)