晨风资讯网
新闻资讯网络冲浪网页设计网络编程图形图像数据库网络媒体服务器网络安全网站运营软件教程黑客认证Wap技术
教程搜索
教程搜索:
  首页 > 程序开发 > VB/VB.NET > 正文  

VB.NET2005图像的锐化和钝化的计算
日期:2008-6-27 13:54:02 来源: 作者: 浏览:

VB.NET2005图像的锐化和钝化的计算
Public Function SetImagesharpening(ByVal img As Image) As Image
        '锐化
        Dim DX As Integer = 1, DY As Integer = 1
        Dim red, green, blue As Integer
        Dim bmp As New Bitmap(img)
        With bmp
            For y As Integer = DX To .Height - DX - 1
                For x As Integer = DY To .Width - DY - 1
                    red = Convert.ToInt32(.GetPixel(x, y).R + 0.5 * (Convert.ToInt32(.GetPixel(x, y).R) - Convert.ToInt32(.GetPixel(x - DX, y - DY).R)))
                    green = Convert.ToInt32(.GetPixel(x, y).G + 0.5 * (Convert.ToInt32(.GetPixel(x, y).G) - Convert.ToInt32(.GetPixel(x - DX, y - DY).G)))
                    blue = Convert.ToInt32(.GetPixel(x, y).B + 0.5 * (Convert.ToInt32(.GetPixel(x, y).B) - Convert.ToInt32(.GetPixel(x - DX, y - DY).B)))
                    red = Math.Min(Math.Max(red, 0), 255)
                    green = Math.Min(Math.Max(green, 0), 255)
                    blue = Math.Min(Math.Max(blue, 0), 255)
                    bmp.SetPixel(x, y, Color.FromArgb(red, green, blue))
                Next
            Next
        End With
        Return bmp
    End Function

    Public Function SetImageDeactivation(ByVal img As Image) As Image
        '钝化
        Dim bmp As New Bitmap(img)
        Dim dx As Integer = 1
        Dim dy As Integer = 1
        Dim red, green, blue As Integer
        For y As Integer = dy To img.Height - dy - 1
            For x As Integer = dx To img.Width - dx - 1
                red = CInt((CInt(bmp.GetPixel(x - 1, y - 1).R) + CInt(bmp.GetPixel(x - 1, y).R) + CInt(bmp.GetPixel(x - 1, y + 1).R) + CInt(bmp.GetPixel(x, y - 1).R) + CInt(bmp.GetPixel(x, y).R) + CInt(bmp.GetPixel(x, y + 1).R) + CInt(bmp.GetPixel(x + 1, y - 1).R) + CInt(bmp.GetPixel(x + 1, y).R) + CInt(bmp.GetPixel(x + 1, y + 1).R)) / 9)
                green = CInt((CInt(bmp.GetPixel(x - 1, y - 1).G) + CInt(bmp.GetPixel(x - 1, y).G) + CInt(bmp.GetPixel(x - 1, y + 1).G) + CInt(bmp.GetPixel(x, y - 1).G) + CInt(bmp.GetPixel(x, y).G) + CInt(bmp.GetPixel(x, y + 1).G) + CInt(bmp.GetPixel(x + 1, y - 1).G) + CInt(bmp.GetPixel(x + 1, y).G) + CInt(bmp.GetPixel(x + 1, y + 1).G)) / 9)
                blue = CInt((CInt(bmp.GetPixel(x - 1, y - 1).B) + CInt(bmp.GetPixel(x - 1, y).B) + CInt(bmp.GetPixel(x - 1, y + 1).B) + CInt(bmp.GetPixel(x, y - 1).B) + CInt(bmp.GetPixel(x, y).B) + CInt(bmp.GetPixel(x, y + 1).B) + CInt(bmp.GetPixel(x + 1, y - 1).B) + CInt(bmp.GetPixel(x + 1, y).B) + CInt(bmp.GetPixel(x + 1, y + 1).B)) / 9)
                red = Math.Min(Math.Max(red, 0), 255)
                green = Math.Min(Math.Max(green, 0), 255)
                blue = Math.Min(Math.Max(blue, 0), 255)
                bmp.SetPixel(x, y, Color.FromArgb(red, green, blue))
            Next
        Next
        Return bmp
    End Function


上一篇: VB.NET2005计算图片某一区域的面积 下一篇:

VB.NET2005计算图像的颜色变化(浮雕)

返回列表 打印此页 加入收藏 资讯论坛 关闭窗口 点击复制本页地址,发送给QQ/MSN好友
关于我们 - 联系我们 - 版权声明 - 帮助(?) - 广告服务 - 友情链接 - 服务项目 - 人才招聘
2003-2008 版权所有 © 晨风资讯网 未经授权禁止复制或建立镜像
CopyRight 2003-2008 www.Net118.com,All Rights Reserved.Design By ChenFeng Network Studio