Opening (开运算) (VB 6.0)
Opening (开运算) (VB 6.0)
介绍
开运算(Opening)就是先侵蚀N次,而后增长N次,这样就可以消弭较弱的连接。
用法
Option
Explicit
Private Sub
Form_Load()
Picture1.Picture = LoadPicture(App.Path
& "\demo.bmp")
Picture2.Picture = LoadPicture(App.Path
& "\demo.bmp")
Dim lngX As Long
Dim lngY As Long
Dim intS
Dim intA, intB, intC
Dim intD, intE, intF
Dim intG, intH, intI
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
Picture2.ScaleMode = 3
Picture2.AutoRedraw = True
Picture3.ScaleMode = 3
Picture3.AutoRedraw = True
For lngY = 0 To Picture2.ScaleHeight
For lngX = 0 To Picture2.ScaleWidth
DoEvents
intA = (Picture1.Point(lngX - 1,
lngY - 1) And &HFF) - 255
intB = (Picture1.Point(lngX, lngY -
1) And &HFF) - 255
intC = (Picture1.Point(lngX + 1,
lngY - 1) And &HFF) - 255
intD = (Picture1.Point(lngX - 1,
lngY) And &HFF) - 255
intF = (Picture1.Point(lngX + 1,
lngY) And &HFF) - 255
intG = (Picture1.Point(lngX - 1,
lngY + 1) And &HFF) - 255
intH = (Picture1.Point(lngX, lngY +
1) And &HFF) - 255
intI = (Picture1.Point(lngX + 1,
lngY + 1) And &HFF) - 255
intS = intA And intB And intC And
intD And intF And intG And intH And intI
If intS = 0 Then
intS = 255
Else
intS = 0
End If
Picture2.PSet (lngX, lngY),
RGB(intS, intS, intS)
Next lngX
Next lngY
Set Picture3.Picture = Picture2.Image
SavePicture Picture3, App.Path &
"\Temp.bmp"
Picture3.Picture = LoadPicture(App.Path
& "\Temp.bmp")
For lngY = 0 To Picture1.ScaleHeight
For lngX = 0 To Picture1.ScaleWidth
DoEvents
intA = (Picture3.Point(lngX - 1,
lngY - 1) And &HFF) - 255
intB = (Picture3.Point(lngX, lngY -
1) And &HFF) - 255
intC = (Picture3.Point(lngX + 1,
lngY - 1) And &HFF) - 255
intD = (Picture3.Point(lngX - 1,
lngY) And &HFF) - 255
intE = (Picture3.Point(lngX, lngY)
And &HFF) - 255
intF = (Picture3.Point(lngX + 1,
lngY) And &HFF) - 255
intG = (Picture3.Point(lngX - 1,
lngY + 1) And &HFF) - 255
intH = (Picture3.Point(lngX, lngY +
1) And &HFF) - 255
intI = (Picture3.Point(lngX + 1,
lngY + 1) And &HFF) - 255
intS = Abs(intA + intB + intC +
intD + intE + intF + intG + intH + intI)
If intS > 0 Then
intS = 0
Else
intS = 255
End If
Picture2.PSet (lngX, lngY),
RGB(intS, intS, intS)
Next lngX
Next lngY
End Sub
下载原始档及执行档:
例外
1. 如果执行档不能执行,请先安装vbrun60sp6.exe。
参考
[2] Kuo-Jen,
Lien, Digital Image Processing, ISBN: 9789574998333, Scholars Books Co., Ltd.
致谢
感谢 (维基自由百科, Kuo-Jen, Lien)
提供的知识。