Remapping an image: Modify the appearance(外观) of an image by moving its pixels. The pixel values are not changed by this process; it is rather the position of each pixel that is remapped to a new location.
可以用来创建图像特效,或者修正因镜片等原因导致的图像扭曲。
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <math.h> using namespace cv; void wave(const Mat &image, Mat &result) ; int main() { Mat image = imread("test.jpg", 0); //Grayscale image namedWindow("YunFung Image"); imshow("YunFung Image", image); Mat result; wave(image, result); namedWindow("Remapped image"); imshow("Remapped image", result); waitKey(); return 0; } // remapping an image by creating wave effects void wave(const Mat &image, Mat &result) { // the map functions 映射参数 Mat srcX(image.rows, image.cols, CV_32F); // x-map Mat srcY(image.rows, image.cols, CV_32F); // y-map // creating the mapping for (int i = 0; i < image.rows; i++) { for (int j = 0; j < image.cols; j++) { // new location of pixel at (i,j),horizontal flipping srcX.at<float>(i,j)= image.cols-j-1; srcY.at<float>(i,j)= i; //row,not change } } // applying the mapping remap(image, // source image result, // destination image srcX, // x map srcY, // y map INTER_LINEAR); // interpolation method,插值法 }