Last time, we talked about the algorithm and implementation of sharpening, softening, spreading, and engraving filters.
See "VB image processing, (3) Implementation of several common filters 1"
In this article, I will share with you the pencil drawing algorithm and wood carving algorithm and their implementation.
Why should I put these two algorithms together? Because these two algorithms are very similar.
First, let's talk about the human eye's observation of images, and the human eye's sensitivity to gray (brightness ).
Human eyes are much more sensitive to warm and cold colors than to colors.
Sensitivity to General colors.
After a lot of tests, people have obtained an empirical formula to explain how the human eyes recognize brightness:
Gray = Red * 0.3 + Green * 0.6 + Blue * 0.1
The right side has a more similar formula because the human eyes are most sensitive to Green:
Gray = Green
Let's look back at how we did it when we used to see the landscape with pencil drawing eyes?
What is the outline, right? To put it bluntly, it is a gray-scale hop.
Therefore, we only need to set a threshold value to convert the color of the pixels in the images on the computer to the gray level.
When the gray scale of two adjacent pixels exceeds a certain amount, we determine that the gray scale is a contour.
Draw it out with a pencil.
With this idea, we can easily write this algorithm.
Public Sub penpencil (Optional ByVal sensiti.pdf As Long = 25)
Dim I As Long
Dim L As Long
Dim M As Long
Dim N As Long
Dim Col As Long
Dim ColNext As Long
'On Error GoTo ErrLine
If Not CanPut Then Exit Sub
Done = False
TimeFilter = timeGetTime
For I = 0 To OutPutWid-1
M = I + 1
For L = 0 To OutPutHei-1
N = L + 1
Col = ColOut (0, I, L) * 3 + ColOut (1, I, L) * 6 + ColOut (2, I, L)
Col = Col 10' the gray scale of the current vertex.
ColNext = ColOut (0, M, N) * 3 + ColOut (1, M, N) * 6 + ColOut (2, M, N)