Chinaunix首页 | 论坛 | 博客
  • 博客访问: 364061
  • 博文数量: 19
  • 博客积分: 588
  • 博客等级: 中士
  • 技术积分: 317
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-06 15:35
文章分类
文章存档

2012年(19)

分类: C/C++

2012-04-23 18:00:47

径向梯度,找一个点为中心,其它点到该中心的距离就是变换的比例尺度。
x,y是中心位置,scale是比例尺度。

点击(此处)折叠或打开

  1. #include "stdafx.h"
  2. #include <cv.h>
  3. #include <cxcore.h>
  4. #include <highgui.h>
  5. #include <cmath>
  6. using namespace std;
  7. using namespace cv;

  8. int main(int argc ,char ** argv)
  9. {
  10.     //cvPoint center;
  11.     double scale=-3;
  12.     IplImage * image=cvLoadImage(argv[1]);
  13.     if (!image)
  14.         return -1;

  15.     int x = image->width/4;
  16.     int y =    image->height/4;
  17.     for (int i=0;i<image->height;i++)
  18.     {
  19.         for (int j=0;j<image->width;j++)
  20.         {
  21.             double dx=(double)(j-x)/x;
  22.             double dy=(double)(i-y)/y;
  23.             double weight=exp((dx*dx+dy*dy)*scale);
  24.             uchar* ptr=&CV_IMAGE_ELEM(image,uchar,i,j*3);
  25.             ptr[0]=cvRound(ptr[0]*weight);
  26.             ptr[1]=cvRound(ptr[1]*weight);
  27.             ptr[2]=cvRound(ptr[2]*weight);
  28.         }
  29.     }
  30.     cvNamedWindow("test",1);
  31.     cvShowImage("test",image);
  32.     cvWaitKey(0);
  33.     return 0;
  34. }
改变比例尺度scale=-8,x,y还是原图中心,如图所示:
改变比例尺度scale=-8,x,y还是原图1/4位置,如图所示:
阅读(4295) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~