VB image processing, (four) several commonly used filters to achieve 2

Source: Internet
Author: User
Tags exit
Filter last time we talked about the algorithms and implementations of sharpening, softening, diffusing, and carving these filters
Please refer to the VB image Processing, (three) several commonly used filters of the implementation of 1


In this article I will tell you about pencil-drawing algorithms and woodcarving algorithms and their implementation.
Why do I have to put these two algorithms together, because the two algorithms are very similar.
First of all, the eyes of the human eye for the image observation, the human eye for the gray (brightness) of the sensitivity
is far greater than the sensitivity of color, and people's eyes for the warm and cold tones of the sensitivity of more than
Sensitivity to the general color.
After a lot of testing, people get an empirical formula that shows how the eye recognizes brightness:
Gray = Red * 0.3 + Green * 0.6 + Blue * 0.1
And right because the human eye is the most sensitive to green, there is a more approximate formula:
Gray = Green
Would you please recall how you used to see the scenery with your pencil-drawing eyes?
Outline, by the right, what is the outline? In fact, the gray level is a jump.
So we just set a threshold, the computer on the image of the pixel color into grayscale, and then
Next to the two pixels of gray scale to compare, when the gray changes over a certain amount of time, we will judge it is the contour.
Sketch it out with a pencil.
With this idea, it is easy to write this algorithm.
Public Sub Pencil (Optional ByVal sensitivity 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 ' Current point of grayscale oh.
Colnext = colout (0, M, N) * 3 + colout (1, m, N) * 6 + colout (2, M, N)
Colnext =-colnext/10 ' next point of grayscale oh.
If Col + colnext > Sensitivity Then ' to determine if grayscale changes exceed set thresholds
Colout (0, I, L) = 0 ' RGB (0,0,0) represents black
Colout (1, I, L) = 0
Colout (2, I, L) = 0
Else
Colout (0, I, L) = 255 ' RGB (255,255,255) indicates white
Colout (1, I, L) = 255
Colout (2, I, L) = 255
End If
Next
Next
Done = True
Timefilter = Timegettime-timefilter
Exit Sub
Errline:
MsgBox Err.Description
End Sub
All of the global variables used here have been used in the previous chapters and will not be repeated.

Speaking of this, then the principle of wood carving is simpler, nothing more than to judge the point of pixel grayscale, if the grayscale is greater than the given threshold,
Set it to white if the pixel's grayscale is less than the given threshold, set it to black.
So, this algorithm, I will not write out, to the reader before the computer, write a try it, not your.
These two are some very simple image processing, the next one tells you about the concept of "gray histogram", we may have used
Autolevel in Photoshop, it can turn a color very "awkward" image into a very "comfortable" effect,
Then you need to use the "grayscale histogram" this tool, I hope you do not miss.


By the way, the contents of the previous chapters please click on the link:
"VB image processing, (a) pixel acquisition and output"
"VB image processing, (ii) Two linear interpolation application"
VB image processing, (three) several commonly used filters of the implementation of 1


(here just said my own in the process of writing the method used, there are a lot of deficiencies.) And because in the paste up when made some changes, there may be some mistakes, please do not hesitate to enlighten me, will you use a better way to provide, I would appreciate. )




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.