Paper 82: Comparison of various differential operators for edge detection (Sobel,robert,prewitt,laplacian,canny)

Source: Internet
Author: User

Different image grayscale, the boundary will generally have an obvious edge, using this feature can be segmented image. It is necessary to note that the boundary between the edge and the object is not the same, the edge refers to the image of the value of the pixel has a mutation , and the boundary between objects refers to the real scene in the existence of the boundary between objects . There is a possibility that the edge of the place is not a boundary, there may be no edge of the place, because the real world objects are three-dimensional, and the image only has two-dimensional information, from three-dimensional to two-dimensional projection imaging will inevitably lose a part of the information, in addition, the imaging process of light and noise is an unavoidable important factor. For these reasons, edge-based image segmentation is still a world-class problem in current image research, and researchers are currently trying to add high-level semantic information to edge extraction.

In the actual image segmentation, the first and second derivative is often used only, although, in principle, higher-order derivative can be used, however, because of the effect of noise, in the pure second derivative operation there will be a noise sensitive phenomenon, the third-order derivative information often loses the application value. The second derivative can also describe the type of gray mutation. In some cases, such as gray-scale uniform image, only the first-order derivative may not find the boundary, the second derivative can provide very useful information. Second derivative is more sensitive to noise, and the solution is to filter the image first, eliminate some noise, and then detect the edge. However, the second derivative information algorithm is based on over 0 detection, so the number of edge points is relatively small, conducive to subsequent processing and identification work.

The existence of all kinds of operators is the instantiation calculation of this derivative division principle, which is a kind of calculating unit that is used directly in the calculation process.

Roberts operator : Edge positioning is accurate, but noise sensitive. Suitable for image segmentation with obvious edges and less noise. Roberts Edge detection operator is a kind of operator that uses local difference operator to find edge, and the result edge of Robert operator image processing is not very smooth. It is analyzed that because the Robert operator usually produces a wide response in the area near the edge of the image, the edge image detected by the above operator is often refined and the precision of edge positioning is not very high.

Prewitt operator : The noise is suppressed, the principle of noise suppression is through the average pixel, but the average pixel equivalent to the image of the low-pass filter, so the Prewitt operator to the edge of the positioning is inferior to the Roberts operator.

Sobel operators: Sobel operators and Prewitt operators are weighted averages, but the Sobel operator thinks that the influence of neighboring pixels on the current pixel is not equivalent, so the distance between different pixels has different weights, and the effect on operator results is different. In general, the farther away the distance, the less impact it has.

Isotropic Sobel operator : Weighted average operator, the weights are inversely proportional to the distance between the neighbors and the center point, and when the edges are detected along different directions, the gradient amplitude is the same, which is usually said to be isotropic.

     in Edge detection, a common template is sobel operator . There are two Sobel operators, one is detect horizontal edge ; the other is detection vertical flat edge . Another form of Sobel operator is isotropic Sobel (isotropic Sobel) operator, there are two, one is to detect the horizontal edge, and the other is to detect vertical flat edge. isotropic Sobel operator and the normal Sobel operator, its is more accurate , the amplitude of the gradient is consistent when detecting the edges in different directions. Because of the particularity of the building image, we can find that it is not necessary to calculate the gradient direction when dealing with the contour of this kind of image, so the program does not give the processing method of the isotropic Sobel operator.
     since the Sobel operator is the form of a filter operator for extracting edges, you can use fast convolution function , simple and effective, So it is widely used. In the ointment, the Sobel operator and , in other words, the Sobel operator It is not processed based on the image grayscale , because the Sobel operator does not strictly simulate human visual physiology, the extracted image contour is sometimes not satisfactory. In the observation of an image, we tend to pay attention to the different parts of the image and background, it is this part of the subject highlighting, based on the theory, we can give threshold Contour Extraction algorithm , The algorithm has mathematically proved that the solution is optimal when the pixel points satisfy the normal distribution.

The above operator is the information of the first order derivative, which belongs to the category of the gradient operator .

Laplacian operator: This is a second-order differential operator. It is isotropic, which is independent of the direction of the axis, and the gradient result is unchanged after the axis rotation. However, it is more sensitive to noise, so the image is generally smoothed first, because smoothing is also done with templates, so the usual segmentation algorithm is to combine the Laplacian operator and the smoothing operator to generate a new template.

