sir i have written the code for removing the noise in a color image.so can it be extended for video file

6 views (last 30 days)
i = imread('mandi.tif');
imshow(i);
%demosaic of image
rgb = demosaic(i,'bggr'); *%raw image is converted into true color image*
figure,imshow(rgb);
m1=mean2(rgb);
SD1=mean2(stdfilt(rgb));
snr1=(m1/SD1) *%signal to noise ratio calculation of noise free image*
for i=500:1:1000
for j=500:1:1000
rgb(i,j)=imnoise(rgb(i,j),'gaussian',9); *%noise addition*
end
end
figure,imshow(rgb);
m2=mean2(rgb);
SD2=mean2(stdfilt(rgb));
snr2=(m2/SD2) *%signal to noise ratio calculation of noisy image*
r=rgb;g=rgb;b=rgb;
r(:,:,2)=0;
r(:,:,3)=0;
g(:,:,1)=0;
g(:,:,3)=0;
b(:,:,1)=0;
b(:,:,2)=0;
m = size(rgb,1)
n = size(rgb,2)
for i=2:1:m-1
for j=2:1:n-1
A1=abs(r(i-1,j-1)-r(i+1,j+1)); *% horizontal internal gradient*
B1=abs(r(i-1,j+1)-r(i+1,j-1)); *% vertical internal gradient*
end
end
for i=3:1:m-2
for j=3:1:n-2
A2=abs(2*g(i,j)-g(i-1,j-2)-g(i+1,j+2)); *% horizontal external gradient*
B2=abs(2*g(i,j)-g(i-2,j-1)-g(i+2,j+1)); *% vertical external gradient*
end
end
% to find existence of edge or influence of the noise TH (enumeration variable) is used for noise that in the up and down or in any point of g(i,j)
for k=2:2:m-1
for l=3:2:n-1
x=[k-1,k+1];
y=[l-1,l+1];
up=(A1<B1) & (eq(A2,B2)) & eq(max(abs(2*r(k,y)-r(k-1,l)-r(k+1,l))),l-1); %up says that g(i,j-1) is the noise
down=(A1<B1) & (eq(A2,B2)) & eq(max(abs(2*r(k,y)-r(k-1,l)-r(k+1,l))),l+1); %down says that g(i,j+1) is the noise
left=(A1>B1) & (eq(A2,B2)) & eq(max(abs(2*r(x,l)-r(k,l-1)-r(k,l+1))),k-1); %left says that g(i-1,j) is the noise
right=(A1>B1) & (eq(A2,B2)) & eq(max(abs(2*r(x,l)-r(k,l-1)-r(k,l+1))),k+1); %right says that g(i+1,j) is the noise
no=(eq(A1,B1)) & (eq(A2,B2)); *%no says that there is no noise and also no edge *
level=(A1>B1) & (A2>B2); % level says that there is a edge in vertical direction
erect=(A1>B1) & (A2<B2); % erect says that there is a edge in horizontal direction
end
end
p=[1 2 3 4 5 6 7]
TH=[up down left right no level erect]
p_TH=p(TH==1)
for i=2:1:m-1
for j=2:1:n-1
% switches according to the TH value
switch p_TH
case 1
r(i,j)=(r(i-1,j)+r(i+1,j)+r(i,j+1))/3;
r(i,j-1)=r(i,j);
case 2
r(i,j)=(r(i-1,j)+r(i+1,j)+r(i,j-1))/3;
r(i,j+1)=r(i,j);
case 3
r(i,j)=(r(i+1,j)+r(i,j-1)+r(i,j+1))/3;
r(i-1,j)=r(i,j);
case 4
r(i,j)=(r(i-1,j)+r(i,j-1)+r(i,j+1))/3;
r(i+1,j)=r(i,j);
case 5
r(i,j)=(r(i-1,j)+r(i+1,j)+r(i,j-1)+r(i,j+1))/4;
case 6
r(i,j)=(r(i-1,j)+r(i+1,j))/2;
case 7
r(i,j)=(r(i,j-1)+r(i,j+1))/2;
end
end
end
s=r+g+b;
figure,imshow(s);
m3=mean2(s);
SD3=mean2(stdfilt(s));
snr3=(m3/SD3) *%signal to noise ratio calculation of image after removal of noise*

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!