Time for action – enhancing the edges in our images

We will now try to get a feel of what edge enhancement is all about. We will use our holiday image to perform grayscale enhancement and our soldier image to perform color enhancement (remember that the edge detection techniques of Chapter 3, Morphological Operations and Object Analysis, involved only grayscale images):

  1. First, we will load our two images in two matrices:
    >> gray = imread('holiday_image2.bmp'),
    >> color = imread('soldier.jpg'),
  2. Now, let's prepare our kernels (we'll use their default settings):
    >> lp = fspecial('laplacian'),
    >> lg = fspecial('log'),
    >> pr = fspecial('prewitt'),
    >> sb = fspecial('sobel'),
  3. Next, we apply the filters to both images (in the same line to save space):
    >> g1 = imfilter(gray,lp); c1 = imfilter(color,lp);
    >> g2 = imfilter(gray,lg); c2 = imfilter(color,lg);
    >> g3 = imfilter(gray,pr); c3 = imfilter(color,pr);
    >> g4 = imfilter(gray,sb); c4 = imfilter(color,sb);
  4. And now, let's show our grayscale results on the same figure:
    >> subplot(3,2,1),imshow(gray),title('Original grayscale
      image')
    >> subplot(3,2,2),imshow(g1),title('Grayscale Laplacian
      result')
    >> subplot(3,2,3),imshow(g2),title('Grayscale LoG result')
    >> subplot(3,2,4),imshow(g3),title('Grayscale Prewitt result')
    >> subplot(3,2,5),imshow(g4),title('Grayscale Sobel result')
    Time for action – enhancing the edges in our images
  5. Finally, let's show our color results on the same figure:
    >> subplot(3,2,1),imshow(color),title('Original color image')
    >> subplot(3,2,3),imshow(c1),title('Color Laplacian result')
    >> subplot(3,2,4),imshow(c2),title('Color LoG result')
    >> subplot(3,2,5),imshow(c3),title('Color Prewitt result')
    >> subplot(3,2,6),imshow(c4),title('Color Sobel result')
    Time for action – enhancing the edges in our images

What just happened?

You just performed edge enhancement using all the filters available by the fspecial function. In step 2, we prepared the kernels and in step 3 we filtered our images (loaded in step 1) with each one of the kernels. Note that, to save space in our text, we took advantage of the fact that we can give multiple commands in one command line, just by separating them with the semi-colon symbol (or the comma if we do not care about the result being printed on screen). The same trick has always been used in the case of plotting, so you must have understood the logic by now. The results generated in step 4 show that the edge enhancement filters produce a very interesting effect; in grayscale images they enhance the areas with sudden transitions between dark and bright (high frequencies) and in color images, they have the same effect in each color channel, therefore enhancing bright lights in night scenes. This is an interesting effect, right?

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

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