Page 119 -
P. 119

Chapter 3 ■ Digital Morphology    93


                                    simple.pbm contains the data for the structuring element.
                                    xx.pbm is the name of the file that will be created to hold the resulting
                                    dilated image.
                                 Both the input file and the output file will be in PBM image file format.
                               The structuring element file has its own special format, because the location
                               of the origin is needed. Because dilation is commutative, though, the struc-
                               turing element should also be a PBM image. It was decided to add a small
                               ‘‘feature’’ to the definition of a PBM file — if a comment begins with the string
                               #origin, then the coordinates of the origin of the image will follow, first the
                               column and then the row. Such a file is still a PBM image file, and can still
                               be read in and displayed as such because the new specification occurs in a
                               comment. If no origin is explicitly given, it is assumed to be at (0,0).
                                 Thus, the PBM file for the structuring element B 1 of Figure 3.4 would be:


                                 P1
                                 #origin 1 0
                                 31
                                 10 1
                                 This file will be called B1.pbm. To perform the dilation seen in Figure 3.4, the
                               call to BinDil would be:

                                 BinDil
                                 Enter input image filename:               A1.pbm
                                 Enter structuring element filename:       B1.pbm
                                 Enter output filename:                    A1dil.pbm
                               where the file A1.pbm contains the image A 1 ,and A1dil.pbm will be the file
                               into which the dilated image will be written.
                                 The program BinDil really does not do very much. It merely reads in the
                               images and passes them to the function that does the work: the C function
                               bin_dilate, defined as

                                 int bin_dilate (IMAGE im, SE p);
                                 This function implements a dilation by the structuring element pointed to by
                               p by moving the origin of p to each of the black pixel positions in the image im,
                               and then copying the black pixels from p to the corresponding positions in the
                               output image. Figure 3.5 shows this process, which is basically that specified
                               in Equation 3.9, and which has a strong resemblance to a convolution.
                                 As shown in Figure 3.6, the function bin_dilate looks through the data
                               image for black pixels, calling dil_apply when it finds one; this function
                               performs the actual copy from the current position of the structuring element
                               to the output (dilated) image. A temporary image is used for the result, which
                               is copied over the input image after the dilation is complete.
   114   115   116   117   118   119   120   121   122   123   124