The boundary selection or otherwise boundary detection algorithm works after the image quality is improved by the methods listed above. These algorithms can be divided into two classes:
1) emphasizing, reinforcing, highlighting the boundaries;
2) building contours automatically.
Known linear algorithms for the selection of boundaries and nonlinear. As the first, you can bring masks similar to those used in linear filtering. The difference is that weighting factors of different signs, both positive and negative, are used to highlight borders.
For example, using masks for horizontal or vertical processing (selection, amplification) of an image:

and

In monochromatic areas of the image, all points have approximately the same brightness, the gradient of brightness levels is low, and in the resulting image such areas simply darken. Where there are drops (sharp transitions, edges), the steepness of the brightness change is high and bright lines appear in such places in the final image.
Another option is non-linear algorithms. These include the apertures of Roberts and Sobel, Sharr, dipher. algorithm and so on
Sobel operatorThe Sobel operator is well known all over the world and is used for many tasks. The Sobel operator is a more inaccurate approximation of the image gradient, but it is of sufficient quality for practical application in many tasks. More precisely, the operator uses the intensity values only in the vicinity of 3 × 3 of each pixel to get an approximation of the corresponding image gradient, and uses only integer values of the luminance weights to estimate the gradient ...
[Sobel Wiki operator]Formula operator Sobel:
Gx and Gy are two matrices, where each point contains approximate derivatives with respect to x and y. They are calculated as follows by multiplying the matrix Gx and Gy and summing both matrices; as a result, the result is written to the current x and y coordinates in a new image:

')
Gy and Gx Matrices:
Operator prewittThe algorithm of the Prwitt operator is similar to that of the Sobel operator, except for using a different matrix:
[Operator Prewitt Wiki]Operator sharraThe algorithm of the operator Sharr and is similar to the algorithm of the operator Sobel, except for using a different matrix:
[Operator Scharr Wiki]Roberts Cross OperatorThe Roberts Cross Operator is one of the earliest boundary selection algorithms that calculates the sum of squares of differences between diagonally adjacent pixels. This can be accomplished by convolving an image with two cores:

As a result of using the operation of discrete two-dimensional differentiation, a new value is obtained, which is recorded in a new photo.
[Roberts Cross Operator]Differential selection of bordersThe method consists in using a differential approach to the detection of zeros of the second derivative in the direction of different gradient vectors.
It was proposed to increase or decrease the differences by using the coefficient in front of the coefficients in the matrix. The range of coefficients [0.1; 1.5]. The results of the operators were presented below in a number of pictures.
Figures with the names 0.1, 0.4, 0.8, 1.0, 1.2 and 1.5 are the results of the work of the Sobel operator with the coefficient.
When the coefficient is 1.0 - Sobel operator.
Breast shot
Captcha
Shrek
Also, with proper use of the binarization threshold, it is possible to achieve quite good interests; those who have ideas will be glad to listen (read).