100% found this document useful (1 vote)
963 views7 pages

Implementation of SRAD Filter

This document contains MATLAB code for implementing various image filtering techniques for noise reduction, including SRAD filtering, Frost filtering, Kuan filtering, and Lee filtering. It also contains code for applying different types of spatial filters, such as mean, median, minimum, maximum filters with varying window sizes. Linear filtering using a geometric filter is demonstrated for Gaussian noise reduction on an image.

Uploaded by

Uma Mariappan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
963 views7 pages

Implementation of SRAD Filter

This document contains MATLAB code for implementing various image filtering techniques for noise reduction, including SRAD filtering, Frost filtering, Kuan filtering, and Lee filtering. It also contains code for applying different types of spatial filters, such as mean, median, minimum, maximum filters with varying window sizes. Linear filtering using a geometric filter is demonstrated for Gaussian noise reduction on an image.

Uploaded by

Uma Mariappan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

% Implementation of SRAD Filter

% Ref :Yongjian Yu and Scott T. Acton, "Speckle Reducing Anisotropic


% Diffusion",IEEE TRANSACTIONS ON IMAGE PROCESSING, VOL. 11, NO. 11, NOVEMBER
2002
% Jeny Rajan, Chandrashekar P.S
% usage S=srad(I,T)
% I- noisy image
% T - threshold (greater than 0).
function S=srad(I,T)
tic
[x y]=size(I);
I=double(I);
Ic=double(I);
delta_t = 0.08;
t=1;
eps=0.00000000001;
for t=1:T
qt=exp(-t*.2);
[Ix,Iy] = gradient(Ic);
di=sqrt(Ix.^2+Iy.^2);
di2=del2(Ic);
T1=0.5*((di./(Ic+eps)).^2);
T2=0.0625*((di2./(Ic+eps)).^2);
T3=(1+(0.25*(di2./(Ic+eps)))).^2;
T=sqrt((T1-T2)./(T3+eps));
dd=(T.^2-qt.^2)./((qt.^2*(1+qt.^2)+eps));
cq=1./(1+dd);
[D1,D2]=gradient(cq.*Ix);
[D3,D4]=gradient(cq.*Iy);
D=D1+D4;
Ic=real(Ic+delta_t .*D);
end
toc
S=uint8(Ic);
%Frost filter for speckle noise reduction
%Author : Jeny Rajan
function [ft]=frost(I)
% I is the noisy input image
tic
[x y z]=size(I);
I=double(I);
K=1;
N=I;
for i=1:x
for j=1:y
if (i>1 & i<x & j>1 & j<y)
mat(1)=I(i-1,j);
mat(2)=I(i+1,j);
mat(3)=I(i,j-1);
mat(4)=I(i,j+1);
d(1)=sqrt((i-(i-1))^2);
d(2)=sqrt((i-(i+1))^2);
d(3)=sqrt((j-(j-1))^2);
d(4)=sqrt((j-(j+1))^2);
mn=mean(mean(mat));

c=mat-mn;
c2=c.^2;
c3=c/(c2+.0000001);
Cs=0.25*sum(sum(c3));
m(1)=exp(-K*Cs*d(1));
m(2)=exp(-K*Cs*d(2));
m(3)=exp(-K*Cs*d(3));
m(4)=exp(-K*Cs*d(4));
ms=sum(sum(m));
mp=m/ms;
N(i,j)=sum(sum(mp.*mat));
end
end
end
toc
ft=uint8(N);

%Kuan filter for speckle noise reduction


%Usage - kuan(I)
%I is the noisy image (gray level image m x n x 1)
function [kn]=kuan(I)
[x y z]=size(I)
I=double(I);
for i=1:x
i
for j=1:y
% Checking first and last pixel of first row%
if (i==1 & j==1)
mat(1)=0;
mat(2)=0;
mat(3)=0;
mat(4)=0;
mat(5)=I(i,j);
mat(6)=I(i,j+1);
mat(7)=0;
mat(8)=I(i+1,j);
mat(9)=I(i+1,j+1);
end
if (i==1 & j==y)
mat(1)=0;
mat(2)=0;
mat(3)=0;
mat(4)=I(i,j-1);
mat(5)=I(i,j);
mat(6)=0;
mat(7)=I(i+1,j-1);
mat(8)=I(i+1,j);
mat(9)=0;
end
% Checking first and last pixel of last row%

