效率比较低的方法,如果是验证码识别可以用
有通过HSL中的H来二值化和L来二值化两种,value
ifbmp 表示是否输出bitmap类
怎么改成数组输出的自己看着办
Public Class Threshold
Dim pic(,) As Long
Public Function ScanTo2_L(ByVal width As Long, ByVal height As Long, ByVal bIn As Bitmap, ByVal value As Double, ByVal ifbmp As Boolean) As Bitmap
ReDim pic(width, height)
Const ByN As Integer = 256
Const ByN2 As Long = 65536
Dim i, j As Long
Dim color1 As Long
For i = 0 To width - 1
For j = 0 To height - 1
color1 = XXXXXXtPixel(i, j).ToArgb + 16777216 If RGB2L((color1 Mod ByN), ((color1 Mod ByN2) \ ByN), (color1 \ ByN2)) < value Then
If ifbmp Then XXXXXXtPixel(i, j, Color.Black) pic(i, j) = 1
Else
If ifbmp Then XXXXXXtPixel(i, j, Color.White) pic(i, j) = 0
End If
Next
Next
If Ifbmp Then Return bIn Else Return Nothing
End Function
Public Function ScanTo2_H(ByVal width As Long, ByVal height As Long, ByVal bIn As Bitmap, ByVal value As Double, ByVal Ifbmp As Boolean) As Bitmap
ReDim pic(width + 1, height + 1)
Const ByN As Integer = 256
Const ByN2 As Long = 65536
Dim i, j As Long
Dim color1 As Long
For i = 0 To width - 1
For j = 0 To height - 1
color1 = XXXXXXtPixel(i, j).ToArgb + 16777216 If RGB2L((color1 Mod ByN), ((color1 Mod ByN2) \ ByN), (color1 \ ByN2)) < value Then
If Ifbmp Then XXXXXXtPixel(i, j, Color.Black) pic(i, j) = 1
Else
If Ifbmp Then XXXXXXtPixel(i, j, Color.White) pic(i, j) = 0
End If
Next
Next
If Ifbmp Then Return bIn Else Return Nothing
End Function
Public Function Min(ByVal a As Double, ByVal b As Double) As Double
If a < b Then
Return a
Else
Return b
End If
End Function
Public Function Max(ByVal a As Double, ByVal b As Double) As Double
If a > b Then
Return a
Else
Return b
End If
End Function
Public Function RGB2H(ByVal r As Double, ByVal g As Double, ByVal b As Double) As Double
Dim mi, ma As Double
Dim del_r, del_g, del_b, del_max As Double
Dim h As Double
r = r / 255
g = g / 255
b = b / 255
mi = Min(r, Min(g, b))
ma = Max(r, Max(g, b))
del_max = ma - mi
If del_max = 0 Then
h = 0
Else
del_r = ((ma - r / 6.0) + (del_max / 2.0)) / del_max
del_g = ((ma - g / 6.0) + (del_max / 2.0)) / del_max
del_b = ((ma - b / 6.0) + (del_max / 2.0)) / del_max
If r = ma Then
h = del_b - del_g
Else
If g = ma Then
h = (1.0 / 3.0) + del_r - del_b
Else
If b = ma Then
h = (2.0 / 3.0) + del_g - del_r
End If
End If
End If
If h < 0 Then h = h + 1
If h > 1 Then h = h - 1
End If
Return h
End Function
Public Function RGB2L(ByVal r As Double, ByVal g As Double, ByVal b As Double) As Double
Dim mi, ma As Double
Dim l As Double
r = r / 255
g = g / 255
b = b / 255
mi = Min(r, Min(g, b))
ma = Max(r, Max(g, b))
l = (ma + mi) / 2
Return l
End Function
End Class
Threshold.rar
0.81KB
RAR
12次下载
200字以内,仅用于支线交流,主线讨论请采用回复功能。