标签:opencv
OpenCV_图像梯度化
#include "stdafx.h" #include "cv.h" #include "cxcore.h" #include "highgui.h" using namespace std; using namespace cv; int main(int argc, char **argv) { CvPoint center;//定义一个二维坐标的点 double scale = -3; int i,j; Mat image = imread("pic.jpg");//打开一张图片 if(!image.data) return -1; center=Point2f(image.cols/2,image.rows/2);//构造这个二维坐标的点 Mat ptr[3]; Mat gradImg; split(image,ptr); for(int i=0;i<image.rows;i++) { for(int j=0;j<image.cols;j++) { double dx=(double)(j-center.x)/center.x; double dy=(double)(i-center.y)/center.y; double weight =exp((dx*dx+dy*dy)*scale); ptr[0].at<uchar>(i,j)=(int)ptr[0].at<uchar>(i,j)*weight;// 将浮点数转化为整数。 ptr[1].at<uchar>(i,j)=(int)ptr[1].at<uchar>(i,j)*weight; ptr[2].at<uchar>(i,j)=(int)ptr[2].at<uchar>(i,j)*weight; } } merge(ptr,3,gradImg); imshow("Window",gradImg); cvWaitKey(-1); return 0; }效果:
标签:opencv
原文地址:http://blog.csdn.net/xiao_lxl/article/details/45369129