Edge Detection-Prewitt operator

Source: Internet
Author: User
Edge Detection-Prewitt operator


The Prewitt operator uses the following operators to calculate the image difference between the first-order X direction and the Y direction:


-1 0 1
-1 0 1
-1 0 1
-1 -1 -1
0 0 0
1 1 1

 

# Include <math. h> <br/> // Prewitt operator <br/> // 1. pimagedata image data <br/> // 2. nwidth image width <br/> // 3. nheight image height <br/> // 4. nwidthstep image row size <br/> bool Prewitt (unsigned char * pimagedata, int nwidth, int nheight, int nwidthstep) <br/>{< br/> int I = 0; <br/> Int J = 0; <br/> int dx = 0; <br/> int DY = 0; <br/> int nvalue = 0; <br/> unsigned char * pline [3] = {null, null, null}; <br/> for (j = 1; j <nheight-1; j ++) <br/> {<br/> pline [0] = pimagedata + nwidthstep * (J-1); <br/> pline [1] = pimagedata + nwidthstep * J; <br/> pline [2] = pimagedata + nwidthstep * (J + 1); <br/> for (I = 1; I <nwidth-1; I ++) <br/> {<br/> dx = <br/> pline [0] [I + 1]-pline [0] [I-1] + <br/> pline [1] [I + 1]-pline [1] [I-1] + <br/> pline [2] [I + 1]-pline [2] [I-1]; <br/> DY = <br/> pline [2] [I-1]-pline [0] [I-1] + <br/> pline [2] [I]-pline [0] [I] + <br/> pline [2] [I + 1]-pline [0] [I + 1]; <br/> nvalue = (INT) SQRT (float) (dx * dx + dy * Dy); <br/> If (nvalue> 0xff) <br/>{< br/> nvalue = 0xff; <br/>}< br/> pline [0] [I-1] = (unsigned char) nvalue; <br/>}< br/> return true; <br/>}

 

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.