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):
>> gray = imread('holiday_image2.bmp'), >> color = imread('soldier.jpg'),
>> lp = fspecial('laplacian'), >> lg = fspecial('log'), >> pr = fspecial('prewitt'), >> sb = fspecial('sobel'),
>> 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);
>> 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')
>> 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')
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?