[Opencv learning] gradient an image

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.