### VB图像处理，（三）几个常用滤镜的实现1

A  B C D
E  F  G H
I   J   K L
M N O P

(A+B+C+E+G+I+J+K) / 8就是F周围的像素的平均值，

F=F +  Delta * Alpha

A  B C D
E  F  G H
I   J   K L
M N O P

Delta= A - (B+E+F) / 3
F=F +  Delta * Alpha

Public Sub Sharp(Optional ByVal SharpDgree As Single = 0.3)
Dim X As Long
Dim Y As Long
Dim Ix As Long
Dim Iy As Long
Dim Diff As Long
Dim Diff1 As Long
Dim Div1 As Single
Dim Div2 As Single
Dim Max As Long
On Error GoTo ErrLine

Max = 255
Done = False
TimeFilter = timeGetTime
TemplateSize = 1
Sensitivity = Sensitivity * 9
Div1 = 1 + SharpDgree
Div2 = -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 = ColOut(2, X, Y) * Div1
Ix = X + 1
Iy = Y + 1
R = ColOut(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 Then GG = Max
If BB < 0 Then BB = 0
If BB > Max Then BB = Max
ColOut(0, X, Y) = RR
ColOut(1, X, Y) = GG
ColOut(2, X, Y) = BB
Next
Next

Done = True
TimeFilter = timeGetTime - TimeFilter
Exit Sub
ErrLine:
Done = True
MsgBox Err.Description
End Sub

Public TimeFilter As Long      '用于记录滤镜处理所花费的时间
Dim RR As Long                 '用于保存红色分量
Dim GG As Long                '用于保存绿色分量
Dim BB As Long                 '用于保存蓝色分量

A  B C D
E  F  G H
I   J   K L
M N O P

F=(A+B+C+E+F+G+I+J+K) / 9
G=(B+C+D+F+G+H+J+K+L) / 9
...
...

A  B C D
E  F  G H
I   J   K L
M N O P
F点可以从它周围的A,B,C,E,G,I,J,K中任意选一点代替。
G点可以从它周围的B,C,D,F,H,J,K,L中任意选一点代替。
J点可以从它周围的E,F,G,I,K,M,N,O中任意选一点代替。
K点可以从它周围的F,G,H,J,L,N,O,P中任意选一点代替。

A  B C D
E  F  G H
I   J   K L
M N O P

A=B-A+127
B=C-B+127
C=D-C+127
...

A=E-A+127
B=F-B+127
C=G-C+127
...

Public Sub Emboss(Optional EmbossDirection As Integer , Optional Lighteness As Integer)
...

（这里只是说了我自己在写程序的时候用到的方法，存在很多的不足。并且因为在贴上来的时候作了部分修改，可能会存在部分错误，请各位高手不吝赐教，将您用到的更好的方法提供一下，我将不胜感激。）

VB图像处理，（七）一种邻近均值滤波器的算法介绍（去尘，去噪音）

0 0