├── README.md
├── data
└── PUT-YOUR-DATA-HERE
├── demo.m
├── results
├── all_views.gif
├── bigimg-1.jpg
├── buhhda2-ap-zoom.png
├── epi_h.jpg
└── epi_v.jpg
└── src
├── Allviews2Remap.m
├── ComputEPI.m
├── ImshowAP.m
├── LF2Remap.m
├── Make4DLF.m
├── Mat2LF.m
├── Refocus2Gif.m
├── Remap2LF.m
├── RescaleImg.m
├── ViewLightField.m
├── View_Generator.m
├── ZoomIm.m
└── hdf2LF.m
/README.md:
--------------------------------------------------------------------------------
1 | # Lightfield-processing
2 |
3 | This is an useful tool to decode lightfield files(.lfp) and process the raw images in to 5D data. You can simplely run [`demo.m`](demo.m) step by step to see the results.
4 |
5 | You should download lightfield data to [data](./data/) folder, I uploaded Wanner HCI datasets to [Google Drive](https://drive.google.com/drive/folders/1epj7GTDlCYTnlnG-TCvPmISBbBcWEhB4?usp=sharing).
6 |
7 | # Just one step
8 |
9 | just run [demo.m](demo.m), you will get everything.
10 |
11 | # Step by step
12 |
13 | ## Step 1: load LF data
14 |
15 | Once you have run `ViewLightField`, you will get the following wonderful images.
16 |
17 |
18 |
19 | 
20 |
21 | ## Step 2: Horizontal EPI (fix v & y)
22 |
23 | 
24 |
25 |
26 | ## Step 3: Vertical EPI (fix u & x)
27 |
28 | 
29 |
30 |
31 |
32 | ## Step 4: Show Angular Patches(AP)
33 |
34 | 
35 |
--------------------------------------------------------------------------------
/data/PUT-YOUR-DATA-HERE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vincentqyw/light-field-Processing/00515d3df03a6745ade901f1d84cff1b60643dde/data/PUT-YOUR-DATA-HERE
--------------------------------------------------------------------------------
/demo.m:
--------------------------------------------------------------------------------
1 | addpath(genpath(pwd));
2 |
3 |
4 | %% Step 1: load LF data
5 | % if you do not have LF data, please download before.
6 |
7 | % uncomment either of the following two lines.
8 | % load 'data/buddha2_LF_data.mat'
9 | % [LF,LF_Remap,IM_Pinhole]=hdf2LF('data/Buddha2.h5');
10 |
11 | img = imread('data/your_image.png'); % remap 2D image to 5D LF image
12 |
13 | views=[4,4]; % [NOTE]: angular resolution of your image
14 |
15 | LF = Remap2LF(img,views);
16 |
17 | LF=mat2gray(LF);
18 | ViewLightField(LF);
19 |
20 |
21 | [vN,uN,h,w,ch]=size(LF);
22 |
23 | %% Step 2: Horizontal EPI (fix v & y)
24 |
25 | y_=490;
26 | v_=4;
27 |
28 | % EPI line in central-sub-view image
29 | figure;
30 | img=squeeze(LF(views(1)/2+1,views(2)/2+1,:,:,:));
31 | imshow(img,'border','tight','initialmagnification','fit');
32 | axis normal;
33 | truesize;
34 | line([1 w],[y_ y_],'color','r','linewidth',5);
35 | set(gcf,'color',[1 1 1]);axis equal;
36 | % saveas(gca,'buddha2_epi_line.jpg','jpg');
37 |
38 | % draw EPI
39 | figure;
40 | imagesc(squeeze(LF(v_,:,y_,:,:)));
41 | % set(gca,'position',[0.1 0.1,0.8 0.8])
42 | set(gcf,'pos',[421,298,966,152])
43 | set(gcf,'color',[1 1 1]);
44 | set(gca,'xtick',[],'ytick',[]);
45 | hold off
46 |
47 | % saveas(gcf,'buddha2_epi.jpg');
48 |
49 | %% Step 3: Vertical EPI (fix u & x)
50 |
51 | x_=500;
52 | u_=4;
53 |
54 | % EPI line in central-sub-view image
55 | figure;
56 | img=squeeze(LF(views(1)/2+1,views(2)/2+1,:,:,:));
57 | imshow(img,'border','tight','initialmagnification','fit');
58 | axis normal
59 | truesize
60 | line([x_ x_],[h 1],'color','g','linewidth',5);
61 | set(gcf,'color',[1 1 1]);axis equal
62 |
63 | % draw EPI
64 | figure;
65 | imagesc(permute(squeeze(LF(:,u_,:,x_,:)),[2 1 3]));
66 | % set(gca,'position',[0.1 0.1,0.8 0.8])
67 | set(gcf,'pos',[582 -14 159 818])
68 | set(gcf,'color',[1 1 1]);
69 | set(gca,'xtick',[],'ytick',[]);
70 | hold off
71 |
72 | %saveas(gcf,'buddha2_epi.jpg');
73 |
74 | %% Step 4: Show Angular Patches(AP)
75 |
76 | % pos is the coordinates in central view
77 | % result image is the corresponding AP in light field.
78 | pos=[477 500];
79 | ImshowAP(pos,views,LF)
80 |
81 | pos=[600 265];
82 | ImshowAP(pos,views,LF)
83 |
84 | pos=[458 55];
85 | ImshowAP(pos,views,LF)
86 |
--------------------------------------------------------------------------------
/results/all_views.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vincentqyw/light-field-Processing/00515d3df03a6745ade901f1d84cff1b60643dde/results/all_views.gif
--------------------------------------------------------------------------------
/results/bigimg-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vincentqyw/light-field-Processing/00515d3df03a6745ade901f1d84cff1b60643dde/results/bigimg-1.jpg
--------------------------------------------------------------------------------
/results/buhhda2-ap-zoom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vincentqyw/light-field-Processing/00515d3df03a6745ade901f1d84cff1b60643dde/results/buhhda2-ap-zoom.png
--------------------------------------------------------------------------------
/results/epi_h.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vincentqyw/light-field-Processing/00515d3df03a6745ade901f1d84cff1b60643dde/results/epi_h.jpg
--------------------------------------------------------------------------------
/results/epi_v.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vincentqyw/light-field-Processing/00515d3df03a6745ade901f1d84cff1b60643dde/results/epi_v.jpg
--------------------------------------------------------------------------------
/src/Allviews2Remap.m:
--------------------------------------------------------------------------------
1 |
2 |
3 | function Allviews2Remap(filepath,LF_parameters,ext)
4 |
5 | % 本函数将所有视角的图像拼接成原始Remap图像
6 | % 输入是包含所有视角的文件夹
7 | % 例如:
8 | % filepath='input_vincent\Mat';
9 | % ext='mat';
10 |
11 | addpath(filepath);
12 | list = dir(fullfile([filepath,'\*.',ext])) ;
13 | N = sqrt(size(list,1));
14 | x_size = LF_parameters.x_size ;
15 | y_size = LF_parameters.y_size ;
16 | UV_diameter = LF_parameters.UV_diameter ;
17 |
18 |
19 | % 重构之后的Remap图像
20 | Remap_Construct=zeros(y_size*UV_diameter,x_size*UV_diameter,3);
21 |
22 | for i=1:UV_diameter
23 | for j=1:UV_diameter
24 |
25 | n = sub2ind([N,N],j,i);
26 | filename = [filepath, '\', list(n).name];
27 | if strcmp(ext,'jpg')||strcmp(ext,'jpeg')||strcmp(ext,'tif')...
28 | ||strcmp(ext,'png')||strcmp(ext,'bmp')
29 | I_temp = double(imread(filename));
30 | elseif ext=='mat'
31 | I_temp = load(filename);
32 | I_temp=I_temp.data; %与View_Generator配合使用
33 | end
34 |
35 | Remap_Construct(i:UV_diameter:y_size*UV_diameter,...
36 | j:UV_diameter:x_size*UV_diameter,:)=I_temp;
37 |
38 | end
39 | end
40 |
41 | % imshow(Remap_Construct/max(max(Remap_Construct(:,:,1))));
42 | imwrite(Remap_Construct/max(max(Remap_Construct(:,:,1))),'CAR_REMAP.png');
43 |
44 |
45 |
--------------------------------------------------------------------------------
/src/ComputEPI.m:
--------------------------------------------------------------------------------
1 | function EPI_New=ComputEPI(filepath)
2 | % filepath包含49个视角的图像!
3 |
4 | list = dir(fullfile([filepath,'\*.','jpg']));
5 |
6 | N = sqrt(size(list,1));
7 |
8 | [R, C, CH] = size(imread([filepath,'\',list(1).name]));
9 |
10 | LF_EPI=zeros(R,N*N,C,CH);
11 | EPI_New=zeros(N,N,R,C,CH);%EPI(t,y,N,C,CH)
12 |
13 | for i=1:N*N
14 | file = [filepath, '\', list(i).name];
15 | I_temp = imread(file);
16 | temp_{i}=double(I_temp);
17 | end
18 |
19 | temp_1=cell2mat(temp_);
20 |
21 |
22 | % for k=1:R
23 | %
24 | % t1=reshape(temp_1(k,:,:),[C,N*N,CH]);
25 | % LF_EPI(k,:,:,:)=permute(t1,[2,1,3])/255;
26 | % imshow(squeeze(LF_EPI(k,:,:,:)));
27 | % title(['EPI slice row=',num2str(k)]);
28 | % pause(0.01)
29 | % end% all views
30 |
31 | for m=1:N
32 | for k=1:R %y
33 | t1=squeeze(temp_1(k,:,:));
34 | for j=1:N %t
35 | t2=t1((j-1)*C+1:(j*C),:);
36 | EPI_New(m,j,k,:,1)=t2(:,1)';
37 | EPI_New(m,j,k,:,2)=t2(:,2)';
38 | EPI_New(m,j,k,:,3)=t2(:,3)';
39 | end
40 | imshow(squeeze(EPI_New(m,:,k,:,:))/373);
41 | title(['EPI when t=',num2str(m),', y= ',num2str(k)]);
42 |
43 | pause(0.01)
44 | end
45 | end
46 |
47 | imshow(IM_Pinhole)
48 | line([1 317],[100 100],'color','r','LineWidth',2);
49 | line([1 317],[140 140],'color','b','LineWidth',2);
50 | line([1 317],[200 200],'color','g','LineWidth',2);
--------------------------------------------------------------------------------
/src/ImshowAP.m:
--------------------------------------------------------------------------------
1 | function ImshowAP(pos,views,LF)
2 | % close all;
3 |
4 | x_=pos(2);
5 | y_=pos(1);
6 |
7 |
8 | figure;
9 | img=squeeze(LF(views(1)/2+1,views(2)/2+1,:,:,:));
10 | imshow(img,'border','tight','initialmagnification','fit');
11 | hold on;plot(pos(1),pos(2),'r.','Markersize',20);
12 | axis normal;
13 | truesize;
14 |
15 |
16 | h=figure ;
17 | small_im=(squeeze(LF(:,:,x_,y_,:)));
18 | imagesc(small_im);
19 | axis equal
20 | axis off
21 | set(gcf,'color',[1 1 1]);
22 | set(gca,'xtick',[],'ytick',[]);
23 | set(0,'DefaultFigureMenu','figure');
24 | set(h,'Position',[500,200,800,500])
25 |
--------------------------------------------------------------------------------
/src/LF2Remap.m:
--------------------------------------------------------------------------------
1 | function Remap_Construct=LF2Remap(LF,win_begin)
2 |
3 | if exist('win_begin','var')
4 | win_begin=1;
5 | end
6 |
7 | LF=LF(:,:,:,:,1:3);
8 | [UV_diameter,~,y_size,x_size,c]=size(LF);
9 |
10 | win_end=UV_diameter-win_begin+1;
11 | step=UV_diameter-2*(win_begin-1); % 窗口实际大小
12 | Remap_Construct=zeros(y_size*step,x_size*step,3);
13 |
14 | %% 裁剪窗口大小变成:(N-win_begin)*(N-win_begin)
15 | % 若win_begin=1时,相当于取整个窗口
16 |
17 |
18 | for i=win_begin:win_end
19 | for j=win_begin:win_end
20 |
21 | view=squeeze(LF(i,j,:,:,1:3));
22 | imshow(view);
23 | pause(eps);
24 | hold off;
25 | Remap_Construct((i-win_begin+1):step:x_size*step,...
26 | (j-win_begin+1):step:y_size*step,:)=view;
27 | end
28 | end
29 | imshow(mat2gray(Remap_Construct));
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/Make4DLF.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | % Jinsun Park (zzangjinsun@gmail.com / zzangjinsun@kaist.ac.kr)
3 | % Computer Vision and Image Processing Lab, KAIST, KOREA
4 | %
5 | % Accurate Depth Map Estimation from a Lenslet Light Field Camera
6 | % Hae-Gon Jeon, Jaesik Park, Gyeongmin Choe, Jinsun Park, Yunsu Bok, Yu-Wing Tai and In So Kweon
7 | % IEEE International Conference on Computer Vision and Pattern Recognition (CVPR), Jun 2015
8 | %
9 | % Name : Make4DLF
10 | % Input : filepath - image file path
11 | % ext - extension of image file (e.g. 'png')
12 | % Output : LF - light field image
13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 | function LF = Make4DLF(filepath, ext)
15 | % Get image list
16 | list = dir(fullfile([filepath,'\*.',ext]));
17 |
18 | N = sqrt(size(list,1));
19 |
20 | [R, C, CH] = size(imread([filepath,'\',list(1).name]));
21 |
22 | LF = zeros(N,N,R,C,CH);
23 |
24 | for i=1:N
25 | for j=1:N
26 | n = sub2ind([N,N],j,i);
27 |
28 | filename = [filepath, '\', list(n).name];
29 |
30 | I_temp = imread(filename);
31 |
32 | I_temp = double(I_temp);
33 |
34 | LF(i,j,:,:,:) = I_temp;
35 | end
36 | end
37 |
38 | return;
39 |
40 |
--------------------------------------------------------------------------------
/src/Mat2LF.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | %Read .mat to LF data
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 | function LF = Mat2LF(filepath)
5 | % Get image list
6 |
7 | list = dir(fullfile([filepath,'\*.','mat']));
8 | N = sqrt(size(list,1));
9 | temp=load([filepath,'\',list(1).name]);
10 | temp=temp.data;
11 | [R, C, CH] = size(temp);
12 | LF = zeros(N,N,R,C,CH);
13 |
14 | for i=1:N
15 | for j=1:N
16 | n = sub2ind([N,N],j,i);
17 | filename = [filepath, '\', list(n).name];
18 |
19 | I_temp = load(filename);
20 | I_temp = I_temp.data;
21 | LF(i,j,:,:,:) = I_temp; % 按照行读
22 | end
23 | end
24 |
25 | return;
26 |
27 |
--------------------------------------------------------------------------------
/src/Refocus2Gif.m:
--------------------------------------------------------------------------------
1 | function res=Refocus2Gif(name,FilePath,dt)
2 |
3 | cd(FilePath);
4 | cut=40;
5 | for i=cut:257
6 |
7 | pathimg=['IM_Refoc_alpha_',num2str(i),'.jpg'];
8 | img=imread(pathimg);
9 | imshow(img,'border','tight','initialmagnification','fit');
10 | axis normal
11 | truesize
12 | % text(10,20,sprintf('i : %d',i),'fontsize',20,'color','y');
13 |
14 | %======Creat GIF =======
15 | n=i-cut+1;
16 | frame(n)=getframe(gcf); % get the frame
17 | image=frame(n).cdata;
18 | [image,map] = rgb2ind(image,256);
19 | if n==1
20 | imwrite(image,map,name,'gif');
21 | else
22 | imwrite(image,map,name,'gif','WriteMode','append','DelayTime',dt);
23 | end
24 | %------------------------------------
25 |
26 | end
27 | cd('..');
28 |
29 |
--------------------------------------------------------------------------------
/src/Remap2LF.m:
--------------------------------------------------------------------------------
1 |
2 | function LF=Remap2LF(Remap,views)
3 |
4 | [height, width,~]=size(Remap);
5 |
6 | % ImLittle=zeros(height/view(1),width/view(2),3);
7 |
8 | LF=zeros(views(1),views(2),height/views(1),width/views(2),3);
9 |
10 | for i=1:views(1)
11 | for j=1:views(2)
12 |
13 | ImLittle=Remap(i:views(1):height,j:views(2):width,:);
14 | LF(i,j,:,:,:)=ImLittle;
15 | end
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/src/RescaleImg.m:
--------------------------------------------------------------------------------
1 |
2 | function Res=RescaleImg(LF)
3 |
4 | %---Rescale for 8-bit display---
5 | if( isfloat(LF) )
6 | Res = uint8(LF ./ max(LF(:)) .* 255);
7 | else
8 | Res = uint8(LF.*(255 / double(intmax(class(LF)))));
9 | end
--------------------------------------------------------------------------------
/src/ViewLightField.m:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | % 2018.06.01 Vincent qin
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 |
5 | % function fn_ViewLightField
6 |
7 | % input : 5D light field image structure (t,s,y,x,ch),
8 | % single type pixel intensities.
9 |
10 | function ViewLightField(LF)
11 |
12 | fprintf('ViewLightField...');
13 | save_gif = 1;
14 | out_name = 'all_views';
15 | dt=0.3;
16 |
17 | ns = size(LF,1);
18 | nt = size(LF,2);
19 | h = size(LF,3);
20 | w = size(LF,4);
21 |
22 | % keyboard;
23 |
24 | bigimg = zeros(h*nt,w*ns,3);
25 | cnt=1;
26 | for t=1:nt
27 | ts = (t-1)*h+1;
28 | te = t*h;
29 | for s=1:ns
30 | ss = (s-1)*w+1;
31 | se = s*w;
32 | img = squeeze(LF(t,s,:,:,:));
33 | % bigimg(ts:te,ss:se,:) = img;
34 | bigimg(ts:te,ss:se,1) = img(:,:,1);
35 | bigimg(ts:te,ss:se,2) = img(:,:,2);
36 | bigimg(ts:te,ss:se,3) = img(:,:,3);
37 |
38 | figure(1); imshow(img,'border','tight','initialmagnification','fit');
39 | axis normal;
40 | truesize;
41 | % set(gcf,'pos',[727 298 338 338]);
42 | text(10,30,sprintf('u : %d, v : %d',s,t),'fontsize',20,'color','y');
43 | if save_gif==1
44 | n=cnt;
45 | frame(n)=getframe(gcf); % get the frame
46 | image=frame(n).cdata;
47 | [image,map] = rgb2ind(image,256);
48 | if n==1
49 | % imwrite(image,map,outname,'gif');
50 | imwrite(image,map,[out_name '.gif'],'gif','Loopcount',inf);
51 | else
52 | imwrite(image,map,[out_name '.gif'],'WriteMode','append','DelayTime',0.2);
53 | end
54 | end
55 | % title(sprintf('u : %d, v : %d',s,t));
56 | pause(0.05);
57 | cnt = cnt + 1;
58 | end
59 | end
60 |
61 | % bigimg = imresize(bigimg);
62 | figure; imshow(bigimg);
63 | imwrite(bigimg,'bigimg.jpg','jpg');
64 | fprintf('View Light Field done.\n');
65 |
--------------------------------------------------------------------------------
/src/View_Generator.m:
--------------------------------------------------------------------------------
1 | function View_Generator(inpath,outpath,LF_parameters,ext)
2 | % inpath 输入图像的路径
3 | % outpath保存路径
4 | % ext 保存文件的格式
5 |
6 | % Img=imread('LF_Remap.jpg');
7 | % mkdir('input_vincent\Mat');
8 |
9 |
10 | tic
11 | Img=imread(inpath);
12 | mkdir([outpath,'\',ext]);
13 |
14 | x_size = LF_parameters.x_size ;
15 | y_size = LF_parameters.y_size ;
16 | data=zeros(y_size,x_size,3);
17 | windowside=LF_parameters.UV_diameter;
18 |
19 | for i = 1:LF_parameters.UV_diameter
20 | for j = 1:LF_parameters.UV_diameter
21 | % view_num=j+(i-1)*LF_parameters.UV_diameter;%对窗口编号
22 | for x=1:LF_parameters.x_size%row
23 | for y=1:LF_parameters.y_size%col
24 |
25 | xx=i+(x-1)*windowside;
26 | yy=j+(y-1)*windowside;
27 | data(y,x,:)=Img(yy,xx,:);
28 | end
29 | end
30 |
31 | filename=[outpath,'\',ext,'\view_' num2str(j),'_',num2str(i), '.',ext];%
32 | %
33 | if strcmp(ext,'mat')
34 | save(filename,'data')
35 | else
36 | imwrite(mat2gray(data),filename,ext);%
37 | end
38 |
39 | end
40 | end
41 |
42 | fprintf('View_Generator Done in %.3f seconds!\n',toc);
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/ZoomIm.m:
--------------------------------------------------------------------------------
1 | function ZoomIm(im,pos)
2 |
3 | % figure
4 | % im=IM_Pinhole;pos=[44,65,67,76];
5 |
6 | up_leftX=pos(1);
7 | up_leftY=pos(2);
8 | down_rightX=pos(3);
9 | down_rightY=pos(4);
10 |
11 | imshow(im);set(gcf,'color',[1 1 1]);
12 | line([up_leftX, down_rightX] ,[up_leftY ,up_leftY],'linestyle','-','linewidth',3,'color','r');
13 | line([up_leftX, up_leftX] ,[up_leftY ,down_rightY],'linestyle','-','linewidth',3,'color','r');
14 | line([down_rightX, down_rightX],[up_leftY ,down_rightY],'linestyle','-','linewidth',3,'color','r');
15 | line([up_leftX, down_rightX] ,[down_rightY,down_rightY],'linestyle','-','linewidth',3,'color','r');
16 |
17 | h=figure;
18 | % imshow(im)
19 |
20 | small_im=im(up_leftY:down_rightY,up_leftX:down_rightX,:);
21 | imagesc(small_im);
22 | axis equal
23 | axis off
24 | set(gcf,'color',[1 1 1]);
25 | set(gca,'xtick',[],'ytick',[]);
26 | % set(gca,'position',[0.1 0.1,0.8 0.8])
27 |
28 | set(h,'Position',[500,200,800,500])
--------------------------------------------------------------------------------
/src/hdf2LF.m:
--------------------------------------------------------------------------------
1 | function [LF,LF_Remap,IM_Pinhole]=hdf2LF(file_path)
2 |
3 | %% preprocessing to get LF_REMAP and IM_Pinhole
4 |
5 | [pathstr,name,ext] = fileparts([file_path]);
6 | idx=strfind(name,'_LF_Remap');
7 | name=name(1:idx-1);
8 |
9 | hinfo_data = hdf5info(file_path);
10 | if strcmp('rx_watch',name)
11 | groundtruth = hdf5read(file_path,'/Depth');
12 | else
13 | groundtruth = hdf5read(file_path,'/GT_DEPTH');
14 | end
15 | % LF_temp = hdf5read(input_string,'/LF');
16 |
17 | if strcmp(file_path,'Cube') || strcmp(file_path,'Couple')
18 | data = hdf5read(hinfo_data.GroupHierarchy.Datasets(3));
19 | else
20 | data = hdf5read(hinfo_data.GroupHierarchy.Datasets(2));
21 | end
22 |
23 | use_decode=1;
24 |
25 | if use_decode
26 | idx_size = max(size(hinfo_data.GroupHierarchy.Attributes));
27 | shortname = cell(idx_size,1);
28 | for ids = 1:idx_size
29 | shortname{ids} = hinfo_data.GroupHierarchy.Attributes(ids).Shortname;
30 | end
31 |
32 | indexcell = strfind(shortname, 'dH');
33 | dH_id = find(not(cellfun('isempty', indexcell)));
34 | indexcell = strfind(shortname, 'focalLength');
35 | focalLength_id = find(not(cellfun('isempty', indexcell)));
36 | indexcell = strfind(shortname, 'shift');
37 | shift_id = find(not(cellfun('isempty', indexcell)));
38 | indexcell = strfind(shortname, 'xRes');
39 | xRes_id = find(not(cellfun('isempty', indexcell)));
40 | indexcell = strfind(shortname, 'yRes');
41 | yRes_id = find(not(cellfun('isempty', indexcell)));
42 | indexcell = strfind(shortname, 'hRes');
43 | hRes_id = find(not(cellfun('isempty', indexcell)));
44 | indexcell = strfind(shortname, 'vRes');
45 | vRes_id = find(not(cellfun('isempty', indexcell)));
46 |
47 | dH = hinfo_data.GroupHierarchy.Attributes(dH_id).Value;
48 | focalLength = hinfo_data.GroupHierarchy.Attributes(focalLength_id).Value;
49 |
50 | shift = hinfo_data.GroupHierarchy.Attributes(shift_id).Value;
51 |
52 | xRes = hinfo_data.GroupHierarchy.Attributes(xRes_id).Value;
53 | yRes = hinfo_data.GroupHierarchy.Attributes(yRes_id).Value;
54 | uRes = hinfo_data.GroupHierarchy.Attributes(hRes_id).Value;
55 | vRes = hinfo_data.GroupHierarchy.Attributes(vRes_id).Value;
56 |
57 |
58 | UV_diameter = uRes;
59 | UV_center = round(UV_diameter/2);
60 | UV_radius = UV_center - 1;
61 | UV_size = UV_diameter^2;
62 | LF_y_size = yRes * vRes;
63 | LF_x_size = xRes * uRes;
64 | y_size=yRes;
65 | x_size=xRes;
66 |
67 |
68 | LF = permute(double(data), [5 4 3 2 1]);
69 | depth = groundtruth(:,:,UV_center,UV_center)';
70 | disparity = (double(dH)*focalLength) ./ depth - double(shift);
71 |
72 | LF_Remap = (reshape(permute(LF, [1 3 2 4 5]), [LF_y_size LF_x_size 3]));
73 | IM_Pinhole = (im2double(squeeze(LF(UV_center,UV_center,:,:,1:3))));
74 | end
--------------------------------------------------------------------------------