The application of secondary linear interpolation is said earlier. This article came to you about the implementation of sharpening, softening, diffusion, engraving these filters. First, sharpening
The algorithm of sharpening is simple, is a relatively adjacent pixel, and the current pixel is equipped with the difference between the pixels around it. Here I give an example: A B C DE F G Hi J K LM N o P Suppose there is a picture, 4 * 4, a total of 16 pixels, representing A - L from A - L. We will observe this picture first, only the "neighbors" of the four pixels of the middle f, g, j, and k are all.
For the sake of simplicity, we only handle these four pixels, because in the actual picture, due to many pixels in the size of the picture, the surrounding pixels do not process will not affect the final effect. First calculate the difference: delta = f - (A B C E G I J K) / 8 (A B C E G I J K) / 8 is around The average of the pixels, the average is multiplied by a coefficient to f, get a new F value: f = f delta * alpha, this coefficient alpha is sharpening, change this coefficient to get Different sharpening effects. However, it is generally smaller, such as: 0.3, us, we only need to use two loops to traverse the pixel values of the entire picture (removing the boundary) to get a sharpening effect.
However, everyone may find that the value of the previous point is not the original value, such as processing G, which is already changed, and F changes, and f Also is related to the value of g, which will become a cycle reference. In order to avoid the entire problem, here is a modified method: A BC DE F G Hi J K LM NOP we started from the A point, change the difference calculation method to: delta = a - (B E F) / 3f = f delta * alpha scans all pixels from top to right, from top to bottom, at this time, it will not encounter pixels that have been processed in the calculation, and because of the reduction of pixels participating in the operation. The entire processing process is also accelerated.
According to our VB image processing, (1) pixel array has been obtained in the acquisition and output of pixels. We can write: Public Sub Sharp (Optional ByVal SharpDgree As Single = 0.3) Dim X As LongDim Y As LongDim Ix As LongDim Iy As LongDim Diff As LongDim Diff1 As LongDim Div1 As SingleDim Div2 As SingleDim Max As LongOn Error GoTo ErrLineMax = 255Done = FalseTimeFilter = timeGetTimeTemplateSize = 1Sensitivity = Sensitivity * 9Div1 = 1 SharpDgreeDiv2 = -SharpDgree / 3 For X = 0 To OutPutWid - 1 For Y = 0 To OutPutHei -1 RR = ColOut (0, X, Y) * Div1 GG = ColOut (1, x, y) * Div1 bb = colord (2, x, y) * div1 ix = x 1 = y 1 r = colut (0, IX, IY) R = R Colout (0, X , IY) COLOUT (0, IX, Y) G = Colout (1, IX, IY) G = G COLOUT (1, X, IY) COLOUT (1, IX, Y) B = Colout (2, IX , IY) B = B COLOUT (2, X, IY) COLOUT (2, IX, Y) R = R * Div2 g = g * Div2 B = B * DIV2 RR = Rr R GG = GG G BB = BB B IF RR <0 THEN RR = 0 if rr> max THEN RR = Max IF GG <0 THEN GG = 0 if gg> max life gg = max if bb <0 THEN BB = 0 if bb> max life bb = max colut (0, x, y) = rr colut (1, x, y) = GG colut (2, x, y) = bb next nextdone = trueTimefilter = TimegetTime - Timefilterexit SuberRline: DONE = TruemsGBox Err.descriptionnd Sub Because the new value is greater than 255 or less during the calculation of new pixels Therefore, it must be judged after the calculation is completed.
The global variable used: Public Timefilter As long 'is used to record the time DIM RR AS long' spending the filter processing for saving the red component DIM GG AS long 'for saving green components DIM BB AS long' for saving blue Motivation Summary: Sharping Effect:
Second, softening
Soft algorithms are similar to sharpening, but the role is just the opposite, that is, the average value of the current point is replaced by a few points around. A BC DE F g Hi J K LM NOP calculation method: f = (A B C E F G I J K) / 9G = (B C D F G H J K L) / 9 ... The specific procedure, I am not coming here, everyone can change the above procedure small.
Original image: Sofil effect: Third, spread, produce a similar watercolor. The algorithm is very simple, that is, the current point is replaced by the surroundings. A B C DE F G Hi J K LM N o PF point can be replaced by any option from A, B, C, E, G, I, J, and K around it. The G point can be replaced by any options from B, C, D, F, H, J, K, and L around it. The J point can be replaced by any option from E, F, G, I, K, M, N, O around it. K points can be replaced by any options from F, G, H, J, L, N, O, and P around it. As for which point to choose, you can use an updated number. Original image: Diffusion Effect:
Fourth, the engraving will be subtracted adjacent the two pixels, the difference is added to 127 as a new value A bc de f G Hi J K LM NOP If we follow from the left direction to the right direction "engraving" A = B- A 127B = C-B 127C = D-C 127 ... If we follow the direction from top to "engraving" A = E-A 127B = F-B 127C = G-C 127 ... Of course, we can also "engrave" from more directions such as: to the lower left, upper right, top left, right ..., etc., a total of 8 can be selected. In addition, this 127 is the brightness after the "engraving" effect. We can write engraving directions and brightness as parameters in the process of public subboss (Optional Lighness AS Integer ...
Original image: Engraving effect:
The algorithms of these filters are relatively simple, and it is easy to use VB.
In view of the relationship between the space, he said this time, next time and everyone will tell the effect of pencil painting and wood carving. Please continue to pay attention to other content, please refer to: 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, (6) brightness contrast adjustment VB image processing, (7) an algorithm for neighboring a mean filter (dust, decoction)