加载中
加载中
表情图片
评为精选
鼓励
加载中...
分享
加载中...
文件下载
加载中...
修改排序
加载中...
【.NET 关于图像处理】Threshold.vb (图像二值化)
93°2009/07/27软件综合 IP:广东
效率比较低的方法,如果是验证码识别可以用

有通过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 = bIn.GetPixel(i, j).ToArgb + 16777216
                If RGB2L((color1 Mod ByN), ((color1 Mod ByN2) \ ByN), (color1 \ ByN2)) < value Then
                    If ifbmp Then bIn.SetPixel(i, j, Color.Black)
                    pic(i, j) = 1
                Else
                    If ifbmp Then bIn.SetPixel(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 = bIn.GetPixel(i, j).ToArgb + 16777216
                If RGB2L((color1 Mod ByN), ((color1 Mod ByN2) \ ByN), (color1 \ ByN2)) < value Then
                    If Ifbmp Then bIn.SetPixel(i, j, Color.Black)
                    pic(i, j) = 1
                Else
                    If Ifbmp Then bIn.SetPixel(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




attachment icon Threshold.rar 0.81KB RAR 13次下载
+200  科创币    novakon    2009/07/27 belle
来自:计算机科学 / 软件综合
6
新版本公告
~~空空如也
93° 作者
16年2个月前 IP:未同步
132193
哇靠 。。。你们这群。。。真的无视我啊 = =
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
finalapple
16年2个月前 IP:未同步
132194
额。。。还是支持你一下吧
不过这么长的代码咱消化不了啊。。。= = [s:94]  [s:94]  [s:94]
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
93°作者
16年2个月前 IP:未同步
132196
消化不了……信不信我把BP网络的代码贴上来…… 被pia飞
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
finalapple
16年2个月前 IP:未同步
132199
啊~~~~~~~~不要·····你这不是要我小命吗= = [s:247]  [s:94]
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
acmilan
16年2个月前 IP:未同步
134400
刚看见标题,以为你们在分析Thumbs.db...把我雷进来了...一近来才知道...
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

所属专业
上级专业
同级专业
93°
学者 笔友
文章
651
回复
6032
学术分
30
2007/04/10注册,7年7个月前活动
暂无简介
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:未同步
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的