So far i got Impulse noise removal based on fuzzy. Now i need code to remove Gaussian noise using fuzzy.
Thanks to MATLAB File exchange and code provider,
% Fuzzy Technique for Image Impulse Noice Reduction
clear all
close all
clc
%First read the image from file
org = imread('org.bmp','bmp');
%for adding salt n peper impulse noise\/
sample = imnoise(org,'salt & pepper',0.05);
%for adding Gaussian noise, uncomment\/
% sample = imnoise(org,'gaussian',0,0.02);
%creating noisy image
imwrite(sample,'input.bmp');
%Reading noisy image
sample = imread('input.bmp','bmp');
% output = imread('input.bmp','bmp');
sample(1,:) = org(1,:);
sample(2,:) = org(2,:);
sample(:,1) = org(:,1);
sample(:,2) = org(:,2);
sample(199,:) = org(199,:);
sample(200,:) = org(200,:);
sample(:,199) = org(:,199);
sample(:,200) = org(:,200);
%obs1 = imread('input.bmp','bmp');
% Offset to measure the size of pixel matrix
K = 1;
% No of noisy pixels found in the image
victims1 = 0;
victims2 = 0;
epsilon = 20;
% Place the input to the output matrix before manipulation
for x = 1:length(sample)
for y = 1:length(sample)
obs1(x,y) = 0;
temp(x,y) = 0;
end
end
% **************** First Detection Unit
% Step 1
obs2 = Step1(sample);
% Step 2
obs1 = Step2(obs2);
%Differentiation
for x = K + 1:length(sample)- K % Rows
for y = K + 1:length(sample) - K % Columns
% Compute differences
temp(x,y) = abs( double(obs1(x,y)) - double(obs2(x,y)) );
end
end
%Fuzzy Rule 1
[obs1,victims1] = FuzzyRule1(temp,epsilon);
% **************** Second Detection Unit
%Fuzzy Rule 2 & 3 Gradients
[obs2,victims21,victims22] = FuzzyRule2n3(sample,epsilon);
common = 0;
for x = 1:length(sample)
for y = 1:length(sample)
if obs1(x,y) > 0 | obs2(x,y) > 0
temp(x,y) = 255;
common = common + 1;
else
temp(x,y) = -1;
end
end
end
% Write the Noise distributions into the respective files
imwrite( obs1,'NoiseDistribution_DetectionMothode_1.bmp');
imwrite( obs2,'NoiseDistribution_DetectionMothode_2.bmp');
imwrite( temp,'NoiseDistribution_DetectionMothode_Both.bmp');
output = ApplyOriginalFilter(temp,sample);
% output = ApplyFilter(temp,sample);
imwrite( output,'output.bmp');
victims1,victims21,common
%
scrsz = get(0,'ScreenSize');
figure('Position',[1 scrsz(4) scrsz(3) scrsz(4)])
subplot(2,3,1), subimage(org)
title('Original Image');
subplot(2,3,2), subimage(sample)
title('Noisy Image');
subplot(2,3,3), subimage(obs1)
title('Noise Distribution Detection Method 1');
subplot(2,3,4), subimage(obs2)
title('Noise Distribution Detection Method 2');
subplot(2,3,5), subimage(temp)
title('Noise Distribution Detection Both');
subplot(2,3,6), subimage(output)
title('Final Output');
scrsz = get(0,'ScreenSize');
figure('Position',[10 200 scrsz(3)/2 scrsz(4)-200])
subplot(1,2,1), subimage(sample)
title('Noisy Image');
subplot(1,2,2), subimage(output)
title('Final Output');
scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)/2 200 scrsz(3)/2 scrsz(4)-200])
subplot(1,2,1), subimage(org)
title('Original Image');
subplot(1,2,2), subimage(output)
title('Final Output');