vb.net 教程 5-13 图像处理之像素处理 2

    xiaoxiao2021-03-25  50

    版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。 3、逆反(底片)

    算法:

    原图像:颜色值color=(R,G,B)

    新图像:

    RNew=255-R

    GNew=255-G

    BNew=255-B

    color=(RNew,GNew,BNew)

     

    '逆反 Private Sub btnInversion_Click(sender As Object, e As EventArgs) Handles btnInversion.Click Dim pSourceColor As Color Dim pDestColor As Color Dim destImg As New Bitmap(sourceImg.Width, sourceImg.Height) Dim R, G, B As Integer For i As Integer = 0 To sourceImg.Width - 1 For j As Integer = 0 To sourceImg.Height - 1 pSourceColor = sourceImg.GetPixel(i, j) R = pSourceColor.R G = pSourceColor.G B = pSourceColor.B R = 255 - R G = 255 - G B = 255 - B pDestColor = Color.FromArgb(R, G, B) destImg.SetPixel(i, j, pDestColor) Next Next picDest.Image = destImg End Sub

    处理结果如下:

    4、曝光

    算法:先定义一个阈值,通常取得是128

    原图像:颜色值color=(R,G,B)

    新图像:

    如果R<阈值,那么RNew=255-R

    如果G<阈值,那么GNew=255-G

    如果B<阈值,那么BNew=255-B

    color=(RNew,GNew,BNew)

     

    '曝光 Private Sub btnExposure_Click(sender As Object, e As EventArgs) Handles btnExposure.Click Dim pSourceColor As Color Dim pDestColor As Color Dim destImg As New Bitmap(sourceImg.Width, sourceImg.Height) Dim R, G, B As Integer For i As Integer = 0 To sourceImg.Width - 1 For j As Integer = 0 To sourceImg.Height - 1 pSourceColor = sourceImg.GetPixel(i, j) R = pSourceColor.R G = pSourceColor.G B = pSourceColor.B If R < 128 Then R = 255 - R If G < 128 Then G = 255 - G If B < 128 Then B = 255 - B pDestColor = Color.FromArgb(R, G, B) destImg.SetPixel(i, j, pDestColor) Next Next picDest.Image = destImg End Sub

    处理结果如下:

     

    由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

    学习更多vb.net知识,请参看 vb.net 教程 目录

     

     

    转载请注明原文地址: https://ju.6miu.com/read-32223.html

    最新回复(0)