16
MATLAB LECTURE 4 Spatial Filtering

Matlab Lecture 4

  • Upload
    beth

  • View
    53

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: Matlab   Lecture 4

MATLAB LECTURE 4Spatial Filtering

Page 2: Matlab   Lecture 4

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-scaleBlack and white

Page 3: Matlab   Lecture 4

SUMMARY OF IMAGE TYPES AND NUMERIC CLASSES

Page 4: Matlab   Lecture 4
Page 5: Matlab   Lecture 4

SPATIAL FILTERING

Filtering in MatlabLinear filters:

using fspecial(type,parameter);The type could be: ‘average’ filter ‘laplacian’ filter ‘log’ filter

Non-linear filters:Median filter:

medfilt2

Page 6: Matlab   Lecture 4

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

Page 7: Matlab   Lecture 4

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)

Page 8: Matlab   Lecture 4

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)

Page 9: Matlab   Lecture 4

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:

Page 10: Matlab   Lecture 4

AVERAGING FILTERING

Page 11: Matlab   Lecture 4

AVERAGING FILTERING

Page 12: Matlab   Lecture 4

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)

Page 13: Matlab   Lecture 4

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);

Page 14: Matlab   Lecture 4

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.

Page 15: Matlab   Lecture 4

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.05Higher value more noise

Page 16: Matlab   Lecture 4

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)