積分影像計算






'-----------黑白化----------------------------------
Dim pic_BW = jk_binary_FromColor(pic, False)
pic_BW.Save("BW" + ".bmp", Imaging.ImageFormat.Bmp) '轉存bmp格式

'------------/黑白化/-----------------------------------


'------------積分影像-----------------------------------
For j = 0 To y - 1
For i = 0 To x - 1
colorG_int_array(i, j) = pic_BW.GetPixel(i, j).R
Next
Next
' 先抓好像素再給 // 否則 pic_BW.GetPixel(i, j).R是很慢的
Dim pic_ITG = Claculate_IntegralImage_log(colorG_int_array, x, y) '
'Dim pic_ITG = Claculate_IntegralImage_log(pic_BW)' 這樣做 約慢8倍

' pic_ITG.Save("ITG_image" + ".bmp", Imaging.ImageFormat.Bmp) '轉存bmp格式
PictureBox_Integral.Image = pic_ITG
' MsgBox("ITG OK")
'------------/積分影像/-----------------------------------





Public Function Claculate_IntegralImage_log(ByVal pic_BWdata(,) As Int16, ByVal lengthX As Integer, ByVal lengthY As Integer) As Bitmap


Dim x = lengthX
Dim y = lengthY
Dim pic_Integral As Bitmap

Dim section(x - 1, y - 1) As Double
For j = 0 To y - 1
For i = 0 To x - 1




'-----積分影像計算-------------
If i = 0 Or j = 0 Then
If j = 0 And i <> 0 Then
section(i, j) = section(i - 1, j) + pic_BWdata(i, j)
End If
If i = 0 And j <> 0 Then
section(i, j) = section(i, j - 1) + pic_BWdata(i, j)
End If
If i = 0 And j = 0 Then
section(i, j) = pic_BWdata(i, j)
End If

Else
section(i, j) = section(i, j - 1) + section(i - 1, j) - section(i - 1, j - 1) + pic_BWdata(i, j)

End If



'-----/-積分影像計算-/---------------

Next
Next



pic_Integral = jk_FilltoBitmap_log(section, x, y)
Return pic_Integral

End Function
End Class
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 prague12 的頭像
    prague12

    prague12

    prague12 發表在 痞客邦 留言(5) 人氣()