เอกสารประกอบการสอน การประมวลผลภาพ ชุดที่ ๗

Page 86

82

CHAPTER 6. SPATIAL FILTERING

>> filter2(a,x,’full’) ans = 18.8889 44.4444 48.8889 41.1111 27.7778 23.3333 12.2222

45.5556 76.6667 87.7778 66.6667 67.7778 56.6667 32.2222

46.6667 85.5556 111.1111 110.0000 131.1111 105.5556 60.0000

36.6667 65.5556 108.8889 130.0000 151.1111 107.7778 50.0000

26.6667 67.7778 128.8889 150.0000 148.8889 87.7778 40.0000

25.5556 58.8889 105.5556 106.6667 85.5556 38.8889 12.2222

16.6667 34.4444 58.8889 45.5556 37.7778 13.3333 10.0000

The shape parameter, being optional, can be omitted; in which case the default value is ’same’. There is no single “best” approach; the method must be dictated by the problem at hand; by the filter being used, and by the result required. We can create our filters by hand, or by using the fspecial function; this has many options which makes for easy creation of many different filters. We shall use the average option, which produces averaging filters of given size; thus fspecial(’average’,[5,7]) will return an averaging filter of size ; more simply fspecial(’average’,11) will return an averaging filter of size . If we leave out the final number or vector, the averaging filter is returned. For example, suppose we apply the averaging filter to an image as follows: >> c=imread(’cameraman.tif’); >> f1=fspecial(’average’); >> cf1=filter2(f1,c); We now have a matrix of data type double. To display this, we can do any of the following: transform it to a matrix of type uint8, for use with imshow, divide its values by 255 to obtain a matrix with values in the imshow,

range, for use with

use mat2gray to scale the result for display. We shall discuss the use of this function later. Using the second method: >> figure,imshow(c),figure,imshow(cf1/255) will produce the images shown in figures 6.4(a) and 6.4(b). The averaging filter blurs the image; the edges in particular are less distinct than in the original. The image can be further blurred by using an averaging filter of larger size. This is shown in


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.