Bmp图像处理

Posted

技术标签:

【中文标题】Bmp图像处理【英文标题】:Bmp image manipulation 【发布时间】:2015-07-09 08:34:19 【问题描述】:

为了准备好处理 bmp 图像并能够对其执行算术运算,应遵循什么程序?

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

mean(image1/image2)*image1

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

它会是一个数组吗?还是矩阵?

不胜感激。

【问题讨论】:

【参考方案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 的颜色),我不知道某些操作是否有意义......我知道的还不够关于图像处理来回答这个问题。

【讨论】:

您好 Xavier,感谢您的回答,是的,图像是灰度图像而不是彩色图像 在这种情况下,它应该相对容易,因为您可以选择三个组件(R、G 或 B)中的一个,执行操作,然后再次将其复制为 RGB。希望我的代码有帮助,如果有,请不要忘记将其标记为已回答。如果您有任何问题,请告诉我,我会尽力提供帮助。 您好 Xavier,您的代码有点帮助,但目前尚不清楚如何修改像素并创建新的 bmp 图像。 用您应该使用的确切代码的更接近版本编辑了我的帖子。 谢谢,这可能会有所帮助!

以上是关于Bmp图像处理的主要内容,如果未能解决你的问题,请参考以下文章

BMP字节数组到BMP图像php

如何用MATLAB把bmp格式变成灰度图像

ImageMagick:无法将24位bmp图像转换为8位bmp图像

图像BMP格式介绍

Mat 图像和 BMP格式图像的相互转换

使用 qdbmp 读取.bmp 图像