-
Notifications
You must be signed in to change notification settings - Fork 0
/
noise_removal.m
105 lines (88 loc) · 2.39 KB
/
noise_removal.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
close all
clear
clc
fontSize=15;
%reading image
grayImage = imread('cameraman.tif');
[rows columns numberOfColorBands] = size(grayImage);
%converting to grayscale
if numberOfColorBands > 1
grayImage = rgb2gray(grayImage);
end
subplot(2, 3, 1);
imshow(grayImage, [0 255]);
title('Original Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
%noise generation
rowVector = (1 : rows)';
period = 10; % 20 rows
amplitude = 0.5; % Magnitude of the ripples.
offset = 1 - amplitude;
cosVector = amplitude * (1 + cos(2 * pi * rowVector / period))/2 + offset;
ripplesImage = repmat(cosVector, [1, columns]);
subplot(2, 3, 2);
maxValue = max(max(ripplesImage));
imshow(ripplesImage, [0 maxValue]);
axis on;
title('noise', 'FontSize', fontSize);
%adding noise to image
grayImage = ripplesImage .* double(grayImage);
subplot(2, 3, 3);
imshow(grayImage, [0 255]);
axis on;
title('Original Image with Periodic noise', 'FontSize', fontSize);
% Computing 2D fft.
frequencyImage = fftshift(fft2(grayImage));
% Taking log magnitude
amplitudeImage = log(abs(frequencyImage));
minValue = min(min(amplitudeImage));
maxValue = max(max(amplitudeImage));
subplot(2, 3, 4);
imshow(amplitudeImage, []);
axis on;
amplitudeThreshold = 10.5;
brightSpikes = amplitudeImage > amplitudeThreshold; % Binary image.
figure
imshow(brightSpikes);
axis on;
brightSpikes(115:143, :) = 0;
figure
imshow(brightSpikes);
title('Bright spikes other than central spike', 'FontSize', fontSize);
%removing the lower half
[m n]=size(frequencyImage);
frequencyImage((m/2)+2:m,:)=0;
% Filtering the spectrum.
frequencyImage(brightSpikes) = 0;
a=frequencyImage;
%%reconstruction
row_counter=m;
for i=2:(m/2)
a(row_counter,1)=conj(a(i,1));
row_counter = row_counter - 1;
end
row_counter = ( m/2 ) + 1;
for i=(m/2)+1:m
column_counter=n;
for j=2:(n/2)
a(i,j)=conj(a(row_counter,column_counter));
column_counter=column_counter - 1;
end
row_counter=row_counter - 1;
end
row_counter=m;
column_counter=n;
for i=2:(m/2)+1
column_counter=n;
for j=2:(n/2)+1
a(row_counter,column_counter)=conj(a(i,j));
column_counter=column_counter - 1;
end
row_counter=row_counter - 1;
end
figure;
imshow(mat2gray(log(1+abs(a))));
z=ifft2(a);
q=uint8(abs(z));
figure
imshow(q);