Matlab - encontrar pixel image processing

   
Vista:

encontrar pixel image processing

Publicado por Marco (1 intervención) el 05/05/2009 22:58:53
Buen dia:
El reto es el siguiente; en una imagen en escala de grises, se requiere ubicar el pixel con mayor luminosidad y calcular a que distancia del centro de la imagen se encuentra.

el codigo en Basic es el siguiente: pero tiene una deficiencia por que encuentra el pixel max red (maximo punto en rojo)


Private Sub exit_Click()
' only if running...
If (Timer1.Enabled) Then

Timer1.Enabled = False 'Stop Timer
VideoOCX.Stop
VideoOCX.Close

End If

End
End Sub

Private Sub Start_Click() 'Init VideoOCX Control, allocate memory and start grabbing

If (Not Timer1.Enabled) Then
Start.Caption = "Stop"

' Disable internal error messages in VideoOCX
VideoOCX.SetErrorMessages False

' Init control
If (Not VideoOCX.Init) Then
' Init failed. Display error message and end sub
MsgBox VideoOCX.GetLastErrorString, vbOKOnly, "VideoOCX Error"
End
Else
' Allocate memory for global image handle
capture_image = VideoOCX.GetColorImageHandle
' result_image = VideoOCX_Processed.GetColorImageHandle

Timer1.Enabled = True 'Start capture timer

' Start Capture mode
If (Not VideoOCX.Start) Then
' Start failed. Display error message and end sub
MsgBox VideoOCX.GetLastErrorString, vbOKOnly, "VideoOCX Error"
End
End If
End If
Else
Start.Caption = "Start"
Timer1.Enabled = False 'Stop Timer
VideoOCX.Stop
VideoOCX.Close
End If

End Sub

Private Sub Timer1_Timer()
' Timer for capturing - handles videoOCXTools
Dim matrix As Variant
Dim height, width As Integer
Dim r, c As Integer
Dim max_r, max_c As Integer
Dim max_red As Integer
Dim gain, offset As Variant
Dim h_cm As Variant
Dim range As Integer
Dim pixels_from_center As Integer

' Calibrated parameter for pixel to distance conversion
gain = 0.0024259348
offset = -0.056514344
h_cm = 5.842

max_red = 0

' Capture an image
If (VideoOCX.Capture(capture_image)) Then

' VideoOCX.Show capture_image

' Matrix transformation initialization
matrix = VideoOCX.GetMatrix(capture_image)

height = VideoOCX.GetHeight
width = VideoOCX.GetWidth

' Image processing code

' The laser dot should not be seen above the middle row (with a little pad)
For r = height / 2 - 20 To height - 1

' Our physical setup is roughly calibrated to make the laser
' dot in the middle columns...dont bother lookng too far away
For c = width / 2 - 25 To width / 2 + 24

' Look for the largest red pixel value in the scene (red laser)
If (matrix(c, r, 2) > max_red) Then
max_red = matrix(c, r, 2)
max_r = r
max_c = c
End If
Next c
Next r

' Calculate the distance for the laser dot from middle of frame
pixels_from_center = max_r - 120

' Calculate range in cm based on calibrated parameters
range = h_cm / Tan(pixels_from_center * gain + offset)

' Print laser dot position row and column to screen
row_val.Caption = max_r
col_val.Caption = max_c

' Print range to laser illuminated object to screen
range_val.Caption = range

' Draw a red vertical line to intersect target
For r = 0 To height - 1
matrix(max_c, r, 2) = 255
Next r

' Draw a red horizontal line to intersect target
For c = 0 To width - 1
matrix(c, max_r, 2) = 255
Next c

VideoOCX.ReleaseMatrixToImageHandle (capture_image)

End If

VideoOCX.Show capture_image

End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder