Analysis of non-maximal value suppression (Non-maximum suppression) in canny operators

Source: Internet
Author: User
Tags abs


Analysis of non-maximal value suppression (Non-maximum suppression) in canny operators

Kezunhai@gmail.com

Http://blog.csdn.net/kezunhai


In the common edge detection operator or contour detection related algorithms, there is a non-maximal value inhibition, however, the application of non-maximal value suppression in these edge detection operators, in the understanding may be a bit indefinitely. In this paper, the non-maximal value suppression in the canny algorithm is introduced, and the non-maximal value suppression in the canny operator refers to the inhibition of non-maximal values along the gradient direction.

First, let's look at a piece of code (which can be skipped) for the canny operator's non-maxima suppression:

/* fucntion:non-maximum suppression input:pMag:pointer to Magnitude, pgradx:gradient of X-direction pgrady:gradient
of Y-direction Sz:size of pmag (width = size.cx, height = size.cy) Output:pNSRst:result of non-maximum suppression */
	void Nonmaxsuppress (int*pmag,int* pgradx,int*pgrady,size sz,lpbyte pnsrst) {LONG x, y;
	int NPos;
	The component of the gradient int gx,gy;
	The temp varialbe int g1,g2,g3,g4;
	Double weight;
	Double DTEMP,DTEMP1,DTEMP2;
        Set the edge of the image for the Impossible demarcation Point for (x=0;x<sz.cx;x++) {pnsrst[x] = 0;
		
    pnsrst[(sz.cy-1) *sz.cx+x] = 0;
        } for (y=0;y<sz.cy;y++) {pnsrst[y*sz.cx] = 0;
    Pnsrst[y*sz.cx + sz.cx-1] = 0;
			} for (y=1;y<sz.cy-1;y++) {for (x=1;x<sz.cx-1;x++) {npos=y*sz.cx+x;
			If pmag[npos]==0, then NPos isn't the edge point if (pmag[npos]==0) {pnsrst[npos]=0;
				} else {//the gradient of current point dtemp=pmag[npos]; x, Y Party Wizard number gx=pgradx[NPos];
				Gy=pgrady[npos]; If the Y component of the Party wizard is larger than the X component, it indicates that the derivative direction tends to be Y component if (ABS (GY) >abs (GX)) {//Calculate the factor of interplation Weight=f
					ABS (GX)/fabs (GY);  g2 = pmag[npos-sz.cx];  Previous line g4 = pmag[npos+sz.cx];
                    Next Line//if the symbol for x, y two-party wizards is the same//c as the current pixel, the position relationship with G1-G4 is://G1 G2 C//G4 G3 if (gx*gy>0) {G1 = Pmag[npos-s
                        Z.CX-1];
                    G3 = pmag[npos+sz.cx+1];
                    }//If the direction derivative of x, y two direction is opposite//c is the current pixel, the relationship with G1-G4 is://G2 G1
                        C//G3 G4 else {
                        G1 = pmag[npos-sz.cx+1];
                    G3 = Pmag[npos+sz.cx-1]; }} else {//interpolation scale weight = fabs (GY)/fabs (GX); g2 = pmag[npos+1];	The latter column G4 = pmag[npos-1];
                    Previous column//if the direction derivative symbol for x, y two direction is the same//current pixel C is in relation to G1-G4//G3
                        G4 C G2//G1 if (GX * GY > 0) {
                        G1 = pmag[npos+sz.cx+1];
                    G3 = Pmag[npos-sz.cx-1];
                    }//If the X, y two party wizards are in the opposite direction//C has a relationship with G1-G4//G1 G4 C G2//G3 else {G1
                        = Pmag[npos-sz.cx+1];
                    G3 = Pmag[npos+sz.cx-1];
				}} DTEMP1 = Weight*g1 + (1-weight) *g2;				
				DTEMP2 = Weight*g3 + (1-weight) *g4;
				The gradient of the current pixel is the local maximum//The point may be the boundary point if (dtemp>=dtemp1 && dtemp>=dtemp2) {Pnsrst[npos] = 128; } ElSE {//cannot be a boundary point pnsrst[npos] = 0; }			
			}
		}
	}
}
In the above code, there are several if-else to be aware of. In the canny operator's paper proposed by John Canny, the non-maximum suppression is performed in 0, 90, 45, 1354 gradient directions, and each pixel gradient direction is replaced by this four direction in terms of similarity. In this case, the non-maximum suppression compares the adjacent two pixels:

