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:
# 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/>}