-
Notifications
You must be signed in to change notification settings - Fork 5
/
Demo.m
129 lines (102 loc) · 4.31 KB
/
Demo.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
%% This is a simple test for light field ToolBox.
% You can use your own Lytro or Illum devices to decode the lfp
% or lfr files, and further processing color correction and
% frequency domain correction to improve the quality of your images.
% Enjoy it!
% Anthor: Vincent Qin
% Data: 2017.10
%% Begin to enjoy it.
clc;
clear all;
clc;
addpath(genpath('Sample_test'));
addpath(genpath('LFToolbox0.4'));
LFMatlabPathSetup;
%% Step1: Decompress data.C.0/1/2/3---> to get white image data
fprintf('===============Step1: Unpack Lytro Files===============\n\n ');
LFUtilUnpackLytroArchive('Sample_test')
%% Step2: Including the files after decompressing
fprintf('===============Step2: Process WhiteImages===============\n\n');
% your series number:
% lytro: Axxxxxxxxxx
% illum: Bxxxxxxxxxx
WhiteImagesPath='Sample_test\Cameras\Axxxxxxxxxx';
LFUtilProcessWhiteImages( WhiteImagesPath);
%% Step3: Decode your.lfp/.lfr files
tic
fprintf('=====================Step3: Decode LFP===================\n\n');
cd('Sample_test'); % go to Sample_test directory
lfpname='test'; % test file name
if WhiteImagesPath(21)=='A' %if lytro exist('LYTRO','var')
version='F01';
elseif WhiteImagesPath(21)=='B'%if illum exist('ILLUM','var')
version='B01';
end
InputFname=['Images\',version,'\',lfpname,'.lfp'];
[LF, LFMetadata,WhiteImage,CorrectedLensletImage, ...
WhiteImageMetadata, LensletGridModel, DecodeOptions]...
= LFLytroDecodeImage(InputFname);
cd('..');
imshow(CorrectedLensletImage) %Raw Image
mkdir(['Results_saving\',lfpname]);
imwrite(CorrectedLensletImage,['Results_saving\',lfpname,'\',lfpname,'.bmp']);
save(['Results_saving\',lfpname,'\',lfpname,'.mat'],'CorrectedLensletImage');
toc
%% =======================Frequecy domain Correction================================
%---Setup for linear filters---
tic
% lytro
if strcmp(version,'F01')==1
LFPaddedSize = [16, 16, 400, 400];
BW = 0.03;
FiltOptions = [];
FiltOptions.Rolloff = 'Butter';
Slope1 = -3/9; % Lorikeet
Slope2 = 4/9; % Building
fprintf('Building 4D frequency hyperfan... ');
[H, FiltOptionsOut] = LFBuild4DFreqHyperfan( LFPaddedSize, Slope1, Slope2, BW, FiltOptions );
fprintf('Applying filter');
[LFFilt, FiltOptionsOut] = LFFilt4DFFT( LF, H, FiltOptionsOut );
% illum
elseif strcmp(version,'B01')==1
LFSize = size(LF);
LFPaddedSize = LFSize;
BW = 0.04;
FiltOptions = [];
%---Demonstrate 4D Hyperfan filter---
Slope1 = -4/15; % Lorikeet
Slope2 = 15/15; % Far background
fprintf('Building 4D frequency hyperfan... ');
[H, FiltOptionsOut] = LFBuild4DFreqHyperfan( LFPaddedSize, Slope1, Slope2, BW, FiltOptions );
fprintf('Applying filter');
[LFFilt, FiltOptionsOut] = LFFilt4DFFT( LF, H, FiltOptionsOut );
title(sprintf('Frequency hyperfan filter, slopes %.3g, %.3g, BW %.3g', Slope1, Slope2, BW));
drawnow
save(['Results_saving\',lfpname,'\',lfpname,'5D.mat'],'LFFilt');
end
%% ====================Color correction using Gamma correction=====================
ColMatrix = DecodeOptions.ColourMatrix;
Gamma=DecodeOptions.Gamma;
ColBalance=DecodeOptions.ColourBalance;
% processing gamma correction to get one image NOT 5D LF
ColorCorrectedImage=LFColourCorrect(CorrectedLensletImage, ColMatrix, ColBalance, Gamma);
imwrite(ColorCorrectedImage,['Results_saving\',lfpname,'\',lfpname,'ColorCorrectedImage.bmp']);
save(['Results_saving\',lfpname,'\',lfpname,'ColorCorrectedImage.mat'],'ColorCorrectedImage')
imshow(ColorCorrectedImage);title('Corrected Lenslet Image');
%% Color correction to get 5-D LFColorCorrectedImage data
LFColorCorrectedImage=zeros(size(LF,1),size(LF,2),size(LF,3),size(LF,4),size(LF,5));
for i=1:size(LF,1)
for j=1:size(LF,2)
temp =squeeze(LFFilt(i,j,:,:,1:3));
temp = LFColourCorrect(temp, ColMatrix, ColBalance, Gamma);
LFColorCorrectedImage(i,j,:,:,1:3)=temp;
imshow(temp);
pause(0.1)
end
end
LFColorCorrectedImage(:,:,:,:,4)=LF(:,:,:,:,4);
save(['Results_saving\',lfpname,'\',lfpname,'RawLFColorCorrectedImage.mat'],'LFColorCorrectedImage');% very important
%% show your light field image.
ViewLightField(LFColorCorrectedImage(:,:,:,:,1:3));
toc
%--------------------------------------------------------------------------------------------------------------------