0

私はグレースケール画像を持っています.ROIを抽出し、標準偏差と平均を計算するために画像上に長方形を表示することができました. ただし、長方形を移動していると、特に画像が完全に黒の場合、画像の値が間違っていることに気付きます。この領域では、平均と標準偏差がゼロになるはずです。ただし、標準偏差の平均値と負の値の0を取得し、この黒い領域の他の点を取得すると、平均値は光が支配する領域と同じ平均値に増加します。私は解決策を考え出すのに苦労しています。役立つアイデアはありますか。感謝します。mousemove ボタンと平均および標準偏差の私のコードを以下に掲載します。ありがとう。

Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

    Dim mean As Double = 0
    Dim meancount As Integer = 0
    Dim bmap As New Bitmap(400, 400)
    bmap = PictureBox1.Image
    Dim colorpixel As Color = bmap.GetPixel(e.X, e.Y)
    '   Dim pixels As Double = colorpixel.R + colorpixel.G + colorpixel.B
    If e.Button = Windows.Forms.MouseButtons.Left AndAlso Rect.Contains(e.Location) Then
        If (PictureBox1.Image Is Nothing) Or (PictureBox1.Height - (e.Y + SquareHeight) < 0) Or (PictureBox1.Width - (e.X + SquareWidth) < 0) Then
        Else
            Dim ROI As New Bitmap(400, 400)
            Dim x As Integer = 0
            Dim countx As Integer = 0
            Dim county As Integer = 0

            For i = e.X To (e.X + SquareWidth)
                For j = (e.Y + x) To (e.Y + SquareHeight)
                    Dim pixelcolor As Color = bmap.GetPixel(i, j)
                    ROI.SetPixel(countx, county, pixelcolor)
                    mean = mean + pixelcolor.R + pixelcolor.G + pixelcolor.B
                    county += 1
                    meancount += 1
                Next
                county = 0
                countx += 1
                x = x + 1
            Next

            mean = mean / meancount
            Dim SD = mean - 75
            Dim area As Integer = (SquareHeight * SquareWidth)
            Dim anotherForm As Form2
            anotherForm = New Form2(mean, SD, area, 34)
            anotherForm.Show()
        End If
    End If

    '   Catch ex As Exception
    '   MessageBox.Show(ex.Message())
    '  End Try
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    Rect.X = e.X + x
    Rect.Y = e.Y + y
    Rect.Width = SquareWidth
    Rect.Height = SquareHeight
    ' Label1.Text = "XRect: " + Rect.X.ToString() + " YRect: " + Rect.Y.ToString() + " Xmouse " + e.X.ToString() + " Ymouse " + e.Y.ToString()
    PictureBox1.Refresh()
End Sub

Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    e.Graphics.DrawRectangle(Pens.Red, Rect)
End Sub

Private Function StandardDeviation(ByVal image As Bitmap, ByVal mean As Double, ByVal meancount As Integer) As Double
    Dim SD(SquareHeight * SquareWidth) As Double
    Dim count As Integer = 0
    For i = 0 To SquareWidth
        For j = 0 To SquareHeight
            Dim pixelcolor As Color = image.GetPixel(i, j)

            SD(count) = Double.Parse(pixelcolor.R) + Double.Parse(pixelcolor.G) + Double.Parse(pixelcolor.B) - mean
            count += 1
        Next
    Next

    Dim SDsum As Double = 0
    For i = 0 To count
        SDsum = SDsum + SD(i)
    Next

    SDsum = SDsum / (SquareHeight * SquareWidth)

    SDsum = ((SDsum) ^ (1 / 2))
    Return SDsum

End Function

Private Sub PictureBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
    Dim P As Point = e.Location
    P = New Point
End Sub
4

1 に答える 1

0

平均を計算する必要 mean = mean / (meancount * 3)があります (3 色が追加されています)。すべてを合計して後で割るのではなく、移動平均を計算する方がよいでしょう。数学の間違いが増える可能性があると思います。

于 2013-07-08T17:33:26.013 に答える