OPENCV学习笔记2-7_图像重映射

  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,插值法
}

 

转载于:https://www.cnblogs.com/yunfung/p/7561059.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值