【.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 = 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




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

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

所属专业
上级专业
同级专业
93°
学者 笔友
文章
651
回复
6032
学术分
30
2007/04/10注册,6年3个月前活动
暂无简介
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:未同步
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
支持的图片格式:jpg, jpeg, png
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
收藏
取消收藏
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
管理提醒
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}