-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.m
115 lines (86 loc) · 3.31 KB
/
main.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
%¡¶Enhancing Underwater Images and Videos by Fusion¡· code
clc;
clear all;
close all;
path = "./images/6.jpg";
image = imread(path);
figure,imshow(image),title("origin image");
tic;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% deal with input image for fusion
% input1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img1 = simple_color_balance(image);
lab1 = rgb_to_lab(img1); %rgb change to lab
figure,subplot(1,2,1),imshow(img1),title("imupt1 image");
% input2
lab2 = lab1;
% bilateralFilter deal with luminance channel
lab2(:, :, 1) = uint8(bilateralFilter(double(lab2(:, :, 1))));
%lab2(:, :, 1) = uint8(guidedfilter(double(rgb2gray(image)),double(lab2(:, :, 1)), 15*4, 10^-6) );
% adaptive histogram equalization
lab2(:, :, 1) = adapthisteq(lab2(:, :, 1));
img2 = lab_to_rgb(lab2);
subplot(1,2,2),imshow(img2),title("imupt2 image");
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calculate weight
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R1 = double(lab1(:, :, 1)/255);
R2 = double(lab2(:, :, 1)/255);
%1. Laplacian contrast weight (Laplacian filiter on input luminance channel)
WL1 = abs(imfilter(R1, fspecial('Laplacian'), 'replicate', 'conv'));
WL2 = abs(imfilter(R2, fspecial('Laplacian'), 'replicate', 'conv'));
% 2. Local contrast weight
h = 1/16 * [1, 4, 6, 4, 1];
whc = pi / 2.75; % high frequency cut-off value
WLC1 = imfilter(R1, h' * h, 'replicate', 'conv');
WLC1(find(WLC1 > whc)) = whc;
WLC1 = (R1 - WLC1).^2;
WLC2 = imfilter(R2, h' * h, 'replicate', 'conv');
WLC2(find(WLC2 > whc)) = whc;
WLC2 = (R2 - WLC2).^2;
% 3. Saliency weight
WS1 = saliency_detection(img1);
WS2 = saliency_detection(img2);
% 4. Exposedness weight
average = 0.5;
sigma = 0.25;
WE1 = exp(-(R1 - average).^2 / (2 * sigma^2));
WE2 = exp(-(R2 - average).^2 / (2 * sigma^2));
% normalized weight
W1 = (WL1 + WLC1 + WS1 + WE1) ./ (WL1 + WLC1 + WS1 + WE1 + WL2 + WLC2 + WS2 + WE2);
W2 = (WL2 + WLC2 + WS2 + WE2) ./ (WL1 + WLC1 + WS1 + WE1 + WL2 + WLC2 + WS2 + WE2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% image fusion
% R(x,y) = sum G{W} * L{I}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
level = 5;
% weight gaussian pyramid
Weight1 = gaussian_pyramid(W1, level);
Weight2 = gaussian_pyramid(W2, level);
% image laplacian pyramid
% input1
r1 = laplacian_pyramid(double(double(img1(:, :, 1))), level);
g1 = laplacian_pyramid(double(double(img1(:, :, 2))), level);
b1 = laplacian_pyramid(double(double(img1(:, :, 3))), level);
% input2
r2 = laplacian_pyramid(double(double(img2(:, :, 1))), level);
g2 = laplacian_pyramid(double(double(img2(:, :, 2))), level);
b2 = laplacian_pyramid(double(double(img2(:, :, 3))), level);
% fusion
for i = 1 : level
R_r{i} = Weight1{i} .* r1{i} + Weight2{i} .* r2{i};
G_g{i} = Weight1{i} .* g1{i} + Weight2{i} .* g2{i};
B_b{i} = Weight1{i} .* b1{i} + Weight2{i} .* b2{i};
end
% pyramin reconstruct
R = pyramid_reconstruct(R_r);
G = pyramid_reconstruct(G_g);
B = pyramid_reconstruct(B_b);
fusion = cat(3, uint8(R), uint8(G),uint8(B));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uciqe = UCIQE(fusion)
toc;
figure,imshow(fusion),title("fusion image");