VB image processing, (4) implementation of several common filters 2

xiaoxiao2021-03-06  43

Last time, we talked about sharpening, softening, spreading, engraving, algorithm and implementation of these filters, refer to "VB image processing, (3) implementation of several common filters 1"

In this article, I will tell you about the pencil painting algorithm and the wood carving algorithm and their implementation. Why do I have to put these two algorithms together, because these two algorithms are very similar. First of all, it is necessary to say that the human eye is observed by the image. The human eye is much more sensitive to grayscale (brightness), and the human eye is much more sensitive to warm color adjustment and cold tones. Sensitivity. After a lot of test, people got an empirical formula, how to identify brightness: Gray = Red * 0.3 Green * 0.6 blue * 0.1 and the right because of human eyes is the greatest, With a more approximate formula: Gray = Green Please think about how to do it before you see the scenery you see with pencil painting? Contour, right, outline? In fact, it is a hopping of grayscale. Therefore, we only need to set a threshold, convert the color of the pixels in the picture on the computer to grayscale, then compare the grayscale of the adjacent two pixels, when the grayscale changes more than a certain amount, we Judging it is the contour. Use a pencil to draw it. With this idea, we can easily write this algorithm. Public Sub Pencil (Optional ByVal Sensitivity As Long = 25) Dim I As LongDim L As LongDim M As LongDim N As LongDim Col As LongDim ColNext As Long'On Error GoTo ErrLineIf Not CanPut Then Exit SubDone = FalseTimeFilter = 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 current grayscale. Colnext = Colout (0, M, N) * 3 COLOUT (1, M, N) * 6 COLOUT (2, M, N) colnext = -ColNext / 10 'Little grayscale.

If col colnext> Sensitivity Then 'determines whether the gradation change exceeds the set threshold COLOUT (0, I, L) = 0' RGB (0, 0, 0) to indicate black colut (1, i, l) = 0 COLOUT (2, i, l) = 0 else colut (0, i, l) = 255 'RGB (255, 255, 255) means white colut (1, i, l) = 255 colout (2, i, l) = 255 end if Next nextdone = truetimefilter = timegetTime - Timefilterexit Suberrline: MsgBox Err.Descriptionnd Sub This is not used in the first few chapters, no longer repeat. Original: Pencil painting effect:

Speaking here, then the principle of woodcar is simpler, nothing more than the grayscale of the point pixel, if the gradation is greater than a given threshold, set it for white, if the pixel is less than a given The threshold is set to black. So, this algorithm, I will not write it, let readers before the computer, write a try, don't you? Original: Wood carving effect:

These two are some simple image processing. Next, the concept of "grayscale histogram", you may have used the Autolevel function in Photoshop, it can put a color very The image of the unless "is converted to the effect of" comfort ", then it is necessary to use the" grayscale histogram "tool, I hope everyone should not miss.

Yes, please click on the content of another article:

VB image processing, (1) acquisition and output of pixels

(Here, I just said that I used the method of writing the program, there is a lot of shortcomings. Because some modifications are made in the post, there may be some errors, please enlighten you, you will use you. A better way to provide it, I will be grateful.)

VB image processing, (b) Application VB image processing, (3) Several common filter implementation 1VB image processing, (4) implementation 2 VB image processing of several common filters, (5) image Color correction

VB image processing, (six) brightness contrast adjustment

VB image processing, (7) an algorithm for a neighboring mean filter (dust, noise)

转载请注明原文地址:https://www.9cbs.com/read-74202.html

New Post(0)