1) 0: Left and right

2) 45: Top Right and bottom left

3) 90: Top and bottom

4) 135: Top left and bottom right

The benefit is simple, but this simplified approach does not work best because the edge gradient direction in natural images is not necessarily along these four directions.          Therefore, there is a great need to interpolate to find the pixel values that best match the direction of the gradient in which they are located.          However, the pixel point in the actual digital image is a discrete two-dimensional matrix, so the point at the gradient direction at the true center position C is not necessarily present, or is a sub-pixel (sub-pixel) point, and the non-existent point, and the gradient value of the point must be interpolated on both sides of the point. For the above code, if |gy|>|gx|, this indicates that the gradient direction of the point is closer to the y-axis direction, so G2 and G4 in C, we can use the following to illustrate the two cases (the direction of the same and different direction):
In the image above, C represents the center point, the oblique line represents the gradient direction (non-maximum suppression is the maximum value in the gradient direction), and the left side represents the same direction as the GX, while the GY on the right indicates that the GY is opposite the GX (note that the origin is in the upper-left corner) and the weight is weight = |gx|/| Gy|, therefore, according to this case, the interpolation representation is:

DTEMP1 = Weight*g1 + (1-weight) *g2;
DTEMP2 = Weight*g3 + (1-weight) *g4;	
In the same way, we can get the situation of |gx|>|gy|, which indicates that the gradient direction of the point is closer to the x-axis direction, G2 and G4 are horizontal, we can use the following figure to illustrate the situation:
In the image above, C represents the center point, the oblique line represents the gradient direction (non-maximum suppression is the maximum value in the gradient direction), and the left side represents the same direction as the GX, while the GY on the right indicates that the GY is opposite the GX (note that the origin is in the upper-left corner) and the weight is weight = |gy|/| Gx|, therefore, according to this case, the interpolation representation is:
DTEMP1 = Weight*g1 + (1-weight) *g2;
DTEMP2 = Weight*g3 + (1-weight) *g4;	
Through the above analysis, we can understand the canny operator in the non-maximal value of the pre-inhibition, that is, the necessary interpolation. The reasons for interpolation are further verbose: Because of the simplification method used in the canny operator to determine the edge direction, the edge gradient direction in the natural image is not necessarily along the four direction, so in order to find the pixel value which can best match its gradient direction at one pixel point, the necessary interpolation must be done; Also, because the pixels in the actual digital image are discrete two-dimensional matrices, the points on either side of the gradient direction at the true center position C are not necessarily present, or a sub-pixel (sub-pixel) point, and the non-existent point, and the gradient value of the point, must be interpolated by the points on either side of it. The next work is relatively simple, that is, the comparison between the gradient amplitude of the dtemp at the center position c and the gradient amplitude at two interpolation points dTemp1 and DTEMP2, to determine whether it is the extremum point, the code is as follows:
if (dtemp>=dtemp1 && dtemp>=dtemp2)
{
	Pnsrst[npos] = n;
}
else
{
	//cannot be a boundary point
	pnsrst[npos] = 0;
}
Here, the canny operator of the non-maximum suppression part of the introduction is done. Finally, one point to note is that the non-maximum suppression in the canny operator is slightly different from the non-maximal value suppression in the scene of the corner detection. The non-maximal value suppression in the canny operator is carried out along the gradient direction, that is, whether it is the extreme point in the gradient direction, and the non-maximal value suppression in the scene of the corner detection, is the value at the center point is the maximum value in a certain neighborhood, is, is retained, otherwise removed, in this case, the non-maximum value , if not clear can be consulted: Alexander Neubeck's paper: efficient non-maximum Suppression

Author: Kezunhai Source: Http://blog.csdn.net/kezunhai Welcome to reprint or share, but be sure to declare the source of the article.

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.