CSE/EE 486:  Fundamentals of Computer Vision


      Computer Project Report #2:

      Mathematical Morphology and Gray-scale Image Filtering

      Group #11: Howard Elikan, Jim Geis and Anirudh Modi

      March 19, 1999


      1. Objectives:
        1. To implement code for mathematical morphology operations and mean filters
        2. To observe the effects of a skeletonization operation
        3. To apply aforementioned operations to binary and gray scale images to achieve desired processing

      2. Methods:
        For part 1, several morphological operators are applied to Figure 1, a picture with clover, club, bull, and airplane images. The first two tasks of removing the stem from the clover and the horns from the bull require a closing operator. Since we use gray-scale morphological operators, we must apply a closing operator to remove the bright stem from the dark background. The operator we programmed is a general one, allowing us to specify what size of closing operation to perform. The algorithm simply goes through the image, determining each pixel's value one at a time. For the clover, a 3 x 3 closing is required to remove the stem, as shown in Figure 3. We kept increasing the mask until a 7 x 7 closing completely removed the horns. The resulting image for this is shown in Figure 4.

        The third task of part 1 involves skeletonization of the image in Figure 1. For this we decided to write our own skeletonization function, based on the medial axis algorithm in K&J 2.5.10. The algorithm we used produces slightly different results than Cantata, probably because Cantata uses a different algorithm than the one we implemented. Our results for skeletonization appear in Figure 2.

        For part 2, we chose to work with cupnoise.gif shown in Figure 5. We used the segmentation program from Project 1 to separate the object from its background at a threshold value of 90, as shown in Figure 6.

        The next task requires the implementation of a 5 x 5 mean filter. We again made a general mean filter function which takes as input the size of the filter to perform. The function finds the mean value among all the pixels in the specified neighborhood. Then we supplied to the function the image and an input of 5, to create the 5 x 5 mean filtered image in Figure 7. Segmenting the filtered image yields a much cleaner thresholded image as shown in Figure 8.

        The last operations are dilation and erosion operators. The functions for these operations are very similar to the mean filter implemented above. Instead of taking the average value of the pixels in consideration, the maximum and minimum pixels are used for dilating and eroding, respectively. We created opening and closing functions from these dilation and erosion operators. Applying the 7 x 7 closing operator to the original image, we get the resulting image of Figure 9. Finally, thresholding the result yields the image in Figure 10.

        To run the program, we made a script that compiles the code (if necessary) and executes the filtering program on a specified image file. During execution, the program creates several temporary image files. When execution is complete, the script loads xv to view the output image files created by the program. When the user closes xv, the script deletes the temporary files and terminates. For example, to run the program on the image with four objects in it, the user would type: run match.pgm

        The program code and script code can be found in the Appendix below.

      3. Results:

        As you can see in Figure 3, the 3 x 3 closing was able to totally remove the stem from the four-leaf clover while causing neglible deformation to the rest of the shapes, with the exception of the stem of the three-leaf clover. That mask was not sufficient to remove the horns from the bull. A 7 x 7 closing was necesssary to adequately remove the bull's horns, as you can see in Figure 4. That size mask did the job, but it caused considerable deformation to the shapes, most noticable in removing the plane's wings. Although we used a coded version of a skeletonization operator rather than Cantata's, the results came out very similar. The medial axis of each shape appears to be correctly displayed in Figure 2.

        Segmenting the image cupnoise.gif with a threshold value of 90 left some salt noise in the black background and created pepper noise in the object, as can be seen by comparing Figure 5 and Figure 6. Applying the 5 x 5 mean filter completely removed the noise in the image, although it made the image slightly blurry. Segmenting this image yielded very little noise and separated the cup completely from the dark background, resulting in the best image (Figure 8). The 7 x 7 closing removed the most of the noise from the image, although it left the image appearing "splotchy". This accounts for the image in Figure 9. It is somewhat lighter in color than the original image shown in Figure 5. The colors do not blend uniformly either. Thresholding this image shows that the 7 x 7 closing was unable to remove the salt noise in the background which looked the same as the background in the raw segmented image (Figure 6).

      4. Conclusion:

        For part 1, using the closing operator to remove small features in the image makes the image less detailed. The horns on the bull required a rather large mask to be removed. As a result, the other objects in the image were badly damaged. As for skeletonization, our results were what we expected. When skeletonizing the four leaf clover, it is seen clearly how the skeleton forks at the leaves.

        For the second part, using the mean filter on the image cupnoise.gif successfully eliminated all noise in the image. Although it left the edges of the object blurry, it produced the best looking segmented image in the bunch. The mean filter appears to be the best overall filter because it can eliminate both salt and pepper noise for segmentation. When applying the 7 x 7 closing operator to the image, it effectively removed the pepper noise from the cup, but did nothing to remove salt noise from the background. To get rid of the salt noise, an opening operator would have had to be applied.

      5. Appendix:
        All images are 256 x 256.

        Figure 1: Original image
        match.gif
        Figure 2: Skeletonization applied to
        Figure 1
        Figure 3: 3 x 3 closing applied to
        Figure 1 (Stem disappears)
        Figure 4: 7 x 7 closing applied to
        Figure 1 (Horn disappears)
        Figure 5: Original Image
        cupnoise.gif
        Figure 6: Image segmentation (threshold = 90)
        applied to Figure 5
        Figure 7: 5 x 5 Mean filter applied to
        Figure 5
        Figure 8: Image segmentation (threshold = 90)
        applied to Figure 7
        Figure 9: 7 x 7 Closing operator applied
        to Figure 5
        Figure 10: Image segmentation (threshold = 90)
        applied to Figure 9

        Source code:

          The file image.h is the header file for the class of functions that we designed in C++.

          The file image.cc is the implementation file for the class of functions that we designed in C++.

          The file main.cc is the driver file for our program to compare images.

        Note: Special run scripts are necessary to execute the code.   For a complete copy of the code, scripts, and images, click here.   After you have downloaded the file:

        1. Type "gunzip -c project2.tar.gz | tar -xvf -"
        2. Type "./run images/match1.gif" to execute the code