-
Notifications
You must be signed in to change notification settings - Fork 3
/
noise_enhancement.m
136 lines (78 loc) · 4.55 KB
/
noise_enhancement.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function [I_blurred, I_noised, I_patney, I_patney_noised, noise_pattern] = noise_enhancement(im_gt,sigMax,gaze_x,gaze_y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%These parameters an be adjusted based on display specifications and technical preferences
screen_gamma = 2.2; %the display gamma
width_pixels = 3840; %pixels for the image, we only use 4K (DO NOT CHANGE THIS)
height_pixels = 2160; %pixels for the image, we only use 4K (DO NOT CHANGE THIS)
e_cutoff = 12; %eccentricity cut-off in degrees
width = 120; %width of the display screen in cm
height = 67; %height of the display screen in cm
field_width = 90; %the total field-of-view the display spans (horizontal)
a_ = 0.08; %Gabor Kernel Size
number_of_impulses_per_kernel = 64.0; %numper of impulses-per-gabor-kernel
attenuation = 0.1; %the attenuation value of spatial frequencies which are deemed preserved for amplitude estimation (default 10%).
noise_amp = 16; %s_k
f_sig = 2.1; %s_f
f_e = 0.2; %tuning parameter for contrast enhancement
period = 256; %gabor noise periodicity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ycbcr_max = 219/255; %for normalization to compensate for MATLAB ycbcr
ycbcr_min = 16/255;
im_gt = imresize(im_gt,[height_pixels width_pixels]); %resize the image to incase it is smaller or larger than 4K
im_gt = double(im_gt)./255;
sz = size(im_gt);
im_gt = gamma_correction(im_gt,screen_gamma,1); %linear color space
ppd = (width_pixels/2)/(field_width/2); %pixels-per-degree
dis = (width/2)/tand(field_width/2);
gaze_x = round(gaze_x*height);
gaze_y = round(gaze_y*width);
x = linspace(0,height,height_pixels);
y = linspace(0,width,width_pixels);
[Y,X] = meshgrid(y,x);
R = sqrt((X-gaze_x).^2 + (Y-gaze_y).^2);
theta_mat = atand(R./dis); %pixel-wise eccentricity map
m = sigMax/(30 - e_cutoff);
c = -m*e_cutoff;
sigma_map = m.*theta_mat + c; %pixel-wise gaussian-blur sigmas to model foveation
sigma_map(sigma_map<=0) = 0;
max_sig = ceil(max(sigma_map(:)))+1;
blurred_maps = zeros(sz(1),sz(2),max_sig+1,3);
patney_maps = zeros(sz(1),sz(2),max_sig+1,3);
blurred_maps(:,:,1,:) = im_gt;
patney_maps(:,:,1,:) = im_gt;
for i = 1:max_sig
blurred_image = imgaussfilt(im_gt,i);
blurred_maps(:,:,i+1,:) = blurred_image;
patney_maps(:,:,i+1,:) = contrast_enhancer(blurred_image,i,f_e);
end
[im_blur] = foveation_simulator(blurred_maps,sigma_map); %foveated image
sz = size(im_blur);
im_blur_ycbcr = rgb2ycbcr(im_blur);
y_channel = im_blur_ycbcr(:,:,1);
cb_channel = im_blur_ycbcr(:,:,2);
cr_channel = im_blur_ycbcr(:,:,3);
[I_patney] = foveation_simulator(patney_maps,sigma_map); %contrast enhanced image
omega_0 = orientation_map(rgb2gray(im_blur)); %gabor orientations
resolution_x = sz(1);
resolution_y = sz(2);
y_channel_normalized = (double(y_channel)-ycbcr_min)./ycbcr_max;
y_channel_rescaled_i8 = (ycbcr_max.*y_channel_normalized + ycbcr_min);
[Fmin, Fmax] = frequency_map(ppd,sigma_map,theta_mat,f_sig); %gabor frequencies
k_map = gabor_amplitude_map(y_channel_normalized,sigma_map,double(rgb2gray(I_patney)),noise_amp,attenuation); %gabor amplitudes
patch = noise_matlab(resolution_x, resolution_y, k_map, a_, Fmin, Fmax, omega_0, number_of_impulses_per_kernel, period); %gabor noise synthesis
patch = (patch-mean2(patch)); %gabor noise normalization
I_blurred = ycbcr2rgb(cat(3,y_channel_rescaled_i8,cb_channel,cr_channel));
new_y_channel = y_channel_normalized + patch;
I_noised = ycbcr2rgb(cat(3,ycbcr_max.*new_y_channel + ycbcr_min,cb_channel,cr_channel));
im_patney_ycbcr = rgb2ycbcr(I_patney);
patney_y_channel = im_patney_ycbcr(:,:,1);
patney_y_channel_normalized = (double(patney_y_channel) - ycbcr_min)./(ycbcr_max);
cb_channel = im_patney_ycbcr(:,:,2);
cr_channel = im_patney_ycbcr(:,:,3);
new_patney_y_channel = patney_y_channel_normalized + patch;
I_patney_noised = ycbcr2rgb(cat(3,(ycbcr_max.*new_patney_y_channel + ycbcr_min),cb_channel,cr_channel));
noise_pattern = patch;
I_patney = uint8(real(255.*gamma_correction(I_patney,screen_gamma,0))); %contrast enhanced image
I_blurred = uint8(255.*gamma_correction(I_blurred,screen_gamma,0)); %foveated image
I_noised = uint8(255.*gamma_correction(I_noised,screen_gamma,0)); %noised foveated image
I_patney_noised = uint8(255.*gamma_correction(I_patney_noised,screen_gamma,0)); %noised contrast enhanced image (final output)