-
Notifications
You must be signed in to change notification settings - Fork 10
/
demo.m
85 lines (62 loc) · 1.81 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
addpath(genpath(pwd));
%% Step 1: load LF data
% if you do not have LF data, please download before.
% uncomment either of the following two lines.
% load 'data/buddha2_LF_data.mat'
% [LF,LF_Remap,IM_Pinhole]=hdf2LF('data/Buddha2.h5');
img = imread('data/your_image.png'); % remap 2D image to 5D LF image
views=[4,4]; % [NOTE]: angular resolution of your image
LF = Remap2LF(img,views);
LF=mat2gray(LF);
ViewLightField(LF);
[vN,uN,h,w,ch]=size(LF);
%% Step 2: Horizontal EPI (fix v & y)
y_=490;
v_=4;
% EPI line in central-sub-view image
figure;
img=squeeze(LF(views(1)/2+1,views(2)/2+1,:,:,:));
imshow(img,'border','tight','initialmagnification','fit');
axis normal;
truesize;
line([1 w],[y_ y_],'color','r','linewidth',5);
set(gcf,'color',[1 1 1]);axis equal;
% saveas(gca,'buddha2_epi_line.jpg','jpg');
% draw EPI
figure;
imagesc(squeeze(LF(v_,:,y_,:,:)));
% set(gca,'position',[0.1 0.1,0.8 0.8])
set(gcf,'pos',[421,298,966,152])
set(gcf,'color',[1 1 1]);
set(gca,'xtick',[],'ytick',[]);
hold off
% saveas(gcf,'buddha2_epi.jpg');
%% Step 3: Vertical EPI (fix u & x)
x_=500;
u_=4;
% EPI line in central-sub-view image
figure;
img=squeeze(LF(views(1)/2+1,views(2)/2+1,:,:,:));
imshow(img,'border','tight','initialmagnification','fit');
axis normal
truesize
line([x_ x_],[h 1],'color','g','linewidth',5);
set(gcf,'color',[1 1 1]);axis equal
% draw EPI
figure;
imagesc(permute(squeeze(LF(:,u_,:,x_,:)),[2 1 3]));
% set(gca,'position',[0.1 0.1,0.8 0.8])
set(gcf,'pos',[582 -14 159 818])
set(gcf,'color',[1 1 1]);
set(gca,'xtick',[],'ytick',[]);
hold off
%saveas(gcf,'buddha2_epi.jpg');
%% Step 4: Show Angular Patches(AP)
% pos is the coordinates in central view
% result image is the corresponding AP in light field.
pos=[477 500];
ImshowAP(pos,views,LF)
pos=[600 265];
ImshowAP(pos,views,LF)
pos=[458 55];
ImshowAP(pos,views,LF)