forked from xiangyongcao/CNN-AL-MRF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNN_AL_MRF_GenWeit.m
71 lines (61 loc) · 1.95 KB
/
CNN_AL_MRF_GenWeit.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
function CNN_AL_MRF_GenWeit(data, DirHor, DirVer)
BandInd = data.IndBand;
%BandInd = [12,60,180];
if ~isfield(data, 'F_norm')
Feature = data.F;
% normalize
for b=1:length(BandInd)
Feature(:,:,BandInd(b)) = (Feature(:,:,BandInd(b))-min(min(Feature(:,:,BandInd(b)))))./...
(max(max(Feature(:,:,BandInd(b))))-min(min(Feature(:,:,BandInd(b)))));
end
end
Feature = data.F_norm;
HSI_rgb = im2uint8(Feature(:,:,BandInd));
% figure, imshow(HSI_rgb)
H = size(HSI_rgb, 1);
W = size(HSI_rgb, 2);
R = flipud(HSI_rgb(:,:,1)); R = R(1:H,:);R = R(:,1:W);
G = flipud(HSI_rgb(:,:,2)); G = G(1:H,:);G = G(:,1:W);
B = flipud(HSI_rgb(:,:,3)); B = B(1:H,:);B = B(:,1:W);
for i = 2 : H
for j = 2 : W
Dij_left(i-1,j-1) = (abs(R(i,j) - R(i-1,j)))^2;
Dij_up(i-1,j-1) = (abs(R(i,j) - R(i,j-1)))^2;
end
end
var_left = std(double(Dij_left(:)));
var_up = std(double(Dij_up(:)));
HorzWeight1 = exp(-double(Dij_left)/(2*var_left));
VertWeight1 = exp(-double(Dij_up)/(2*var_up));
for i = 2 : H
for j = 2 : W
Dij_left(i-1,j-1) = (abs(G(i,j) - G(i-1,j)))^2;
Dij_up(i-1,j-1) = (abs(G(i,j) - G(i,j-1)))^2;
end
end
var_left = std(double(Dij_left(:)));
var_up = std(double(Dij_up(:)));
HorzWeight2 = exp(-double(Dij_left)/(2*var_left));
VertWeight2 = exp(-double(Dij_up)/(2*var_up));
for i = 2 : H
for j = 2 : W
Dij_left(i-1,j-1) = (abs(B(i,j) - B(i-1,j)))^2;
Dij_up(i-1,j-1) = (abs(B(i,j) - B(i,j-1)))^2;
end
end
var_left = std(double(Dij_left(:)));
var_up = std(double(Dij_up(:)));
HorzWeight3 = exp(-double(Dij_left)/(2*var_left));
VertWeight3 = exp(-double(Dij_up)/(2*var_up));
HorzWeight = real(HorzWeight1+HorzWeight2+HorzWeight3)/3;
VertWeight = real(VertWeight1+VertWeight2+VertWeight3)/3;
% figure;
% mesh(HorzWeight);
% title('HorzWeight');
% axis([1 W 1 H]);
% figure;
% mesh(VertWeight);
% title('VertWeight');
% axis([1 W 1 H]);
save(DirHor, 'HorzWeight', '-ascii');
save(DirVer, 'VertWeight', '-ascii');