forked from robotVisionHang/Image_Fusion_Evaluation_ToolBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metricChenBlum.m
160 lines (115 loc) · 2.85 KB
/
metricChenBlum.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
function res=metricChenBlum(im1,im2,fim)
% function res=metricChenBlum(im1,im2,fim)
%
% This function implements Yin Chen's algorithm for fusion metric.
% im1, im2 -- input images;
% fim -- fused image;
% res -- metric value;
%
% IMPORTANT: The size of the images need to be 2X.
% See also: evalu_fusion.m
%
% Z. Liu [July 2009]
%
% Ref: A new automated quality assessment algorithm for image fusion, Image and Vision Computing, 27 (2009) 1421-1432
% By Yin Chen et al.
%
%% pre-processing
%im1=double(im1);
%im2=double(im2);
%fim=double(fim);
im1 = im2double(im1);
im2 = im2double(im2);
fim = im2double(fim);
im1=normalize1(im1);
im2=normalize1(im2);
fim=normalize1(fim);
%% set up some constant values for experiment
f0=15.3870;
f1=1.3456;
a=0.7622;
% parameters for local constrast computation
k=1;
h=1;
p=3; %2.4;
%p=2.4;
q=2;
Z=0.0001;
sigma=2;
%% caculate the quality Q
[hang,lie]=size(im1);
%DoG filter
%DoG1
%HH=hang/2; LL=lie/2;
HH=hang/30; LL=lie/30;
%DoG2
%HH=hang/4; LL=lie/4;
%DoG3
%HH=hang/8; LL=lie/8;
[u,v]=freqspace([hang,lie],'meshgrid');
u=LL*u; v=HH*v;
r=sqrt(u.^2+v.^2);
Sd=exp(-(r/f0).^2)-a*exp(-(r/f1).^2);
% constrast sensitivity filtering
fim1=ifft2(ifftshift(fftshift(fft2(im1)).*Sd));
fim2=ifft2(ifftshift(fftshift(fft2(im2)).*Sd));
ffim=ifft2(ifftshift(fftshift(fft2(fim)).*Sd));
%--------------------
%fim1=normalize1(fim1);
%fim2=normalize1(fim2);
%ffim=normalize1(ffim);
% local contrast computation
% one level of contrast
G1=gaussian2d(hang,lie,2);
G2=gaussian2d(hang,lie,4);
% filtering in frequency domain
C1=contrast(G1,G2,fim1);
C1=abs(C1); % I add this. (see your notes)
C1P=(k*(C1.^p))./(h*(C1.^q)+Z);
C2=contrast(G1,G2,fim2);
C2=abs(C2); % I add this.
C2P=(k*(C2.^p))./(h*(C2.^q)+Z);
Cf=contrast(G1,G2,ffim);
Cf=abs(Cf); % I add this.
CfP=(k*(Cf.^p))./(h*(Cf.^q)+Z);
% contrast preservation calculation
mask=(C1P<CfP);
mask=double(mask);
Q1F=(C1P./CfP).*mask+(CfP./C1P).*(1-mask);
mask=(C2P<CfP);
mask=double(mask);
Q2F=(C2P./CfP).*mask+(CfP./C2P).*(1-mask);
% Saliency map generation
ramda1=(C1P.*C1P)./(C1P.*C1P+C2P.*C2P);
ramda2=(C2P.*C2P)./(C1P.*C1P+C2P.*C2P);
% global quality map
Q=ramda1.*Q1F+ramda2.*Q2F;
res=mean2(Q);
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% sub-functions
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res=gaussian2d(n1,n2,sigma)
% creat a 2D Gaussian filter in spatial domain
%
% hang (H)-> y; lie (L) -> x
H=floor((n1-1)/2);
L=floor((n2-1)/2);
[x,y]=meshgrid(-15:15,-15:15);
G=exp(-(x.*x+y.*y)/(2*sigma*sigma))/(2*pi*sigma*sigma);
%This is to normalize
%G=G/sum(G(:));
res=G;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res=contrast(G1,G2,im)
%[hang,lie]=size(im);
%FG1=fft2(G1,hang,lie);
%FG2=fft2(G2,hang,lie);
%Fim=fft2(im);
%buff=real(ifft2(FG1.*Fim));
%buff1=real(ifft2(FG2.*Fim));
buff=filter2(G1,im,'same');
buff1=filter2(G2,im,'same');
res=buff./buff1-1;