'*************************sobel() subroutine************************* ' ' purpose: take an image and weight the pixels to find the differences ' and then save the differences (edges) only ' ' input: black and white video data in the BWArray array ' xmask and ymask arrays holding the weights to be given to adjacent pixels ' ' output: sobel data that is stored in the SobelData array which is ' then used in the translate subroutine ' '******************************************************************** Sub sobel() Dim x1 As Integer 'row of picture Dim y1 As Integer 'col of picture Dim sumx As Integer 'sum based on xmask weights Dim sumy As Integer 'sum based on ymask weights Dim sum As Integer 'overall absolute value of combined weights-->is the final sobel data Dim i As Integer Dim j As Integer For x1 = 0 To picHEIGHT - 1 'fill in rows 120 to 1 For y1 = 0 To picWIDTH - 1 sumx = 0 'reinitialize these to zero every time through the loop sumy = 0 SobelData(y1, x1) = 255 ' initialize each element of the array (avoids separate initializing loop) 'if not on the border of the image, step into the if statement If Not (y1 = 0) And Not (y1 = picWIDTH - 1) And Not (x1 = 0) And Not (x1 = picHEIGHT - 1) Then For i = -1 To 1 'work through the masks For j = -1 To 1 'move across columns first, then go to next row 'pic is stored (col, row) while the mask is (row,col) 'x and i refer to rows, y and j refer to columns sumx = sumx + BWArray((y1 + j), (x1 + i)) * xmask(i + 2, j + 2) sumy = sumy + BWArray((y1 + j), (x1 + i)) * ymask(i + 2, j + 2) Next j Next i sum = Abs(sumx) + Abs(sumy) 'the larger the overall absolute value, the greater the difference 'between the adjacent pixels 'adjust the meaning of "black" and "white" via the slider control on the form If sum >= (255 - sliderval) Then sum = 255 ElseIf sum <= sliderval Then sum = 0 Else sum = 0 End If SobelData(y1, x1) = 255 - sum 'subtract so edges are outlined in black, everything else is white End If Next y1 Next x1 Call translate End Sub