PV-WAVE Foundation > Tutorial > Creating PV-WAVE Applications > Lesson 1: Writing a Simple Function
Lesson 1: Writing a Simple Function
In this lesson, you will write a function to compute the digital gradient of an image. The digital gradient approximates the two-dimensional gradient of an image and emphasizes the edges. This simple function consists of three lines, corresponding to the three required components of procedures and functions: 1) the procedure or function declaration, 2) the body of the procedure or function, and 3) the terminating END statement.
To write the function, do the following:
1. Define a function called GRAD.
FUNCTION GRAD, IMAGE
; Write the following code, which evaluates and returns the
; result. Result = abs (dz/dx) + abs (dz/dy), which is the sum
; of the absolute values of the derivative in the x and y
; directions.
RETURN, ABS(IMAGE - SHIFT(IMAGE, 1, 0))+ $ 
ABS(IMAGE - SHIFT(IMAGE, 0, 1))
; Use END to end of function.
END
The function has one parameter called IMAGE. There are no local variables. (Local variables are variables within a module that are not parameters and are not contained in Common Blocks.)