開運算(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
例外¶
如果執行檔不能執行,請先安裝vbrun60sp6.exe。
參考¶
[1] https://www.wikipedia.org/
[2] Kuo-Jen, Lien, Digital Image Processing, ISBN: 9789574998333, Scholars Books Co., Ltd.
致謝¶
感謝 (維基自由百科, Kuo-Jen, Lien) 提供的知識。