程序员人生 网站导航

OpenCV_图像梯度化

栏目:php教程时间:2015-08-07 08:10:26

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;//定义1个2维坐标的点 double scale = ⑶; int i,j; Mat image = imread("pic.jpg");//打开1张图片 if(!image.data) return ⑴; center=Point2f(image.cols/2,image.rows/2);//构造这个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(⑴); return 0; }
效果:



------分隔线----------------------------
------分隔线----------------------------

最新技术推荐