if (i==x & j==1)


mat(1)=0;
mat(2)=I(i-1,j);
mat(3)=I(i-1,j+1);
mat(4)=0;
mat(5)=I(i,j);
mat(6)=I(i,j+1);
mat(7)=0;
mat(8)=0;
mat(9)=0;
end
if (i==x & j==y)
mat(1)=I(i-1,j-1);
mat(2)=I(i-1,j);
mat(3)=0;
mat(4)=I(i,j-1);
mat(5)=I(i,j);
mat(6)=0;
mat(7)=0;
mat(8)=0;
mat(9)=0;
end
% Checking rest of the image%
if (i>1 & i<x & j>1 & j<y)
mat(1)=I(i-1,j-1);
mat(2)=I(i-1,j);
mat(3)=I(i-1,j+1);
mat(4)=I(i,j-1);
mat(5)=I(i,j);
mat(6)=I(i,j+1);
mat(7)=I(i+1,j-1);
mat(8)=I(i+1,j);
mat(9)=I(i+1,j+1);
end
y1=I(i,j);
ybar=mean(mean(mat));
ystad=std2(mat);
ENL=(ybar/ystad)^2;
sx2=((ENL*(ystad)^2)-(ybar)^2)/(ENL+1);
xcap=ybar+(sx2*(y1-ybar))/(sx2+((ybar^2+sx2)/ENL));
N(i,j)=xcap;
end
end
kn=uint8(N);

%Lee filter for speckle noise reduction


%Authors : Jeny Rajan, Chandrashekar P.S
%Usage - lee(I)
%I is the noisy image (gray level image m x n x 1)
function [le]=lee(I)
[x y z]=size(I)
I=double(I);

N=zeros(x,y,z);
for i=1:x
i
for j=1:y
% Checking first and last pixel of first row%
if (i==1 & j==1)
mat(1)=0;
mat(2)=0;
mat(3)=0;
mat(4)=0;
mat(5)=I(i,j);
mat(6)=I(i,j+1);
mat(7)=0;
mat(8)=I(i+1,j);
mat(9)=I(i+1,j+1);
end
if (i==1 & j==y)
mat(1)=0;
mat(2)=0;
mat(3)=0;
mat(4)=I(i,j-1);
mat(5)=I(i,j);
mat(6)=0;
mat(7)=I(i+1,j-1);
mat(8)=I(i+1,j);
mat(9)=0;
end
% Checking first and last pixel of last row%
if (i==x & j==1)
mat(1)=0;
mat(2)=I(i-1,j);
mat(3)=I(i-1,j+1);
mat(4)=0;
mat(5)=I(i,j);
mat(6)=I(i,j+1);
mat(7)=0;
mat(8)=0;
mat(9)=0;
end
if (i==x & j==y)
mat(1)=I(i-1,j-1);
mat(2)=I(i-1,j);
mat(3)=0;
mat(4)=I(i,j-1);
mat(5)=I(i,j);
mat(6)=0;
mat(7)=0;
mat(8)=0;
mat(9)=0;
end
% Checking rest of the image%
if (i>1 & i<x & j>1 & j<y)
mat(1)=I(i-1,j-1);
mat(2)=I(i-1,j);

mat(3)=I(i-1,j+1);
mat(4)=I(i,j-1);
mat(5)=I(i,j);
mat(6)=I(i,j+1);
mat(7)=I(i+1,j-1);
mat(8)=I(i+1,j);
mat(9)=I(i+1,j+1);
end
y1=I(i,j);
ybar=mean(mean(mat));
if ybar~=0
ystad=std2(mat);
ENL=(ybar/ystad)^2;
sx2=((ENL*(ystad)^2)-(ybar)^2)/(ENL+1);
xcap=ybar+(sx2*(y1-ybar)/(sx2+(ybar^2/ENL)));
N(i,j)=xcap;
else
N(i,j)=y1;
end
end
end
le=uint8(N);

