摘要:[Visual Basic 6.0] 利用 Picture Point、Pset 模擬 Mask 遮罩影像處理
[Visual Basic 6.0] 利用 Picture Point、Pset 模擬 Mask 遮罩影像處理
Dim PictureXY()
Private Sub Cm_LoadPicture_Click()
InpImage.Picture = LoadPicture(App.Path & "/MaskPicture3.jpg")
End Sub
Private Sub Command1_Click()
MaskPicture.Cls
ReDim PictureXY(500, 500, 2)
'----------Inp
NowX = 0
NowY = 0
For X = 0 To 5000 Step 10
NowY = 0
For Y = 0 To 5000 Step 10
T = InpPicture.Point(X, Y)
R = T Mod 256
T = T \ 256
G = T Mod 256
T = T \ 256
B = T Mod 256
PictureXY(NowX, NowY, 0) = R
PictureXY(NowX, NowY, 1) = G
PictureXY(NowX, NowY, 2) = B
NowY = NowY + 1
Next Y
NowX = NowX + 1
Next X
'----------Mask
For X = 0 To 500
For Y = 0 To 500
For T = 0 To 2
PictureXY(X, Y, T) = MaskChangeNumber(X, Y, T)
Next T
Next Y
Next X
'----------MaskOut
NowX = 0
NowY = 0
For X = 0 To 5000 Step 10
NowY = 0
For Y = 0 To 5000 Step 10
MaskPicture.PSet (X, Y), RGB(Abs(PictureXY(NowX, NowY, 0)), Abs(PictureXY(NowX, NowY, 1)), Abs(PictureXY(NowX, NowY, 2)))
NowY = NowY + 1
Next Y
NowX = NowX + 1
Next X
End Sub
'----------MaskFunction
Function MaskChangeNumber(A, B, C)
If A - 1 >= 0 And B - 1 >= 0 And B + 1 <= 500 And A + 1 <= 500 Then
MaskNumbers = 0
MaskNumbers = MaskNumbers + Val(PictureXY(A - 1, B - 1, C)) * Val(MaskNumber(0))
MaskNumbers = MaskNumbers + Val(PictureXY(A, B - 1, C)) * Val(MaskNumber(1))
MaskNumbers = MaskNumbers + Val(PictureXY(A + 1, B - 1, C)) * Val(MaskNumber(2))
MaskNumbers = MaskNumbers + Val(PictureXY(A - 1, B, C)) * Val(MaskNumber(3))
MaskNumbers = MaskNumbers + Val(PictureXY(A, B, C)) * Val(MaskNumber(4))
MaskNumbers = MaskNumbers + Val(PictureXY(A + 1, B, C)) * Val(MaskNumber(5))
MaskNumbers = MaskNumbers + Val(PictureXY(A - 1, B + 1, C)) * Val(MaskNumber(6))
MaskNumbers = MaskNumbers + Val(PictureXY(A, B + 1, C)) * Val(MaskNumber(7))
MaskNumbers = MaskNumbers + Val(PictureXY(A + 1, B + 1, C)) * Val(MaskNumber(8))
If (MaskNumbers / 9) <= 0 Then
MaskChangeNumber = 0
ElseIf Abs(MaskNumbers / 9) <= 255 Then
MaskChangeNumber = MaskNumbers / 9
Else
MaskChangeNumber = 255
End If
Else
MaskChangeNumber = 0
End If
End Function
Private Sub Command2_Click()
MaskPicture.Cls
NowX = 0
NowY = 0
For X = 0 To 5000 Step 10
NowY = 0
For Y = 0 To 5000 Step 10
MaskPicture.PSet (X, Y), RGB(Abs(PictureXY(NowX, NowY, 0)), Abs(PictureXY(NowX, NowY, 1)), Abs(PictureXY(NowX, NowY, 2)))
NowY = NowY + 1
Next Y
NowX = NowX + 1
Next X
End Sub
#參考資料與圖片來源:影像處理作業七
#0xDe 從分享中學習
#Facebook:ProgrammerDe (https://www.facebook.com/MicrosoftDes) 有問題歡迎提問