Laplacian operators are generally not used for edge detection in their original form, because as a second derivative, the Laplacian operator has unacceptable sensitivity to noise, and its amplitude is generated to calculate edges, which is a complex segmentation of unwanted results. The last Laplacian operator cannot detect the direction of the edge, so the role of Laplacian in the segmentation includes: (1) using its 0 cross-properties for edge positioning; (2) Determine whether a pixel is on a dark side or a bright side of an edge , generally using the Gaussian-type Laplace operator (Laplacian of a gaussian,log), because the second derivative is a linear operation, the use of a LoG convolution image with the first Gaussian-type smoothing function convolution to change the image, and then calculate the result of the Laplace is the same. So the purpose of using the Gaussian function in the log formula is to smooth the image, using the Laplacian operator to provide an image with a 0 cross to determine the edge position. Image smoothing reduces the effect of noise and its main function is to counteract the increasing noise effects caused by the second derivative of the Laplacian operator.

The differential operator plays an important role in image processing, its algorithm is simple, and the effect of edge detection is good, so these basic differential operators are the necessary methods in the process of learning image processing, and some common differential operators are emphatically discussed below.

1.Sobel

It is mainly used for edge detection, technically it is a discrete differential operator, used to calculate the approximate value of the gradient of the image luminance function, the disadvantage is that the Sobel operator does not distinguish the subject and background of the image strictly, in other words, Sobel operator is not based on the image grayscale processing, Because the Sobel operator does not strictly simulate human visual physiological characteristics, the extracted image contour is sometimes not satisfactory, the algorithm implementation is very simple, is the 3*3 of the two different directions of the template operation, here no longer write.

2.Robert operator

The difference between each perpendicular direction is used to estimate the gradient, and the Robert operator uses the deviation of the neighboring pixels in the diagonal direction.

3.Prewitt operator

The operator is similar to the Sobel operator, but the weight value has changed, but there is still a gap between the two implementations, it is learned that Sobel is more accurate than Prewitt to detect the edge of the image.

4.Laplacian operator

The Laplace operator is a second-order differential operator that can be detected only if the position of the edge point is taken into account, regardless of the gray difference around it. For a step-like edge, its second derivative appears 0 crosses at the Edge Point, and the second derivative of the pixels along the edge points is different.

5.Canny operator

The operator is better than the previous several, but it is cumbersome to implement, the canny operator is a multi-stage optimization operator with filtering, enhancement, detection, before processing, the canny operator first uses the Gaussian smoothing filter to smooth the image to remove the noise, Canny segmentation algorithm uses the finite difference of the first order bias to calculate the gradient amplitude and direction, in the process of processing, the canny operator will also undergo a non-maximal value suppression process, and finally the canny operator uses two thresholds to connect the edge.

The following algorithm is based on the algorithm is not possible to run directly, just to canny the specific implementation of the steps written out, if required to write their own.

The specific implementation method of the operator:

