Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
# Include "CV. H "# include" cxcore. H "# include" highgui. H "# include int main (INT argc, char ** argv) {cvpoint center; // defines a two-dimensional coordinate point double scale =-3; int I, J; iplimage * image = argc = 2? Cvloadimage (argv [1], cv_load_image_color): 0; // open an image if (! Image) Return-1; center = cvpoint (image-> width/2, image-> height/2); // construct the point of the Two-dimensional coordinate for (I = 0; iheight; I ++) for (j = 0; jwidth; 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);/* you can use the macro defined by opencv to extract the pixel value. Assume that the grayscale image, you can access the pixels in the J column of the I row as follows: cv_image_elem (image, uchar, I, j) if the color image is cv_image_elem (image, uchar, I, 3 * j) cv_image_elem (image, uchar, I, 3 * j + 1) CV _ Image_elem (image, uchar, I, 3 * j + 2) */uchar * PTR = & cv_image_elem (image, uchar, I, j * 3 ); PTR [0] = cvround (PTR [0] * weight); // converts a floating point number to an integer. PTR [1] = cvround (PTR [1] * weight); PTR [2] = cvround (PTR [2] * weight);} cvsaveimage ("copy.jpg", image ); // Save the image/* Open the image */cvnamedwindow ("window", 1); cvshowimage ("window", image); cvwaitkey (-1); Return 0 ;}