For the relief effect, stroke (edge detection)CodeIt's not complicated. It's just a little more complicated in theory, and the effect looks more attractive.
If the gray value at the edge of the image passes through a skip, we can calculate the Skip and perform some processing on the value to obtain the stroke effect of the Black edge.
First, consider the difference between the two pixels of this pixel to get a difference. The larger the difference, the more the image is at the edge, and the edge should be in the left and right directions. We can also get the image edges in the upper and lower directions and on two diagonal lines. In this way, we need to construct a filter.
After this filter, the difference value of the image changes in this pixel is obtained, which is converted into a gray value and the absolute value (the difference value may be negative ), then we define that the greater the absolute value of the difference, the blacker the place (the edge is obviously Black). Otherwise, the more white the difference, the following results can be obtained:
The code for this effect is as follows (the Code of the dip_filter function is the same as above ):
The template used in the above demonstration is an edge detector, which is a gradient-based filter in signal processing, also known as edge operators. The gradient is oriented and always orthogonal to the edge (vertical). In the above Code, we use a 45-degree gradient template, it can detect an edge of 135 degrees.
These are simple edge detection operators. More strictly, We can sample the Sobel operator. There are two Sobel operators: one is to detect the horizontal edge, and the other is to detect the same vertical flat edge. The other is the Sobel operator, which also has two, one is to detect the horizontal edge, and the other is to detect the vertical edge. Compared with the common Sobel operator, the location weighting coefficient of the same-sex Sobel operator is more accurate, and the gradient amplitude is consistent when detecting the edge of different directions. You can try the effect of the Sobel operator by yourself. You only need to modify the value of pencil_filter.