-
Notifications
You must be signed in to change notification settings - Fork 0
/
Noise.asv
48 lines (37 loc) · 1.52 KB
/
Noise.asv
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
classdef Noise
properties (Constant)
noiseTypesInbuilt = ['gaussian', 'salt & pepper', 'speckle', 'poisson', 'localvar'];
end
methods
function noisy = noise_inbuilt(image, noiseType,h)
if(noiseType <= 3)
noisy = imnoise(image, Noise.noiseTypesInbuilt(noiseType), h);
elseif(noiseType == 4)
noisy = imnoise(image, Noise.noiseTypesInbuilt(noiseType), h);
else
noisy = imnoise(image, Noise.noiseTypesInbuilt(noiseType), h*rand(size(image)));
end
end
function noisy = noise_custom(image, noiseType, h)
sz = size(image);
switch noiseType
case 1
noisy = rayleigh_noise_cvip(image, h*10, sz);
case 2
noisy = gamma_noise_cvip(image, h, sz);
case 3
% Create a sinusoidal grating
[x,y] = meshgrid(1:size(image,2), 1:size(image,1));
grating = sin(2*pi*y/32);
% Add sinusoidal grating to the image
noisy = im2double(image) + h*grating;
% Clip the values to [0,1]
noisy(noisy < 0) = 0;
noisy(noisy > 1) = 1;
% Convert back to uint8 format
noisy = im2uint8(noisy);
otherwise
end
end
end
end