f=zeros(250,250);
%1
f(20:229,20:27)=1;
%2
f(20:229,44:51)=1;
%3
f(20:229,68:75)=1;
%4
f(20:229,92:99)=1;
%5
f(20:229,116:123)=1;
%6
f(20:229,140:147)=1;
%7
f(20:229,164:171)=1;
%8
f(20:229,188:195)=1;
%9
f(20:229,212:219)=1;
imshow(f,'InitialMagnification','fit');

%
%A_1=spfilt(f,'amean',3,3);
%figure,imshow(A_1);
%A_2=spfilt(f,'amean',5,5);
%figure,imshow(A_2);

%33
%55

%A_3=spfilt(f,'amean',7,7);
%figure,imshow(A_3);

%77

%
%B_1=spfilt(f,'gmean',3,3);
%figure,imshow(B_1);
%B_2=spfilt(f,'gmean',5,5);
%figure,imshow(B_2);
%B_3=spfilt(f,'gmean',7,7);
%figure,imshow(B_3);

%33
%55
%77

%
%C_1=spfilt(f,'hmean',3,3);
%figure,imshow(C_1);
%C_2=spfilt(f,'hmean',5,5);
%figure,imshow(C_2);
%C_3=spfilt(f,'hmean',7,7);
%figure,imshow(C_3);

%33
%55
%77

%
%D_1=spfilt(f,'chmean',3,3);
%figure,imshow(D_1);
%D_2=spfilt(f,'chmean',5,5);
%figure,imshow(D_2);
%D_3=spfilt(f,'chmean',7,7);
%figure,imshow(D_3);

%
%E_1=spfilt(f,'median',3,3);
%figure,imshow(E_1);
%E_2=spfilt(f,'median',5,5);
%figure,imshow(E_2);
%E_3=spfilt(f,'median',7,7);
%figure,imshow(E_3);
%
%F_1=spfilt(f,'midpoint',3,3);
%figure,imshow(F_1);
%F_2=spfilt(f,'midpoint',5,5);
%figure,imshow(F_2);
%F_3=spfilt(f,'midpoint',7,7);
%figure,imshow(F_3);
%
%G_1=spfilt(f,'max',3,3);
%figure,imshow(G_1);
%G_2=spfilt(f,'max',5,5);
%figure,imshow(G_2);
%G_3=spfilt(f,'max',7,7);
%figure,imshow(G_3);
%
%H_1=spfilt(f,'min',3,3);

%33
%55
%77

%33
%55
%77

%33
%55
%77

%33
%55
%77

%33

%figure,imshow(H_1);
%H_2=spfilt(f,'min',5,5);
%figure,imshow(H_2);
%H_3=spfilt(f,'min',7,7);
%figure,imshow(H_3);

%55
%77

% alpha-trimmed
%H_1=spfilt(f,'atrimmed',3,3);
%figure,imshow(H_1);
%H_2=spfilt(f,'atrimmed',5,5);
%figure,imshow(H_2);
%H_3=spfilt(f,'atrimmed',7,7);
%figure,imshow(H_3);

%33alpha-trimmed
%55alpha-trimmed
%77alpha-trimmed

%linear filtering using geometric filter--GAUSSIAN NOISE


a=imread('lc.bmp');
a=rgb2gray(a);
a=im2double(a);
imshow(a);
[row col]=size(a);
na=imnoise(a,'gaussian');
figure,imshow(na);
fa=na;
for i=1:row-2,
for j=1:col-2,
ad=1;
for g=i:i+2,
for h=j:j+2,
ad=ad*na(g,h);
end;
end;
%ad=power(ad,1/9);
ad=ad.^(1/9);
fa(i+1,j+1)=ad;
end;
end;
figure,imshow(fa);

You might also like