1 / 16

Matlab Lecture 4

Matlab Lecture 4. Spatial Filtering. Image Types in the Toolbox. The Image Processing Toolbox supports four: Basic types of images: Indexed images RGB images Intensity images Binary images. Colored. Gray-scale. Black and white. Summary of Image Types and Numeric Classes.

beth
Download Presentation

Matlab Lecture 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matlab Lecture 4 Spatial Filtering

  2. Image Types in the Toolbox The Image Processing Toolbox supports four: Basic types of images: • Indexed images • RGB images • Intensity images • Binary images Colored Gray-scale Black and white

  3. Summary of Image Types and Numeric Classes

  4. Spatial Filtering • Filtering in Matlab • Linear filters:usingfspecial(type,parameter);The type could be: • ‘average’ filter • ‘laplacian’ filter • ‘log’ filter • Non-linear filters: • Median filter: • medfilt2

  5. Spatial Filtering • We can create our filters by hand, or by using the fspecial function; this has many options which makes for easy creation of many deferent filters. • fspecial(type,parameter)  creates and returns common filters. • filter2(filter,image)  apply the filter on the image

  6. Averaging Filtering • fspecial('average',[5,7]) • will return an averaging filter of size 5 x 7 • fspecial('average',11) • will return an averaging filter of size 11 x 11 • fspecial('average') • will return an averaging filter of size 3 x 3 (default)

  7. Averaging Filtering • For example, suppose we apply the 3 x 3 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. • imshow(uint8(cf1)); • divide its values by 255 to obtain a matrix with values in the 0.1-1.0 range, for use with imshow. • imshow(cf1/255); • use mat2gray to scale the result for display. • imshow(mat2gray(cf1)); >> figure,imshow(c),figure,imshow(cf1/255)

  8. Averaging Filtering • 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 the following figures:

  9. Averaging Filtering

  10. Averaging Filtering

  11. Frequencies; low and high pass Filters • High pass filter if it passes over the high frequency components, and reduces or eliminates low frequency components. • Low pass filter if it passes over the low frequency components, and reduces or eliminates high frequency components. • Both are mainly used for noise reduction, sharpen, or smooth the image. • May be used for edge detection. • The output may be the same for the tow types. • sharp  smooth (low), smooth  sharp (high)

  12. Frequencies; low and high pass Filters >> f=fspecial('laplacian'); >> cf=filter2(f,c); >> imshow(cf/255); >> f1=fspecial('log'); >> cf1=filter2(f1,c); >> figure,imshow(cf1/255);

  13. High Pass Filtering • The images are shown in figure 6.5. Image (a) is the result of the Laplacian filter; image (b) shows the result of the Laplacian of Gaussian (log) filter.

  14. Median Filter • medfilt2 • Median filtering is a nonlinear operation often used in image processing to reduce "salt and pepper" noise. • What is "salt and pepper" noise ? • it is randomly occurring of white and black pixels. n = imnoise(i,'salt & pepper‘,0.2); imshow(n); The default is 0.05 Higher value  more noise

  15. Median Filter • B = medfilt2(A) performs median filtering of the matrix A using the default 3-by-3. • Examples • Add salt and pepper noise to an image and then restore the image using medfilt2. >>I = imread('eight.tif'); >>J = imnoise(I,'salt & pepper',0.2); >>K = medfilt2(J); >>imshow(J), figure, imshow(K)

More Related