Creating filters with fspecial

So far you have seen the averaging filter kernel, which can be generated in any method possible that can produce a mxn matrix with all its values equal to 1/mn.

The fspecial function used in our previous examples is one way to produce the averaging kernel mentioned. However, it can be used to produce several other filtering kernels. A simple call to the help of MATLAB on this function shows us its usage in the first few lines of the result:

>> help fspecial

The call to the help command of MATLAB will give following output:

 fspecial Create predefined 2-D filters.
    H = fspecial(TYPE) creates a two-dimensional filter H of the
    specified type. Possible values for TYPE are:
      'average'   averaging filter
      'disk'      circular averaging filter
      'gaussian'  Gaussian lowpass filter
      'laplacian' filter approximating the 2-D Laplacian operator
      'log'       Laplacian of Gaussian filter
      'motion'    motion filter
      'prewitt'   Prewitt horizontal edge-emphasizing filter
      'sobel'     Sobel horizontal edge-emphasizing filter
      'unsharp'   unsharp contrast enhancement filter

This means that fspecial can create nine different filters, depending on the input choice of the user. If we want to categorize them according to their functionality, we will have to use three broad categories:

  • Image smoothing or Blurring: This is a process that is performed using low-pass filters. The ones that fspecial provides are average, disk, motion and gaussian. The filters of this type are generally called low-pass because they only let image areas with low frequencies (smooth areas without much detail) be unaffected.
  • Edge detection filters: These are the core filters used for the edge detection techniques visited in Chapter 3, Morphological Operations and Object Analysis. The ones supported by fspecial are laplacian, log, prewitt and sobel. All these filters suppress the pixel values in areas that do not have many edges and enhance the edges in the image. When they are thresholded, they produce results like the ones generated by edge.
  • Finally, fspecial can create a filter that is used for high-pass filtering, that is, the enhancement of areas that contain much detail. This has the opposite effect from the first group of filters and can be accomplished using an unsharp kernel.

In the rest of the chapter, we will try to check the functionality of some of these filters, using real and practical examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset