Bmp图像处理

时间:2015-07-09 08:34:20

标签: arrays vb.net matrix bmp

为了能够操作bmp图像以及能够使用它们执行aritmethic操作,需要遵循的步骤是什么?

例如,如果我有image1.bmpimage2.bmp并且我想获得某种修正系数,那么我需要执行诸如

之类的操作

mean(image1/image2)*image1

我唯一能想到的是将图像以某种方式放在数组中,但我不明白如何加载图像并将其放入数组中。

它会是阵列吗?还是一个矩阵?。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

这是我对它的刺痛。希望它有所帮助。

Sub Main(filePath1 As String, filePath2 As String, filePath3 As String)

    Dim bmpImage1 As New Drawing.Bitmap(filePath1)
    Dim bmpImage2 As New Drawing.Bitmap(filePath2)
    Dim bmpImage3 As New Drawing.Bitmap(filePath3)

    Dim resultBmpImage As New Drawing.Bitmap(bmpImage1.Width, bmpImage1.Height)

    'Iterate through every pixel:
    For x As Integer = 0 To bmpImage1.Width - 1
        For y As Integer = 0 To bmpImage1.Height - 1
            Dim processedColor As System.Drawing.Color =
                ProcessColor(
                    bmpImage1.GetPixel(x, y),
                    bmpImage2.GetPixel(x, y),
                    bmpImage3.GetPixel(x, y))
            resultBmpImage.SetPixel(x, y, processedColor)
        Next
    Next

End Sub

Private Function ProcessColor(
                             color1 As System.Drawing.Color,
                             color2 As System.Drawing.Color,
                             color3 As System.Drawing.Color) As System.Drawing.Color
    Dim resultGrayLevel As Integer = (color1.R / color2.R) + color3.R
    Dim color As System.Drawing.Color = System.Drawing.Color.FromArgb(255, resultGrayLevel, resultGrayLevel, resultGrayLevel)
    Return color
End Function

问题是:如果我们不是在谈论灰度颜色(即:R = G = B的颜色),我不知道某些操作是否有意义...我不知道关于图像处理来回答这个问题。