Matlab Lecture 4

Preview:

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

MATLAB LECTURE 4Spatial 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-scaleBlack and white

SUMMARY OF IMAGE TYPES AND NUMERIC CLASSES

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

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

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)

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)

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:

AVERAGING FILTERING

AVERAGING FILTERING

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)

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

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.

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

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)

Recommended