Anny.cpp:implementation of the Canny class.///////////////////////////////////////////////////////////////////// #include "anny.h" #include "math.h"//#include "algorithms.h"//#include "algorithm.h" #include "stdlib.h"//#include "Maths.h"//using namespace std;//////////////////////////////////////////////////////////////////////// Construction/destruction//////////////////////////////////////////////////////////////////////canny::canny (int Picheight,int picwidth,double * * picdata,double picsigma,double picratiolow,double PicRatioHigh) {iHeight=PicHeight; Iwidth=picwidth; Idata=picdata; Sigma=picsigma; Dratiolow=picratiolow; Dratiohigh=picratiohigh;}                       Canny::~canny () {}void canny::cannyarith (int **iedgepoint) {int i; int **igradx;                         Pointer to X-side wizard number int **igrady;                      Pointer to Y-side wizard int **iextent; The amplitude of the gradient igradx=new int *[iheight]; For (I=0;i igradx[i]=new int[iwidth]; igrady=new int. *[iheight]; for (I=0;i igrady[i]=new iNt[iwidth]; iextent=new int *[iheight];  For (I=0;i iextent[i]=new int[iwidth];    The original image is filtered gaussionsmooth ();//calculates the directional derivative Dirgrad (igradx,igrady) in the x, Y direction;    Calculates the amplitude of the gradient gradextent (igradx,igrady,iextent); Application of Non-maximum inhibition of nonmaxsuppress (iextent,igradx,igrady,iedgepoint); Apply hysteresis to find all the boundary hysteresis (iextent,iedgepoint);     Free memory for (i=0;i delete []* (igradx+i); Delete IGRADX;     for (i=0;i delete []* (igrady+i); Delete Igrady;     for (i=0;i delete []* (iextent+i);  Delete iextent;                             } void Canny::gaussionsmooth () {int i,j,k;                       loop variable int iwindowsize;                          Record template size variable int ihalflen;                         Half of the template size double *pdkernel;                        The weights of each point of the template are double Ddotmul;                     The convolution and double dweightsum of the template with corresponding pixel points;                         The weights of the template are cumulative and double **dtemp;           Intermediate variables for recording image data//opening space dtemp=new double *[iheight]; for (I=0;i dtemp[i]=newDouble[iwidth]; Obtain the template length and the various weights of the template Makegauss (&pdkernel,&iwindowsize); Get half the length of the template ihalflen=iwindowsize/2;   Smooth the direction of the image to the water according to the template smoothing for (I=0;i {j=0;j {ddotmul=0;   dweightsum=0; For (k= (-ihalflen); k<=ihalflen;k++) {if (k+j>=0) && (k+j {ddotmul+=idata[i][j+k]*pdkernel[k+ihalf     Len];    Dweightsum+=pdkernel[k+ihalflen];  }} dtemp[i][j]=ddotmul/dweightsum;   }}//To smooth the image vertically based on the transpose of the template (note that the image data is performed after horizontal smoothing) for (I=0;i {j=0;j {ddotmul=0;   dweightsum=0; For (k= (-ihalflen); k<=ihalflen;k++) {if (k+j>=0) && (k+j {ddotmul+=dtemp[j+k][i]*pdkernel[k+ihalf     Len];        Dweightsum+=pdkernel[k+ihalflen];  }} idata[j][i]=ddotmul/dweightsum; }}//Space release delete []pdkernel; Pdkernel=null;     for (i=0;i delete []* (dtemp+i);   Delete dtemp;                             }void Canny::makegauss (double **pdkernel,int *iwindowsize) {int i;                       loop variable int ncenter;          Determine half the length of the Gaussian template double ddistance;        The distance from the center point of each point of a Gaussian template is double pi=3.1415926;                     Pi double dvalue;                     Intermediate variables, which record the weights of each point of the Gaussian template (without normalization) double dsum=0;    Intermediate variables, which record the sum of the weights of Gaussian template points *iwindowsize=int (1+2*int (3*sigma+0.5)); Determine the length of a Gaussian template, based on the knowledge of probability theory, select the data within [ -3*sigma, 3*sigma].          Ncenter= (*iwindowsize)/2; Get half the length *pdkernel=new double[*iwindowsize];//open up a space for recording the weights of each point//using the Gaussian distribution function (positive distribution) to determine the weights of each point, mainly based on the distance from the center point of the Gaussian distribution, the lower the value, This is somewhat//similar to the image, and the farther away from the center point, the smaller the impact on the center point.  For (i=0;i< (*iwindowsize); i++) {ddistance=double (i-ncenter);  Gaussian distribution Function Evaluation Dvalue=exp (( -1/2) *ddistance*ddistance/(Sigma*sigma))/(sqrt (2*PI) *sigma); (*pdkernel)  [I]=dvalue;  Dsum+=dvalue; }//normalization (since the gray area of the original image is not changed, the sum of the weights must be guaranteed to be 1 for (i=0;i< (*iwindowsize); i++) {(*pdkernel) [i]/= dSum;}}  void Canny::D irgrad (int **igradx,int **igrady) {int i,j,temp1,temp2;/////////////directional derivative of the horizontal direction (below are the corresponding processing of the boundary values with min and Max) for (I=0;i {   For (J=0;j {if (iWidth-1 temp1=iwidth-1;   else temp1=j+1;   if (0 temp2=j-1;     else temp2=0; Igradx[i][j]=int(IDATA[I][TEMP1]-IDATA[I][TEMP2]);   }}//direction derivative for vertical direction for (I=0;i {j=0;j {if (iHeight-1 temp1=iheight-1;   else temp1=j+1;   if (0 temp2=j-1;   else temp2=0;  Igrady[j][i]=int (Idata[temp1][i]-idata[temp2][i]); }}} void Canny::gradextent (int **igradx,int **igrady,int **iextent) {int i,j; double itemp1,itemp2; for (i=0;i   ; j {Itemp1=igradx[i][j]*igradx[i][j];   ITEMP2=IGRADY[I][J]*IGRADY[I][J];  Iextent[i][j]=int (sqrt (ITEMP1+ITEMP2) +0.5);                     }}} void canny::nonmaxsuppress (int **iextent,int **igradx,int **igrady,int **dunchrst) {int i,j; int gx,gy;               Record pixel point x, y direction direction value int g1,g2,g3,g4;                    Gradient value of each field double weight;       Specific Gravity double dtemp1,dtemp2,dtemp;  Intermediate variable//processing edge value (edge Point cannot be a boundary point for (i=0;i {dunchrst[i][0]=0; dunchrst[i][iwidth-1]=0;  } for (J=0;j {dunchrst[0][j]=0; dunchrst[iheight-1][j]=0;   The///tag has the potential to be the boundary point of the pixel for (I=1;i {////gradient value is 0 pixels the point cannot be a boundary point if (iextent[i][j]==0) dunchrst[i][j]=0;  Else {DTEMP=IEXTENT[I][J];    GX=IGRADX[I][J];    GY=IGRADY[I][J]; The following are the gradient values that determine the gradient value of the current pixel point and its field pixels, such as greater than it is possible to be a boundary point, such as less than can not be the boundary point if (ABS (GY) >abs (GX)) {weight=double (ab        S (GX)/abs (GY));        G2=IEXTENT[I-1][J];        G4=IEXTENT[I+1][J];         if (gx*gy>0) {g1=iextent[i-1][j-1];        G3=IEXTENT[I+1][J+1];         } else {g1=iextent[i-1][j+1];        G3=IEXTENT[I+1][J-1];     }} else {weight=double (abs (GY)/abs (GX));     G2=IEXTENT[I][J+1];     G4=IEXTENT[I][J-1];      if (gx*gy>0) {g1=iextent[i+1][j+1];     G3=IEXTENT[I-1][J-1];      } else {g1=iextent[i-1][j+1];     G3=IEXTENT[I+1][J-1];    }} dtemp1=weight*g1+ (1-weight) *g2;    dtemp2=weight*g3+ (1-weight) *g4;    When it is greater then it is possible that the boundary point if (DTEMP&GT;=DTEMP1&AMP;&AMP;DTEMP&GT;=DTEMP2) {dunchrst[i][j] = 128;    } else {dunchrst[i][j]=0; }}}}} void canny::hysteresis (int **iextent,int **IEDGEPoint) {int i,j; int ithrehigh; int ithrelow; Setthreshold (Iextent,&ithrehigh,&ithrelow,iedgepoint); For (I=0;i {j=0;j {if ((iedgepoint[i][j]==128) && (Iextent[i][j]>=ithrehigh)) {iedgepoint[i][j]=255    ;   Traceedge (i,j,ithrelow,iedgepoint,iextent); }}}//Those pixels that have not yet been set to a boundary point are not likely to become boundary points for (I=0;i {j=0;j {if (iedgepoint[i][j]!=255) {//Set to non-boundary points Iedgepoin   T[I][J] = 0; }}}}void canny::setthreshold (int **iextent,int *ithrehigh,int *ithrelow,int **iedgepoint) {int i,j,k; int GradHist[102                     4];                           Statistical gradient histogram data, the maximum value of the gradient can not exceed the iedgenum int;                         The number of boundary points int igradmax=0;                         The gradient maximum value of the boundary point int ihighcount; Based on the number of iratiohigh pixels less than the high threshold value//Initialize for (i=0;i<1024;i++) gradhist[i]=0;   Gradient histogram statistics for (I=0;i {j=0;j {if (iedgepoint[i][j]==128) {gradhist[iextent[i][j]]++; }}} iedgenum=0; Find the maximum gradient and the number of statistical boundary points for (i=0;i<1024;i++) {if (gradhist[i]!=0) igradmax=i; Iedgenum+=gradhist[i]; }//Get the number Ihighcount=int (iedgenum*dratiohigh+0.5) less than the high threshold value; k=1; IEDGENUM=GRADHIST[1];  Find the high threshold while ((k<= (iGradMax-1)) && (Iedgenum {k++; IEDGENUM+=GRADHIST[K]; } *ithrehigh=k; The low Threshold value *ithrelow=int ((*ithrehigh) *dratiolow+0.5) is calculated based on high threshold and proportional relationships;} void Canny::traceedge (int y,int x,int ithrelow,int **iedgepoint,int **iextent) {//query for 8 neighborhood pixels int Xnb[8] = {1, 1, 0,-1,-1, -1, 0, 1}; int ynb[8] = {0, 1, 1, 1,0, -1,-1,-1}; int yy; int xx; int k;  for (k=0;k<8;k++) {yy=y+ynb[k]; XX=X+XNB[K];  If the pixel is a possible boundary point and has not been processed, and the gradient is greater than the threshold if (Iedgepoint[yy][xx]==128&&iextent[yy][xx]>=ithrelow) {//sets the point as a boundary point iedgepoint[yy][xx]=255;   Follow//traceedge (yy,xx,ithrelow,iedgepoint,iextent) with this point as the center; } }}

  

Paper 82: Comparison of various differential operators for edge detection (Sobel,robert,prewitt,laplacian,canny)

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.