-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecision_function.m
More file actions
62 lines (50 loc) · 1.94 KB
/
Copy pathdecision_function.m
File metadata and controls
62 lines (50 loc) · 1.94 KB
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
function nsim_score = compute_nsim(neurogram_ref, neurogram_degraded, C1, C2)
% Compute the neurogram similarity index measure (NSIM).
if nargin < 3
C1 = 0.01;
end
if nargin < 4
C2 = 0.03;
end
neurogram_ref = normalize(neurogram_ref);
neurogram_degraded = normalize(neurogram_degraded);
mu_r = mean(neurogram_ref(:));
mu_d = mean(neurogram_degraded(:));
sigma_r = var(neurogram_ref(:)) + 1e-10;
sigma_d = var(neurogram_degraded(:)) + 1e-10;
sigma_rd = cov(neurogram_ref(:), neurogram_degraded(:));
sigma_rd = sigma_rd(1, 2);
% Check if variances are zero and handle the edge case
if sigma_r <= 1e-10 && sigma_d <= 1e-10
nsim_score = 0;
return;
end
% Compute luminance term
luminance = (2 * mu_r * mu_d + C1) / (mu_r^2 + mu_d^2 + C1);
% Compute contrast term
contrast = (sigma_rd + C2) / (sqrt(sigma_r * sigma_d) + C2);
nsim_score = luminance * contrast;
% Clamp the NSIM score to the range [0, 1] to avoid slight deviations above 1
nsim_score = min(max(nsim_score, 0), 1);
end
function normalized_neurogram = normalize(neurogram)
% Normalize the neurogram to the range [0, 1].
min_val = min(neurogram(:));
max_val = max(neurogram(:));
if max_val - min_val == 0
normalized_neurogram = zeros(size(neurogram));
else
normalized_neurogram = (neurogram - min_val) / (max_val - min_val);
end
end
% Example usage
neurogram_ref = rand(100, 50); % example reference neurogram
neurogram_degraded = rand(100, 50); % example degraded neurogram
% compute NSIM score
nsim_score = compute_nsim(neurogram_ref, neurogram_degraded);
fprintf('NSIM Score: %.4f\n', nsim_score);
% Example usage
neurogram_ref = ones(100, 50);
neurogram_degraded = zeros(100, 50);
nsim_score = compute_nsim(neurogram_ref, neurogram_degraded);
fprintf('NSIM Score: %.4f\n', nsim_score);