Page 135 -
P. 135

Chapter 3 ■ Digital Morphology   109


                                 Variables may be declared to be of any of these three types by stating the
                               type name followed by a list of variables having that type. STRING constants
                               areallowedin somecases, but there are no string variables.
                                 The executable part of a MAX program is a sequence of statements enclosed
                               by a begin statement at the beginning and an end statement at the end.
                               A semicolon (;) separates each statement from the next in a statement sequence,
                               except before an end statement. The preceding program has only one kind of
                               statement: a DO statement. This is simply the word ‘‘do’’ followed by any legal
                               expression, and permits the expression to be evaluated without assigning the
                               value to anything.
                                 The only operators seen above are << (input) and >> (output), in this case
                               applied to images. The expression a<<“a“ reads an image in PBM file format
                               from the file named “a“ into the image variable a; if the string constant is the
                               empty string ““, then standard input is used as the input file, and if the string is
                               “$1“, then the first command line argument is copied into the string, allowing
                               a program to open dynamically specified file. In the preceding program, two
                               images are read into variables. These are immediately written again under
                               different names: the output operator >> works in the same way as the input
                               operator, creating a PBM image file from the specified image.
                                 MAX has six different types of statements, designed to allow a great
                               deal of flexibility in what kinds of morphological operations can be easily
                               implemented. In summary, the legal statements are as follows:
                                 if ( expression ) then statement

                                 If the expression evaluates to a non-zero integer (TRUE), the statement
                               that follows will be executed. The statement can be a sequence of statements
                               enclosed by begin–end.

                                 if ( expression ) then statement1 else statement2
                                 This is another form of the if statement, but if the expression is 0 (FALSE),
                               statement2 is executed.

                                 loop ... end
                                 Repeat a sequence of code. When the end is reached, execution resumes
                               from the statement following the loop statement. Statements within the loop
                               must be separated by semicolons.

                                 exit N when expression
                                 Exit from a loop if the expression evaluates to a non-zero integer. If N is
                               omitted, the exit branches to the statement following the end of the nearest
                               enclosing loop. If N=2, we escape from the nearest 2 nested loops, and so on.

                                 do expression
   130   131   132   133   134   135   136   137   138   139   140