Beruflich Dokumente
Kultur Dokumente
Vedat Tavşanoğlu
Image Filtering
y( n , m ) x( k ,l )h( n k , m l )
k l
x( n k , m l )h( k ,l )
k l
Image Filtering
j x j y j ( x m y n )
Y( e ,e ) y( n , m )e
n m
[ x( k ,l )h( n k , m l ) ] e
j ( x m y n )
n m k l
[ x( n k , m l )h( k ,l ) ] e
j ( x m y n )
n m k l
Image Filtering
Now let
n k i and m l j
j x j y
Y( e ,e )
[ x( k ,l )h( i , j ) ] e
j ( x ( j l ) y ( i k ))
n m k l
[ x( i , j )h( k ,l ) ] e
j ( x ( j l ) y ( i k ))
n m k l
Image Filtering
j x j y
Y( e ,e )
h( i , j )e x( k ,l )e
j ( x i y j ) j ( x l y k )
i j k l
j x j y j x j y
H( e ,e )X ( e ,e )
Image Filtering
Low-pass Filtering:
Image Filtering
Low-pass Filtering:
Image Filtering
Low-pass Filtering:
Image Filtering
Low-pass Filtering:
1 1 1
h 1 1 1
1 1 1
Image Filtering
Low-pass Fıltering:
I=zeros(12,12);
I(2:9,2:9)=1;
h=ones(3,3)/9;
Iout=conv2(I,h)
imshow(I,'notruesize'),title('Original Image')
figure,mesh(I)
imshow(h,'notruesize'),title('Original Image')
figure,mesh(h)
figure,imshow(Iout,'notruesize'),title('Filtered Image')
figure,mesh(Iout);
Image Filtering
Low-Pass Filter
Close all
I=ones(12,12);
I(2:9,2:9)=1;
h=ones(3,3)/9;
Iout=conv2(I,h)
imshow(I,'notruesize'),title('Original Image')
figure,mesh(I),title('Original Image')
F=fft2(I,256,256);
F=fftshift(F);
F2=abs(F);
Image Filtering
figure,imshow(F2,[0
5],'notruesize');colormap(jet);colorbar,title('FT Original
Image')
figure,mesh(F2),title('FT of Original Image')
figure,mesh(h),title('Filter Kernel')
H=fft2(h,256,256);
H=fftshift(H);
H2=abs(H);
figure,imshow(H2,[0
5],'notruesize');colormap(jet);colorbar,title('FT of Filter
Kernel')
figure,mesh(H2),title('FT of Filter Kernel')
figure,imshow(Iout,'notruesize'),title('Filtered Image')
figure,mesh(Iout),title('Filtered Image')
Image Filtering
I2=fft2(Iout,256,256);
I2=fftshift(I2);
I2=abs(I2);
figure,imshow(I2,[0
5],'notruesize');colormap(jet);colorbar,title('FT of
Filtered Image')
figure,mesh(I2),title('FT of Filtered Image')
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
OUTPUT IMAGE
0 0 0 0 0 0 0 0 0 0 0 0
0 .11 .22 .33 .33 .33 .33 .33 .33 .22 .11 0
0 .22 .44 .67 .67 .67 .67 .67 .67 .44 .22 0
0 .33 .67 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33 0
0 .33 .67 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33 0
0 .33 .67 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33 0
0 .33 .67 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33 0
0 .33 .67 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33 0
0 .33 .67 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33 0
0 .22 .44 .67 .67 .67 .67 .67 .67 .44 .22 0
0 .11 .22 .33 .33 .33 .33 .33 .33 .22 .11 0
0 0 0 0 0 0 0 0 0 0 0 0
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Low-pass Fıltering
Exercise: Apply the same filter to the image given by
I=ones(10,10).
Image Filtering
Iout =
Columns 1 through 10
0.1111 0.2222 0.3333 0.3333 0.3333 0.3333 0.3333 0.3333 0.3333 0.3333
0.2222 0.4444 0.6667 0.6667 0.6667 0.6667 0.6667 0.6667 0.6667 0.6667
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.3333 0.6667 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
0.2222 0.4444 0.6667 0.6667 0.6667 0.6667 0.6667 0.6667 0.6667 0.6667
0.1111 0.2222 0.3333 0.3333 0.3333 0.3333 0.3333 0.3333 0.3333 0.3333
Image Filtering
Columns 11 through 12
0.2222 0.1111
0.4444 0.2222
0.6667 0.3333
0.6667 0.3333
0.6667 0.3333
0.6667 0.3333
0.6667 0.3333
0.6667 0.3333
0.6667 0.3333
0.6667 0.3333
0.4444 0.2222
0.2222 0.1111
Image Filtering
FILTERED IMAGE
.11 .22 .33 .33 .33 .33 .33 .33 . 33 .33 .22 .11
.22 .44 .67 .67 .67 .67 .67 .67 .67 .67 .44 .22
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.33 .67 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 .67 .33
.22 .44 .67 .67 .67 .67 .67 .67 .67 .67 .44 .22
.11 .22 .33 .33 .33 .33 .33 .33 .33 .33 .22 .11
Image Filtering
Image Filtering
Image Filtering
Image Filtering
High-Pass Filter
Image Filtering
High-Pass Filter
High-pass filter with no DC bias
(coefficients added to zero)
8 1 1
8
1
8
h 18 1 1
8
18 1
8
1
8
Image Filtering
High-Pass Filter
High-pass filter with no DC bias
(coefficients added to zero)
8 1 1
8
1
8
h 18 1 1
8
18 1
8
1
8
Image Filtering High-Pass Filter
Image Filtering High-Pass Filter
Image Filtering High-Pass Filter
Image Filtering
Close all
I=zeros(16,16);
I(5:12,5:12)=1;
h=ones(3,3)/8;
h=-h;
h(2:2,2:2)=1;
Iout=conv2(I,h);
imshow(I,'notruesize'),title('Original Image')
figure,mesh(I),title('Original Image')
F=fft2(I,256,256);
F=fftshift(F);
F2=abs(F);
Image Filtering
figure,imshow(F2,[0
5],'notruesize');colormap(jet);colorbar,title('FT Original
Image')
figure,mesh(F2),title('FT of Original Image')
figure,imshow(h,'notruesize'),title('Filter Kernel')h
figure,mesh(h),title('Filter Kernel')
H=fft2(h,256,256);
H=fftshift(H);
H2=abs(H);
figure,imshow(H2,[0
1.5],'notruesize');colormap(jet);colorbar,title('FT of
Filter Kernel')
figure,mesh(H2),title('FT of Filter Kernel')
figure,imshow(Iout,[-.5 .7],'notruesize'),title('Filtered
Image')
figure,mesh(Iout),title('Filtered Image')
Image Filtering
I2=fft2(Iout,256,256);
I2=fftshift(I2);
I2=abs(I2);
figure,imshow(I2,[0
5],'notruesize');colormap(jet);colorbar,title('FT of
Filtered Image')
figure,mesh(I2),title('FT of Filtered Image')
Image Filtering
Image Filtering
I=
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Image Filtering
Iout =
Columns 1 through 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 -0.1250 -0.2500 -0.3750 -0.3750 -0.3750 -0.3750
0 0 0 0 -0.2500 0.6250 0.3750 0.3750 0.3750 0.3750
0 0 0 0 -0.3750 0.3750 0 0 0 0
0 0 0 0 -0.3750 0.3750 0 0 0 0
0 0 0 0 -0.3750 0.3750 0 0 0 0
0 0 0 0 -0.3750 0.3750 0 0 0 0
0 0 0 0 -0.3750 0.3750 0 0 0 0
0 0 0 0 -0.3750 0.3750 0 0 0 0
0 0 0 0 -0.2500 0.6250 0.3750 0.3750 0.3750 0.3750
0 0 0 0 -0.1250 -0.2500 -0.3750 -0.3750 -0.3750 -0.3750
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Image Filtering
Columns 11 through 18
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
-0.3750 -0.3750 -0.2500 -0.1250 0 0 0 0
0.3750 0.3750 0.6250 -0.2500 0 0 0 0
0 0 0.3750 -0.3750 0 0 0 0
0 0 0.3750 -0.3750 0 0 0 0
0 0 0.3750 -0.3750 0 0 0 0
0 0 0.3750 -0.3750 0 0 0 0
0 0 0.3750 -0.3750 0 0 0 0
0 0 0.3750 -0.3750 0 0 0 0
0.3750 0.3750 0.6250 -0.2500 0 0 0 0
-0.3750 -0.3750 -0.2500 -0.1250 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
High-pass filtering of rotated image
The image I in the previous example can be rotated 45o
by using I=imrotate(I,45),and we obtain
Image Filtering
I=
Columns 1 through 17
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Image Filtering
Iout =
Columns 1 through 10
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 -0.1250
0 0 0 0 0 0 0 0 -0.1250 -0.3750
0 0 0 0 0 0 0 -0.1250 -0.3750 0.3750
0 0 0 0 0 0 0 -0.1250 0.6250 0.2500
0 0 0 0 0 0 0 -0.1250 -0.3750 0.3750
0 0 0 0 0 0 0 0 -0.1250 -0.3750
0 0 0 0 0 0 0 0 0 -0.1250
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Image Filtering
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 -0.1250 -0.1250 -0.1250 0 0 0 0 0
0 -0.1250 -0.3750 0.6250 -0.3750 -0.1250 0 0 0 0
-0.1250 -0.3750 0.3750 0.2500 0.3750 -0.3750 -0.1250 0 0 0
-0.3750 0.3750 0.1250 0 0.1250 0.3750 -0.3750 -0.1250 0 0
0.3750 0.1250 0 0 0 0.1250 0.3750 -0.3750 -0.1250 0
0.1250 0 0 0 0 0 0.1250 0.3750 -0.3750 -0.1250
0 0 0 0 0 0 0 0.2500 0.6250 -0.1250
0.1250 0 0 0 0 0 0.1250 0.3750 -0.3750 -0.1250
0.3750 0.1250 0 0 0 0.1250 0.3750 -0.3750 -0.1250 0
-0.3750 0.3750 0.1250 0 0.1250 0.3750 -0.3750 -0.1250 0 0
-0.1250 -0.3750 0.3750 0.2500 0.3750 -0.3750 -0.1250 0 0 0
0 -0.1250 -0.3750 0.6250 -0.3750 -0.1250 0 0 0 0
0 0 -0.1250 -0.1250 -0.1250 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Hihg-pass filter with DC bias
(coefficients added to one)
1 1 1
h 1 9 1
1 1 1
Image Filtering
Image Filtering
Image Filtering
Iout =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 -1 -2 -3 -3 -3 -3 -3 -3 -2 -1 0 0 0 0
0 0 0 0 -2 6 4 4 4 4 4 4 6 -2 0 0 0 0
0 0 0 0 -3 4 1 1 1 1 1 1 4 -3 0 0 0 0
0 0 0 0 -3 4 1 1 1 1 1 1 4 -3 0 0 0 0
0 0 0 0 -3 4 1 1 1 1 1 1 4 -3 0 0 0
0
0 0 0 0 -3 4 1 1 1 1 1 1 4 -3 0 0 0
0
0 0 0 0 -3 4 1 1 1 1 1 1 4 -3 0 0 0
0 0 0 0 -3 4 1 1 1 1 1 1 4 -3 0 0 0 0
0 0 0 0 -2 6 4 4 4 4 4 4 6 -2 0 0 0 0
0 0 0 0 -1 -2 -3 -3 -3 -3 -3 -3 -2 -1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Edge Detection Methods Based on the First Derivative
Image Filtering
Edge Detection Methods Based on the First Derivative
Image Filtering
Edge Detection (Enhancement)
Edge Detection Methods Based on the Second Derivative
Image Filtering
Edge Detection (Enhancement)
Edge Detection Methods Based on the Second Derivative
I ( x, y ) I ( x x, y ) I ( x, y )
x x
Image Filtering
Edge Detection (Enhancement)
I ( x x, y ) I ( x, y ) I ( x, y ) I ( x x, y )
2 I ( x, y ) x x
x 2 x
I ( x x, y ) 2 I ( x, y ) I ( x x, y )
x 2
Image Filtering
Edge Detection (Enhancement)
Similarly we obtain
I ( x, y ) I ( x, y y ) 2 I ( x, y ) I ( x, y y )
2
y 2
y 2
Let Dx=Dy=1pixel and x and y be the vertical and
horizontal axes. Then the above equations represent the
convolution sums for the pixel (x,y) in the output image
obtained as a result of the convolutions of the input
image I(x,y) with the filter kernels
1
hx 2, hy 1 2 1
1
respectively.
Image Filtering
Edge Detection(Enhancement)
Image Filtering
Edge Detection (Enhancement)
I ( x, y ) I ( x, y )
2 2
I ( x, y )
x 2
y 2
Image Filtering
Edge Detection (Enhancement)
2 I ( x, y ) 2 I ( x, y ) I ( x x, y ) 2 I ( x, y ) I ( x x, y ) I ( x, y y ) 2 I ( x, y ) I ( x, y y )
I ( x, y )
x 2 y 2 x 2 y 2
Assuming that x=y=1pixel, the above represents the
convolution sum for the pixel (x,y) in the output image
obtained as a result of the convolution of the input image
I(x,y) with the filter kernel
0 1 0
h 1 4 1
0 1 0
which is called the Laplacian Edge Enhancement Kernel.
Image Filtering
Edge Detection (Enhancement)
Now applying Euler’s forward difference in the ‘y’ direction
I ( x x, y y ) 2 I ( x, y y ) I ( x x, y y ) I ( x x, y ) 2 I ( x, y ) I ( x x, y )
( I ( x, y ))
2
x 2
x 2
yx 2 y
1 2 1
h 2 4 2
1 2 1
Image Filtering
Edge Detection (Enhancement)
0 1 0
h 1 4 1
0 1 0
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
1 2 1
h 2 4 2
1 2 1
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Edge Detection (Enhancement)
Image Filtering
Close all
I = zeros(256,256);
r = 75;
r2 = r*r;
x = -r;
cx=120;
cy=120;
while x < r
y1 = (sqrt(r2-x*x)+cx);
y2 = (-sqrt(r2-x*x)+cx);
y3 = (sqrt(r2-x*x)+cy);
y4 = (-sqrt(r2-x*x)+cy);
for i = cy:round(y1)
I(i,x+cy) = 1;
end
Image Filtering
for i = round(y2):cy
I(i,x+cy) = 1;
end
I(x+cx,round(y3)) = 1;
I(x+cx,round(y4)) = 1;
x = x+1;
end
h = [1/8 1/8 1/8
1/8 1 1/8
1/8 1/8 1/8]
Iout=conv2(I,h);
imshow(I,'notruesize'),title('Original Image')
figure,mesh(I),title('Original Image')
Image Filtering
F=fft2(I,256,256);
F=fftshift(F);
F2=abs(F);
figure,imshow(F2,[0
5],'notruesize');colormap(jet);colorbar,titl
e('FT Original Image')
figure,mesh(F2),title('FT of Original Image')
figure,imshow(h,[-.125
1],'notruesize'),title('Filter Kernel')
figure,mesh(h),title('Filter Kernel')
H=fft2(h,256,256);
H=fftshift(H);
H2=abs(H);
Image Filtering
Close all
I = zeros(256,256);
r = 75;
r2 = r*r;
x = -r;
cx=120;
cy=120;
while x < r
y1 = (sqrt(r2-x*x)+cx);
y2 = (-sqrt(r2-x*x)+cx);
y3 = (sqrt(r2-x*x)+cy);
y4 = (-sqrt(r2-x*x)+cy);
for i = cy:round(y1)
I(i,x+cy) = 1;
end
Image Filtering
for i = round(y2):cy
I(i,x+cy) = 1;
end
I(x+cx,round(y3)) = 1;
I(x+cx,round(y4)) = 1;
x = x+1;
end
h = [1/8 1/8 1/8
1/8 1 1/8
1/8 1/8 1/8]
Iout=conv2(I,h);
imshow(I,'notruesize'),title('Original Image')
figure,mesh(I),title('Original Image')
Image Filtering
F=fft2(I,256,256);
F=fftshift(F);
F2=abs(F);
figure,imshow(F2,[0
5],'notruesize');colormap(jet);colorbar,titl
e('FT Original Image')
figure,mesh(F2),title('FT of Original Image')
figure,imshow(h,[-.125
1],'notruesize'),title('Filter Kernel')
figure,mesh(h),title('Filter Kernel')
H=fft2(h,256,256);
H=fftshift(H);
H2=abs(H);
Image Filtering
figure,imshow(H2,[0
1.5],'notruesize');colormap(jet);colorbar,title('FT
of Filter Kernel')
figure,mesh(H2),title('FT of Filter Kernel')
figure,imshow(Iout,'notruesize'),title('Filtered
Image')
figure,mesh(Iout),title('Filtered Image')
I2=fft2(Iout,256,256);
I2=fftshift(I2);
I2=abs(I2);
figure,imshow(I2,[0 5],'notruesize');colormap(jet);
colorbar,title('FT of Filtered Image')
figure,mesh(I2),title('FT of Filtered Image')
Image Filtering
1 / 10 1 / 10 1 / 10 1 / 10 1 / 10 1 / 10
1 / 10 1 / 5 1 / 10 1 / 10 2 / 5 1 / 10
1 / 10 1 / 10 1 / 10 1 / 10 1 / 10 1 / 10
Image Filtering
Middle row of the mask:
1/ 4 1 / 2 1 / 4
Yields FIR digital filter with the transfer function:
Z-transform of h(n)
1 z
H (z) H 1(z) H 2 (z)
1 z 1 1 z
1 2
H ( z)
z 1 1 2 z
Image Filtering
Frequency response
1 2
H ( e j )
1 2 2 cos
Image Filtering
Difference Equation
1 2 V ( z)
H ( z)
z 1 z U ( z )
1 2
v ( n 1) (1 2 ) v ( n ) v ( n 1) (1 2 )u ( n ) 0
(1 )2
0 1 2
0
x x x x x x
y ( n 1) y (n) y ( n 1) x ( n 1) x ( n ) x ( n 1)
+
Now defining:
G0 (1 ) 2 , G1
v ( n 1) (1 2 ) v ( n ) v ( n 1) (1 2 )u ( n ) 0
yields:
Image Filtering
G1v ( n 1) (G0 2G1 )v ( n) G1v ( n 1) (1 2 )u ( n) 0
Which represents the node equation of the following
resistive circuit:
where
v(n): the node voltage of node n (output)
u(n): the current source connected to node n,
where, u(n) is the input and 2
(1 )
2
.
Image Filtering
The above can be extended to the 2-D case using the
2-D templates:
0 0 0 0 0
A (1 4 2 ) , B 0 1 4 2 0
0 0 0 0 0
v ( m , n 1) (1 4 2 ) v ( m , n ) v ( m 1, n ) v ( m 1, n ) v ( m , n 1) (1 4 2 )u ( m , n ) 0
1
a
k ,l 1
k ,l v(m k , n l ) bu (m, n) 0
where
A ak ,l 1k ,l 1 : feedback cloning template
b : feedforward cloning template
Image Filtering
Z-transform of h(m,n)
V (zx , zy ) 1 4 2
H (zx , zy )
U (zx, zy ) z y 1 (1 4 2 ) z x z x 1 z y
Frequency response
j x j
j x j Y (e ,e y
) 1 4 2
H (e ,e y
) j y
X (e j x
,e ) 1 4 2
2 cos x 2 cos y
Image Filtering
>0 yields low-pass filters
0.45 0.25
Image Filtering
<0 yields high-pass filters
0.45 0.25
Image Filtering
Such 2-D transfer functions can be obtained
using resistive grid structures.
v ( m , n 1) (1 4 2 ) v ( m , n ) v ( m 1, n )
v ( m 1, n ) v ( m , n 1) (1 4 2 )u ( m , n ) 0
Defining:
G 0 (1 2 ) 2
, G1
yields:
Image Filtering
G1v ( m, n 1) G0 v ( m, n) G1v ( m 1, n) G1v ( m 1, n) G1v ( m, n 1) (1 4 2 )u ( m, n) 0
1 2
H LP (e j )
e j 1 2 e j
by o.
1 2
H LP (e j ( 0 ) )
e j ( 0 ) 1 2 e j ( 0 )
Image Filtering
Shifting the LP by yields BP.
j ( 0 ) 1 2
H BP (e j ) H LP (e )
1 2 2 cos( o )
Image Filtering
The corresponding H(z):
1 2
H BP ( z )
e j o z 1 1 2 e j o z
leading to the templates:
A [ e jo (1 2 ) e j ]
o
and B [0 1 2 0]
A a e k
jko
k
: feedback cloning template;
B b e k
jko
k
: feedforward cloning template.
Image Filtering
Similarly shifting of 2-D LP yields:
j x j y j ( x xo ) j ( y yo ) 1 4 2
H BP (e ,e ) H LP (e ,e )
1 4 2 2 cos( x xo ) 2 cos( y yo )
j x j y (1 2 ) 2 /
H BP (e ,e )
1 4 2
2 cos( x xo ) 2 cos( y yo )
2-D band-pass filter tuned to the centre
frequency (xo,yo)
Now let: (1 2 ) /
2 2
Image Filtering
j y 2
H BP (e j x , e )
4 2 2 cos( x xo ) 2 cos( y yo )
The templates :
j
0 e y0 0
j x 0 j x 0
A e (4 ) 2 e
0 e
j y 0
0
0 0 0
B 0 2 0
0 0 0
Image Filtering
In practice, every node will also have a
parasitic capacitor connected to the ground.
Considering these capacitors the spatial
difference equation becomes :
dv(n)
C G1v(n 1 ) (G0 2G1 )v(n) G1v(n 1 ) ( 1 α 2 )u(n) 0
dt 1
v(n) a v(n k ) bu (n)
k 1
k
CNN Filters
A circuit realisation
Image Filtering
or
1
v(m, n) a
k ,l 1
k ,l v(m k , n l ) bu (m, n)
respectively.
This happens when the states v(n), v(m,n)
become constant
i.e., settle to a solution.
That is, the processing of the image has been
completed.
Image Filtering
clear all;
close all;
I = zeros(64,64);
I(15:25,15:25)=1;
I(15:25,35:45)=1;
I(35:45,15:25)=1;
I(35:45,35:45)=1;
a = zeros(128,128);
a=[1010101010101010]
z = a;
for k = 1:7
z = [z a] ;
end
l = z;
for k = 1:127
z = [z;l];
end
z = 1 - z;
figure, imshow(z,'notruesize')
figure, imshow(I,'notruesize')
Image Filtering
clear all;
close all;
I = zeros(64,64);
I(15:25,15:25)=1;
I(15:25,35:45)=1;
I(35:45,15:25)=1;
I(35:45,35:45)=1;
a = zeros(128,128);
b = zeros(128,128);
a = [ 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0];
b=[1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0];
z = a;
s=b;
for k = 1:7
z = [z a] ;
s=[s b];
end
l = z;
j=s;
for k = 1:127
z = [z;l];
s=[s;j];
end
z = 1 - z;
figure, imshow(z,'notruesize')
figure, imshow(I,'notruesize')
figure, imshow(s,'notruesize')
Image Filtering
Image Filtering
Image Filtering
Image Filtering
Noise Removal
For example:
•If the image is scanned from a photograph made on film, the
film grain is a source of noise. Noise can also be the result
Of damage to the film, or be introduced by the scanner itself.
•If the image is acquired directly in a digital format, the
mechanism for gathering the data (such as a CCD detector) can
introduce noise.
•Electronic transmission of image data can introduce noise.
Image Filtering
The MATLAB toolbox provides a number of different
ways toremove or reduce noise in an image. Different
methods are better for different kinds of noise. The
Methods available include:
•Linear filtering
•Median filtering
•Adaptive filtering
close all
I =imread('saturn.tif');
J =imnoise(I,'gaussian',0,0.005);
K =medfilt2(J,[3 3 ]);
M =wiener2(J,[5 5 ]);
imshow(I),title('Original Image');
figure,imshow(J),title('Noisy Image');
figure,imshow(K),title('Median filtered Image');
figure,imshow(M),title('Wiener filtered Image');
Image Filtering
Image Filtering
Image Deblurring
Understanding Deblurring
This section provides some background on deblurring
techniques. The section includes these topics:
•“Causes of Blurring”
•“Deblurring Model”
Causes of Blurring
The blurring, or degradation, of an image can be caused
by many factors:
•Movement during the image capture process, by the
camera or, when long exposure times are used, by the
subject
Image Filtering
•Out-of-focus optics, use of a wide-angle
lens, atmospheric turbulence, or a short
exposure time, which reduced the number of
photons captured