>> orgImg=imread('cameraman.tif');
>> filterArray=ones(3,3)/9;
>> filterArray
filterArray =
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
>> appFilter_1=filter2(filterArray,orgImg,'same');
>> appFilter_2=filter2(filterArray,orgImg,'full');
>> appFilter_3=filter2(filterArray,orgImg,'valid');
>> figure, imshow(orgImg);
>> figure, imshow(appFilter_1/255);
>> figure, imshow(appFilter_2/255);
>> figure, imshow(appFilter_3/255);
//Spatial Filter
>> clear all
>> close all
>> i=zeros(200,200);
>> i(150,50: 50:150)=1;
>> imshow(i,[]);
>>
>> %apply 3*3 Box Filter
>> w=[1 1 1; 1 1 1; 1 1 1;]/9;
>> w
w =
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
0.1111 0.1111 0.1111
>> i2=imfilter(i,w);
>> imtool(i2,[]);
>>
>> w=fspecial('average',[15 15]);
>> w
w =
Columns 1 through 5
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
Columns 6 through 10
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
Columns 11 through 15
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
0.0044 0.0044 0.0044 0.0044 0.0044
>> i3=imfilter(i,w);
>> imtool(i3,[]);
>>
>> %Show Tha Averaging Reduces Noise
>> i=i+randn(200,200)*[0.5];
>> imshow(i,[]);
>> w=fspecial('average',[5 5]);
>> i4=imfilter(i,w);
>> figure, imshow(i4,[]);