重映射 Remap
重映射是指把一个图像指定位置的像素通过映射关系转到另一个图像的指定位置
函数原型
public static void Remap(InputArray src, OutputArray dst, InputArray map1, InputArray map2, InterpolationFlags interpolation = InterpolationFlags.Linear, BorderTypes borderMode = BorderTypes.Constant, Scalar? borderValue = null);
参数 | 说明 |
---|---|
src | 数据源图像 |
dst | 目的地形象。它的大小与map1相同,类型与src相同 |
map1 | The first map of either (x,y) points or just x values having the type CV_16SC2,CV_32FC1, or CV_32FC2. |
map2 | The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map if map1 is (x,y) points), respectively. |
interpolation | Interpolation method. The method INTER_AREA is not supported by this function. |
borderMode | Pixel extrapolation method. When borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that corresponds to the “outliers” in the source image are not modified by the function. |
borderValue | Value used in case of a constant border. By default, it is 0. |
Mat mat = new Mat(@"I:\OpenCvSharp学习\4.jpg", ImreadModes.AnyColor);
Window window = new Window("源图像", WindowMode.Normal, mat);
Mat MapMat1 = new Mat(mat.Size(),MatType.CV_32FC1);
Mat MapMat2 = new Mat(mat.Size(), MatType.CV_32FC1);
for (int j = 0; j < mat.Rows; j++)
{
for (int i = 0; i < mat.Cols; i++)
{
MapMat1.At<float>(j, i) = (float)(i);
MapMat2.At<float>(j, i) = (float)(mat.Rows - j);
}
}
Mat mat2 = new Mat();
Cv2.Remap(mat, mat2,MapMat1,MapMat2);
Window window1 = new Window("源图像1", WindowMode.Normal, mat2);
Cv2.WaitKey(0);