Skip to main content

開運算(Opening)(VB 6.0)

開運算(Opening)(VB 6.0)

開運算(Opening)(VB 6.0)

介紹

開運算(Opening)就是先侵蝕N次,而後增長N次,這樣就可以消弭較弱的連接。

用法

image.png

程式碼


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) 提供的知識。

Popular posts from this blog

Python 日期與時間的處理

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Python 日期與時間的處理

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

Image

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Image

數位影像處理:最佳化處理策略之快速消除扭曲演算法

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (04. 人事考勤管理系統)

Image

用10種程式語言做影像二值化(Image binarization)

Visual Basic 6.0 (VB6) 程式語言案例學習 (07. 收據列印程式)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (03. 場地預約系統)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (11. 生產線拍照程式)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (06. 題庫測驗系統)

Image