├── Data
├── Lytro
│ └── Lytro.xml
└── Raytrix
│ └── Raytrix.xml
├── Demo
├── RunSimulateLytroImage.m
└── RunSimulateRaytrixImage.m
├── MyPlenopticTool
├── AddToolboxPath.m
├── GenerateRawImgTools
│ ├── CalculateCornerGT.m
│ ├── FastPlaneObjectRawSim
│ │ ├── AddDefocusEffect.m
│ │ ├── FastGenerateRawImgFromPlaneObject.m
│ │ ├── FastSimulateAndSaveImg.m
│ │ ├── PreparePlaneObject.m
│ │ └── SetPlaneSimConfiguration.m
│ ├── FillPatchtoRaw.m
│ ├── GenerateCornersGT.m
│ ├── GenerateSimulatedImg.m
│ ├── GenerateWhiteImage.m
│ ├── ShowCornerResults.m
│ ├── ShowSimulatedCorner.m
│ ├── SimulateRawImg.m
│ ├── SimulateWhiteImg.m
│ └── findLensID.m
├── ProcessWhiteImg
│ ├── Convert2GrayImg.m
│ ├── ExtractRGBLensID.m
│ ├── FuncGenerateMLA.m
│ ├── GetLensGridFormXML.m
│ ├── GetMLAInfoByWhiteImg.m
│ ├── LFBuildHexGrid.m
│ ├── LFBuildLensletGridModel.m
│ ├── LFFigure.m
│ ├── LFProcessWhiteImage.m
│ ├── LFReadRaw.m
│ ├── LFRotz.m
│ ├── RemoveVignet.m
│ └── ValidateLensLetGridModel.m
└── Utility
│ ├── GetAxis.m
│ ├── GetAxisSam.m
│ ├── LFDefaultField.m
│ ├── LFDefaultVal.m
│ ├── LFFindFilesRecursive.m
│ ├── SetAxis.m
│ ├── SetAxisSam.m
│ └── xml2struct.m
└── README.md
/Data/Lytro/Lytro.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 0.333333333333
4 | 0.333333333333
5 |
6 | 11.0
7 | 0
8 | 1.0
9 | 2.000000000000
10 |
11 | 1.000000000000
12 | 0.000000000000
13 |
14 |
15 | 0.500000000000
16 | 0.866025403784
17 |
18 |
19 | 3.000000000000
20 | 1.732050807569
21 |
22 |
23 | constant
24 | 0
25 |
26 | 0.000000000000
27 | 0.000000000000
28 |
29 |
30 |
31 |
32 | 0.000000000000
33 | 0.000000000000
34 |
35 |
36 | 1.000000000000
37 | 3.000000000000
38 |
39 |
40 |
41 |
42 | 1.000000000000
43 | 0.000000000000
44 |
45 |
46 | 2.799999952316
47 | 4.000000000000
48 |
49 |
50 |
51 |
52 | -1.000000000000
53 | 0.000000000000
54 |
55 |
56 | 3.799999952316
57 | 100.000000000000
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Data/Raytrix/Raytrix.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 0.333333333333
4 | 0.333333333333
5 |
6 | 32.0
7 | 0
8 | 1.0
9 | 2.000000000000
10 |
11 | 1.000000000000
12 | 0.000000000000
13 |
14 |
15 | 0.500000000000
16 | 0.866025403784
17 |
18 |
19 | 3.000000000000
20 | 1.732050807569
21 |
22 |
23 | constant
24 | 0
25 |
26 | 0.000000000000
27 | 0.000000000000
28 |
29 |
30 |
31 |
32 | 0.000000000000
33 | 0.000000000000
34 |
35 |
36 | 1.000000000000
37 | 3.000000000000
38 |
39 |
40 |
41 |
42 | 1.000000000000
43 | 0.000000000000
44 |
45 |
46 | 2.799999952316
47 | 4.000000000000
48 |
49 |
50 |
51 |
52 | -1.000000000000
53 | 0.000000000000
54 |
55 |
56 | 3.799999952316
57 | 100.000000000000
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Demo/RunSimulateLytroImage.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/Demo/RunSimulateLytroImage.m
--------------------------------------------------------------------------------
/Demo/RunSimulateRaytrixImage.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/Demo/RunSimulateRaytrixImage.m
--------------------------------------------------------------------------------
/MyPlenopticTool/AddToolboxPath.m:
--------------------------------------------------------------------------------
1 | function AddToolboxPath()
2 | addpath(genpath(pwd));
3 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/CalculateCornerGT.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/CalculateCornerGT.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/FastPlaneObjectRawSim/AddDefocusEffect.m:
--------------------------------------------------------------------------------
1 | function PatchImg = AddDefocusEffect(i,CellRGBLensID,PatchImg)
2 | if ismember(i,CellRGBLensID{1})
3 | % do nothing.
4 | end
5 | if ismember(i,CellRGBLensID{2})
6 | h = fspecial('average',[3,3]); % The degree of blurness is up to the kernal size.
7 | PatchImg = imfilter(PatchImg,h);
8 | end
9 | if ismember(i,CellRGBLensID{3})
10 | h = fspecial('average',[5,5]); % The degree of blurness is up to the kernal size.
11 | PatchImg = imfilter(PatchImg,h);
12 | end
13 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/FastPlaneObjectRawSim/FastGenerateRawImgFromPlaneObject.m:
--------------------------------------------------------------------------------
1 | function RawImg = FastGenerateRawImgFromPlaneObject(InfoBag)
2 | % Data preprocess.
3 | % Get the data with regard to the object image.
4 | Obj_CameraCoords = InfoBag.Obj_CameraCoords; % coordinate of the object image.
5 | Obj = im2double(InfoBag.Obj); % Object image.
6 | [ObjY,ObjX] = size(Obj); % Object size.
7 | cm = (ObjX+1)/2; % Object image center.
8 | cn = (ObjY+1)/2; % Object image center.
9 | PixelSize = InfoBag.PixelSize; % Physical size of the
10 | PlaneDistance = Obj_CameraCoords(1,3); % the distance between plane and camera center.
11 |
12 | % Get the date with regard to the MLA.
13 | GridCoordsX = InfoBag.GridCoords(:,:,1);
14 | GridCoordsY = InfoBag.GridCoords(:,:,2);
15 | CellRGBLensID = ExtractRGBLensID( InfoBag.GridCoords, InfoBag.LensletGridModel);
16 |
17 | % Add blur to different micro-images.
18 |
19 | % Get the date with regard to the plenoptic camera.
20 | cu = (InfoBag.pixelX+1)/2; % principal point location.
21 | cv = (InfoBag.pixelY+1)/2; % principal point location.
22 | K1 = InfoBag.K1;
23 | K2 = InfoBag.K2;
24 | fx = InfoBag.fx;
25 | Dmi = InfoBag.Dmi; % the diameter of micro-image .
26 | ImgSize = [InfoBag.pixelX,InfoBag.pixelY]; % the size of the raw image.
27 | RawImgHeight = ImgSize(2);
28 | RawImgWidth = ImgSize(1);
29 | MicImgNum = size( GridCoordsX(:),1 ); % the number of micro-image.
30 |
31 | % Calculate the Circle relative coordinate in the object plane.
32 | ScaleFactor = fx*PixelSize / ( K2 + PlaneDistance * K1 );
33 | ValidPDFRadius = Dmi/2;
34 | MicImgRadius = round(Dmi/2)+3;
35 | % the interger radius. Increase the radius in order to avoid the edge
36 | % effect of the subsequent mean filter.
37 | Xrange = -MicImgRadius : 1 : MicImgRadius;
38 | Yrange = -MicImgRadius : 1 : MicImgRadius;
39 | [XX,YY] = meshgrid(Xrange, Yrange);
40 | XY = [XX(:),YY(:)];
41 | CircleIndex = find( sqrt( sum(XY.^2,2) )< ValidPDFRadius );
42 | CircleXY = XY(CircleIndex,:);
43 |
44 | % iterate each micro-image
45 | RawImg = zeros( RawImgHeight,RawImgWidth );
46 | for i = 1: MicImgNum
47 | % find the corresponding location in the raw image.
48 | CurMicImgCenter = [GridCoordsX(i),GridCoordsY(i)];
49 |
50 | % Calculate the location in Obj image.
51 | ObjCircelCenter = PlaneDistance/( fx * PixelSize ).*( CurMicImgCenter - [cu,cv] )+[cm,cn];
52 | PatchXX = ObjCircelCenter(1) + XX.*(1/ScaleFactor);
53 | PatchYY = ObjCircelCenter(2) + YY.*(1/ScaleFactor);
54 | ObjImgRadius = floor( MicImgRadius*(1/ScaleFactor) )+2;
55 | ObjCenterXOrigin = round(ObjCircelCenter(1));
56 | ObjCenterYOrigin = round(ObjCircelCenter(2));
57 | PatchUPX = ObjCenterXOrigin - ObjImgRadius;
58 | PatchUPY = ObjCenterYOrigin - ObjImgRadius;
59 | PatchDownX = ObjCenterXOrigin + ObjImgRadius;
60 | PatchDownY = ObjCenterYOrigin + ObjImgRadius;
61 |
62 | if ( PatchUPX>0) && (PatchUPY>0) && (PatchDownX< ObjX) && (PatchDownY< ObjY)
63 | % Extract the image patch from Object image.
64 | PatchImgOrigin = Obj( PatchUPY : PatchDownY , PatchUPX : PatchDownX );
65 | OriginX = PatchUPX : PatchDownX;
66 | OriginY = PatchUPY : PatchDownY;
67 | [OriginXX,OriginYY] = meshgrid(OriginX,OriginY);
68 | PatchImg = interp2(OriginXX,OriginYY,PatchImgOrigin,PatchXX,PatchYY,'linear'); % 'nearest' 'cubic'
69 |
70 | % Add blurness according to the different micro-images
71 | % classification.
72 | PatchImg = AddDefocusEffect(i,CellRGBLensID,PatchImg);
73 |
74 | % Extract the circle part.
75 | PatchImgCircle = PatchImg(CircleIndex);
76 |
77 | % Calculate the location in micro-image.
78 | RawImgCoord = CurMicImgCenter + CircleXY; % Relative location in raw image.
79 | PixLocPx = round( RawImgCoord(:,1) );
80 | PixLocPy = round( RawImgCoord(:,2) );
81 | LinearInd = int32( PixLocPx.*RawImgHeight+PixLocPy );
82 |
83 | % Boundary check.
84 | ValidID_X = ( PixLocPx < RawImgWidth ) & ( PixLocPx > 0 );
85 | ValidID_Y = ( PixLocPy < RawImgHeight ) & ( PixLocPy > 0 );
86 | ValidID = find( ( ValidID_X & ValidID_Y ) ==1 );
87 |
88 | % Store the pixel value.
89 | RawImg(LinearInd(ValidID)) = PatchImgCircle(ValidID);
90 | end
91 | end
92 | end
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/FastPlaneObjectRawSim/FastSimulateAndSaveImg.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/FastPlaneObjectRawSim/FastSimulateAndSaveImg.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/FastPlaneObjectRawSim/PreparePlaneObject.m:
--------------------------------------------------------------------------------
1 | function [Obj_CameraCoords,Obj,PixelSize] = PreparePlaneObject(InfoBag)
2 | % generate the scene(point cloud) in world coordinate system.
3 | ObjImgSize = InfoBag.ObjImgSize; %
4 | PicPath = InfoBag.PicPath;
5 | Distance = InfoBag.ObjDistance; % The physical distance of the image. mm.
6 |
7 | % Get the info of camera.
8 | bL0 = InfoBag.bL0;
9 | B = InfoBag.B;
10 | pixelY = InfoBag.pixelY;
11 | pixelX = InfoBag.pixelX;
12 | sxy = InfoBag.sxy;
13 | %Height = sxy*pixelY*Distance/(bL0+B);
14 | Width = sxy*pixelX*Distance/(bL0+B)+50;
15 |
16 | ImgMetricSize = Width; % The physical size of the image. mm.
17 |
18 | % set the image size which is odd.
19 | Xradius = round(ObjImgSize(1)/2);
20 | if mod(Xradius,2)==0
21 | Xradius = Xradius+1;
22 | end
23 | Yradius = round(ObjImgSize(2)/2);
24 | if mod(Yradius,2)==0
25 | Yradius = Yradius+1;
26 | end
27 | ObjImgSize = [2*Xradius+1, 2*Yradius+1]; % Actual picture resolution.
28 | PixelSize = ImgMetricSize/ObjImgSize(1); % The physical size of the pixel.
29 |
30 | % Read the picture.
31 | Obj1 = imread(PicPath);
32 | Obj1 = im2double(rgb2gray(Obj1));
33 | Obj = imresize(Obj1, [ObjImgSize(2),ObjImgSize(1)]); % resize the image to unify the resolution.
34 |
35 | % generate the location of the point clouds.
36 | X = -Xradius : Xradius;
37 | Y = -Yradius : Yradius;
38 | [XX,YY] = meshgrid(X,Y);
39 | XY = [XX(:),YY(:)];
40 | PixelNum = size(XY,1);
41 | ObjWorldCoords1 = [XY.*PixelSize,Distance+zeros(PixelNum,1)];
42 | Obj_CameraCoords = ObjWorldCoords1;
43 |
44 | % visually validate the results
45 | %figure;pcshow(Obj_CameraCoords,Obj);
46 | %xlabel('X');ylabel('Y');zlabel('Z');
47 | %figure;plot3( Obj_CameraCoords(:,1), Obj_CameraCoords(:,2), Obj_CameraCoords(:,3),'*' );
48 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/FastPlaneObjectRawSim/SetPlaneSimConfiguration.m:
--------------------------------------------------------------------------------
1 | function InfoBag = SetPlaneSimConfiguration()
2 | % set the parameters for raw image generation.
3 | % Set the working distance.
4 | WorkDistance = 1000;
5 | FocusedVdValue = 4; % working distance
6 | InfoBag.ObjImgSize = [6000,4000];
7 |
8 | % Set the simulation parameter.
9 | InfoBag.FlagRemoveEdge = false; % whether remove the micro-lenses which is not complete .
10 | InfoBag.ParallelFlag = false; % whether use parallel computation.
11 |
12 | % Set the intrinsic parameters.
13 | InfoBag.pixelY = 2000;
14 | InfoBag.pixelX = 3000;
15 | InfoBag.sxy = 0.0055; % size of the pixel on sensor
16 | InfoBag.F = 100; % focal length(mm).
17 | InfoBag.B = 2; % Distance between MLA and sensor.
18 | InfoBag.fm1 = 2; % focal length of micro-lens type 1
19 | InfoBag.fm2 = 2; % focal length of micro-lens type 2
20 | InfoBag.fm3 = 2; % focal length of micro-lens type 3
21 | InfoBag.Dmi = 32; % the diameter of micro-image(pixel)
22 | InfoBag.k1 = 0;
23 | InfoBag.k2 = 0;
24 | InfoBag.bL0 = InfoBag.F * WorkDistance / ( WorkDistance-InfoBag.F )-FocusedVdValue*InfoBag.B; % Distance between MLA and main lens.
25 | InfoBag.DL = 0.9*InfoBag.bL0/( InfoBag.B/(InfoBag.Dmi*InfoBag.sxy) ); % the diameter of main lens aperture.
26 |
27 | % Calculate the rest of parameters
28 | InfoBag.Dml = InfoBag.Dmi*InfoBag.bL0/(InfoBag.bL0+InfoBag.B); % The diameter of the micro-lenses.
29 | Lm = -InfoBag.bL0;
30 | Lc = -InfoBag.bL0-InfoBag.B;
31 | InfoBag.K1 = -(Lm+InfoBag.F)*Lc/( (Lm-Lc)*InfoBag.F );
32 | InfoBag.K2 = Lm*Lc/(Lm-Lc);
33 | InfoBag.fx = (InfoBag.bL0+InfoBag.B)/InfoBag.sxy;
34 | InfoBag.fy = (InfoBag.bL0+InfoBag.B)/InfoBag.sxy;
35 | InfoBag.cx = InfoBag.pixelX/2;
36 | InfoBag.cy = InfoBag.pixelY/2;
37 |
38 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/FillPatchtoRaw.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/FillPatchtoRaw.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/GenerateCornersGT.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/GenerateCornersGT.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/GenerateSimulatedImg.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/GenerateSimulatedImg.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/GenerateWhiteImage.m:
--------------------------------------------------------------------------------
1 |
2 | function WhiteNew = GenerateWhiteImage(LensletGridModel,GridCoords,DataPath,FilePath,Debug)
3 | white = imread(FilePath);
4 | white = im2double(white);
5 | TrueDiameter = LensletGridModel.HSpacing;
6 | Diameter = round(TrueDiameter);
7 | if mod(Diameter,2)==0 % make sure the circlesize is odd.
8 | CircleSize = Diameter+1;
9 | else
10 | CircleSize = Diameter+2;
11 | end
12 |
13 | %extract three position.
14 |
15 | McLensCenter3 =[GridCoords(2,2,1),GridCoords(2,2,2);
16 | GridCoords(2,5,1),GridCoords(2,5,2);
17 | GridCoords(2,8,1),GridCoords(2,8,2);
18 | GridCoords(2,11,1),GridCoords(2,11,2)];
19 | McLensCenter2 =[GridCoords(2,3,1),GridCoords(2,3,2);
20 | GridCoords(2,6,1),GridCoords(2,6,2);
21 | GridCoords(2,9,1),GridCoords(2,9,2);
22 | GridCoords(2,12,1),GridCoords(2,12,2)];
23 | McLensCenter1 =[GridCoords(2,4,1),GridCoords(2,4,2);
24 | GridCoords(2,7,1),GridCoords(2,7,2);
25 | GridCoords(2,10,1),GridCoords(2,10,2);
26 | GridCoords(2,13,1),GridCoords(2,13,2)];
27 | if Debug == true
28 | figure; imshow(white);
29 | hold on;
30 | plot(McLensCenter1(:,1),McLensCenter1(:,2),'b*');
31 | plot(McLensCenter2(:,1),McLensCenter2(:,2),'r*');
32 | plot(McLensCenter3(:,1),McLensCenter3(:,2),'y*');
33 | hold off;
34 | end
35 | %extract three types.
36 | CellRGBLensID = ExtractRGBLensID(GridCoords,LensletGridModel);
37 | RLens_ID = CellRGBLensID{1};
38 | GLens_ID = CellRGBLensID{2};
39 | BLens_ID = CellRGBLensID{3};
40 | GridCoordsX = GridCoords(:,:,1);
41 | GridCoordsY = GridCoords(:,:,2);
42 | RLensCoord = [GridCoordsX(RLens_ID'),GridCoordsY(RLens_ID')];
43 | GLensCoord = [GridCoordsX(GLens_ID'),GridCoordsY(GLens_ID')];
44 | BLensCoord = [GridCoordsX(BLens_ID'),GridCoordsY(BLens_ID')];
45 | if Debug == true
46 | figure;imshow(white);
47 | hold on;
48 | plot(RLensCoord(:,1),RLensCoord(:,2),'b*');
49 | plot(GLensCoord(:,1),GLensCoord(:,2),'r*');
50 | plot(BLensCoord(:,1),BLensCoord(:,2),'y*');
51 | hold off;
52 | end
53 | %*******produce mask*************************
54 | Mask = zeros(CircleSize,CircleSize);
55 | x = 1:CircleSize;
56 | y = 1:CircleSize;
57 | [xx,yy] = meshgrid(x,y);
58 | xy = [xx(:),yy(:)];
59 | center = [CircleSize+1,CircleSize+1]/2;
60 | distance= sqrt(sum((xy-center).^2,2));
61 | Mask(distance<(TrueDiameter)/2) = 1; % enlarge a little
62 |
63 | %******extract three types micro images **************************************
64 | PatchSize = CircleSize;
65 | Num = size(McLensCenter3,1);
66 | PatchInterpMasked1 = zeros(size(Mask));
67 | for i=1:Num
68 | PatchInterp1 = ExtractPatchFromRaw(white,McLensCenter1(i,:),PatchSize);
69 | PatchInterpMasked1_1 = PatchInterp1.*Mask;
70 | PatchInterpMasked1 = PatchInterpMasked1+PatchInterpMasked1_1;
71 | PatchInterp2 = ExtractPatchFromRaw(white,McLensCenter2(i,:),PatchSize);
72 | PatchInterpMasked2_1 = PatchInterp2.*Mask;
73 | PatchInterpMasked2 = PatchInterpMasked1+PatchInterpMasked2_1;
74 | PatchInterp3 = ExtractPatchFromRaw(white,McLensCenter3(i,:),PatchSize);
75 | PatchInterpMasked3_1 = PatchInterp3.*Mask;
76 | PatchInterpMasked3 = PatchInterpMasked1+PatchInterpMasked3_1;
77 | end
78 | PatchInterpMasked1 = PatchInterpMasked1./Num;
79 | PatchInterpMasked2 = PatchInterpMasked2./Num;
80 | PatchInterpMasked3 = PatchInterpMasked3./Num;
81 |
82 |
83 | if Debug == true
84 | figure;imshow(Mask);
85 | figure;imshow(PatchInterpMasked1);
86 | figure;imshow(PatchInterpMasked2);
87 | figure;imshow(PatchInterpMasked3);
88 | end
89 | %
90 | ImgSize = size(white);
91 | WhiteNewCollect = zeros(ImgSize(1)+100,ImgSize(2)+100);
92 | PatchRadius = (PatchSize-1)/2;
93 | X2 = -PatchRadius : 1 : PatchRadius;
94 | Y2 = -PatchRadius : 1 : PatchRadius;
95 | RLensCoord = [GridCoordsX(RLens_ID'),GridCoordsY(RLens_ID')]+[50,50];
96 | for i=1:size(RLensCoord,1)
97 | Coords = RLensCoord(i,:);
98 | FillPatchInterp1 = FillPatchtoRaw(PatchInterpMasked1,Coords,PatchSize);
99 | FillPatchInterp1(isnan(FillPatchInterp1))=0;
100 | %figure;imshow(PatchInterp)
101 | WhiteNewCollect( round(Coords(2))+Y2 ,round(Coords(1))+X2 )=WhiteNewCollect( round(Coords(2))+Y2 ,round(Coords(1))+X2 )+FillPatchInterp1;%PatchInterpMasked1;
102 | end
103 |
104 | GLensCoord = [GridCoordsX(GLens_ID'),GridCoordsY(GLens_ID')]+[50,50];
105 | for i=1:size(GLensCoord,1)
106 | Coords = GLensCoord(i,:);
107 | FillPatchInterp2 = FillPatchtoRaw(PatchInterpMasked2,Coords,PatchSize);
108 | FillPatchInterp2(isnan(FillPatchInterp2))=0;
109 | WhiteNewCollect( round(Coords(2))+Y2 ,round(Coords(1))+X2 )=WhiteNewCollect( round(Coords(2))+Y2 ,round(Coords(1))+X2 )+ FillPatchInterp2;%PatchInterpMasked2;
110 | end
111 |
112 | BLensCoord = [GridCoordsX(BLens_ID'),GridCoordsY(BLens_ID')]+[50,50];
113 | for i=1:size(BLensCoord,1)
114 | Coords = BLensCoord(i,:);
115 | FillPatchInterp3 = FillPatchtoRaw(PatchInterpMasked3,Coords,PatchSize);
116 | FillPatchInterp3(isnan(FillPatchInterp3))=0;
117 | WhiteNewCollect( round(Coords(2))+Y2 ,round(Coords(1))+X2 )=WhiteNewCollect( round(Coords(2))+Y2 ,round(Coords(1))+X2 )+FillPatchInterp3;%PatchInterpMasked3;
118 | end
119 | WhiteNew = WhiteNewCollect(51:ImgSize(1)+50,51:ImgSize(2)+50);
120 | if Debug == true
121 | figure;imshow(WhiteNewCollect);
122 | figure;imshow(WhiteNew);
123 | end
124 | imwrite(WhiteNew,[DataPath,'\WhiteRaw.png']);
125 |
126 |
127 |
128 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/ShowCornerResults.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/ShowCornerResults.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/ShowSimulatedCorner.m:
--------------------------------------------------------------------------------
1 | function ShowSimulatedCorner(corn_est,GridCoords)
2 | GridCoordsX = GridCoords(:,:,1);
3 | GridCoordsY = GridCoords(:,:,2);
4 | ImageValueNum = length(corn_est);
5 | for iFile = 1 :ImageValueNum
6 | CurrentGroundTruthtem = corn_est{iFile};
7 | CornerNumPerFrame = size(CurrentGroundTruthtem,1);
8 | figure;
9 | plot(GridCoordsX(:) , GridCoordsY(:),'b*');
10 | for k = 1:CornerNumPerFrame
11 | CornerInfoGT = CurrentGroundTruthtem{k};
12 | hold on ;
13 | if ~isempty(CornerInfoGT)
14 | plot(CornerInfoGT(:,1),CornerInfoGT(:,2),'r*');
15 | %plot(GridCoordsX(CornerInfoGT(:,3)) , GridCoordsY(CornerInfoGT(:,3)),'b*');
16 | end
17 | hold off;
18 | end
19 |
20 | end
21 |
22 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/SimulateRawImg.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/SimulateRawImg.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/SimulateWhiteImg.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/SimulateWhiteImg.m
--------------------------------------------------------------------------------
/MyPlenopticTool/GenerateRawImgTools/findLensID.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/GenerateRawImgTools/findLensID.m
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/Convert2GrayImg.m:
--------------------------------------------------------------------------------
1 | function GrayImg = Convert2GrayImg(Img)
2 | b=size(Img,3);
3 | if b==3
4 | GrayImg = rgb2gray(Img);
5 | else
6 | GrayImg = Img;
7 | end
8 | GrayImg = im2double(GrayImg);
9 | end
10 |
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/ExtractRGBLensID.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/ProcessWhiteImg/ExtractRGBLensID.m
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/FuncGenerateMLA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/ProcessWhiteImg/FuncGenerateMLA.m
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/GetLensGridFormXML.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/ProcessWhiteImg/GetLensGridFormXML.m
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/GetMLAInfoByWhiteImg.m:
--------------------------------------------------------------------------------
1 | function [LensletGridModel,GridCoords,ImgSize]= GetMLAInfoByWhiteImg(WhitePath, FileSpecWhite,RoughRadius)
2 | GridModelOptions.ApproxLensletSpacing = RoughRadius;
3 | [FileList_raw, BasePath_raw] = ReadRawImgInfo(WhitePath, FileSpecWhite);
4 | WhiteImage = ReadRawImg(BasePath_raw,FileList_raw, 1);
5 | [LensletGridModel,GridCoords] = LFProcessWhiteImage( WhiteImage,GridModelOptions);
6 |
7 | Radius = LensletGridModel.HSpacing/2;
8 | ImgSize = size(WhiteImage);
9 | GridCoordsX = GridCoords(:,:,1);
10 | GridCoordsY = GridCoords(:,:,2);
11 |
12 | % check the edge of the MLA.
13 | if sum( GridCoordsX(:,end)>(ImgSize(2)-Radius) ) > 1
14 | GridCoords(:,end,:)=[];
15 | end
16 | if sum( GridCoordsY(end,:)>(ImgSize(1)-Radius) ) > 1
17 | GridCoords(end,:,:)=[];
18 | end
19 | if sum( GridCoordsX(:,1)<(Radius) ) > 1
20 | GridCoords(:,1,:)=[];
21 | end
22 | if sum( GridCoordsY(1,:)<(Radius) ) > 1
23 | GridCoords(1,:,:)=[];
24 | end
25 |
26 | % update the LensletGridModel
27 | LensletGridModel.UMax = size(GridCoords,2);
28 | LensletGridModel.VMax = size(GridCoords,1);
29 |
30 |
31 |
32 |
33 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/LFBuildHexGrid.m:
--------------------------------------------------------------------------------
1 | function [GridCoords] = LFBuildHexGrid( LensletGridModel )
2 |
3 | RotCent = eye(3);
4 | RotCent(1:2,3) = [LensletGridModel.HOffset, LensletGridModel.VOffset];
5 |
6 | ToOffset = eye(3);
7 | ToOffset(1:2,3) = [LensletGridModel.HOffset, LensletGridModel.VOffset];
8 |
9 | R = ToOffset * RotCent * LFRotz(LensletGridModel.Rot) * RotCent^-1;
10 |
11 |
12 | [vv,uu] = ndgrid((0:LensletGridModel.VMax-1).*LensletGridModel.VSpacing, (0:LensletGridModel.UMax-1).*LensletGridModel.HSpacing);
13 |
14 | uu(LensletGridModel.FirstPosShiftRow:2:end,:) = uu(LensletGridModel.FirstPosShiftRow:2:end,:) + 0.5.*LensletGridModel.HSpacing;
15 |
16 | GridCoords = [uu(:), vv(:), ones(numel(vv),1)];
17 | GridCoords = (R*GridCoords')';
18 |
19 | GridCoords = reshape(GridCoords(:,1:2), [LensletGridModel.VMax,LensletGridModel.UMax,2]);
20 |
21 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/LFBuildLensletGridModel.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/ProcessWhiteImg/LFBuildLensletGridModel.m
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/LFFigure.m:
--------------------------------------------------------------------------------
1 | function h = LFFigure(h, varargin)
2 | % LFFIGURE (originally sfigure) Create figure window (minus annoying focus-theft).
3 | %
4 | % Usage is identical to figure.
5 | %
6 | % Daniel Eaton, 2005
7 | %
8 | % See also figure
9 |
10 | if nargin>=1
11 | if ishandle(h)
12 | set(0, 'CurrentFigure', h);
13 | else
14 | h = figure(h, varargin{:});
15 | end
16 | else
17 | h = figure;
18 | end
19 |
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/LFProcessWhiteImage.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/samliu0631/Light-Field-Simulation/0f71ce150f0ad71f22f93b62bad2cce99e741e0c/MyPlenopticTool/ProcessWhiteImg/LFProcessWhiteImage.m
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/LFReadRaw.m:
--------------------------------------------------------------------------------
1 | % LFReadRaw - Reads 8, 10, 12 and 16-bit raw image files
2 | %
3 | % Usage:
4 | %
5 | % Img = LFReadRaw( Fname )
6 | % Img = LFReadRaw( Fname, BitPacking, ImgSize )
7 | % Img = LFReadRaw( Fname, [], ImgSize )
8 | %
9 | % There is no universal `RAW' file format. This function reads a few variants, including the 12-bit and 10-bit files
10 | % commonly employed in Lytro cameras, and the 16-bit files produced by some third-party LFP extraction tools. The output
11 | % is always an array of type uint16, except for 8-bit files which produce an 8-bit output.
12 | %
13 | % Raw images may be converted to more portable formats, including .png, using an external tool such as the
14 | % cross-platform ImageMagick tool.
15 | %
16 | % Inputs :
17 | %
18 | % Fname : path to raw file to read
19 | %
20 | % [optional] BitPacking : one of '12bit', '10bit' or '16bit'; default is '12bit'
21 | %
22 | % [optional] ImgSize : a 2D vector defining the size of the image, in pixels. The default value varies according to
23 | % the value of 'BitPacking', to correspond to commonly-found Lytro file formats: 12 bit images are employed by the
24 | % Lytro F01, producing images of size 3280x3280, while 10-bit images are produced by the Illum at a resolutio of
25 | % 7728x5368; 16-bit images default to 3280x3280.
26 | %
27 | % Outputs:
28 | %
29 | % Img : an array of uint16 gray levels. No demosaicing (decoding Bayer pattern) is performed.
30 | %
31 | % See also: LFReadLFP, LFDecodeLensletImageSimple, demosaic
32 |
33 | % Part of LF Toolbox v0.4 released 12-Feb-2015
34 | % Copyright (c) 2013-2015 Donald G. Dansereau
35 |
36 | function Img = LFReadRaw( Fname, BitPacking, ImgSize )
37 |
38 | %---Defaults---
39 | BitPacking = LFDefaultVal( 'BitPacking', '12bit' );
40 |
41 | switch( BitPacking )
42 | case '8bit'
43 | ImgSize = LFDefaultVal( 'ImgSize', [3280,3280] );
44 | BuffSize = prod(ImgSize);
45 |
46 | case '12bit'
47 | ImgSize = LFDefaultVal( 'ImgSize', [3280,3280] );
48 | BuffSize = prod(ImgSize) * 12/8;
49 |
50 | case '10bit'
51 | ImgSize = LFDefaultVal( 'ImgSize', [7728, 5368] );
52 | BuffSize = prod(ImgSize) * 10/8;
53 |
54 | case '16bit'
55 | ImgSize = LFDefaultVal( 'ImgSize', [3280,3280] );
56 | BuffSize = prod(ImgSize) * 16/8;
57 |
58 | otherwise
59 | error('Unrecognized bit packing format');
60 | end
61 |
62 | %---Read and unpack---
63 | f = fopen( Fname );
64 | Img = fread( f, BuffSize, 'uchar' );
65 | Img = LFUnpackRawBuffer( Img, BitPacking, ImgSize )'; % note the ' is necessary to get the rotation right
66 | fclose( f );
67 |
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/LFRotz.m:
--------------------------------------------------------------------------------
1 | % LFRotz - simple 3D rotation matrix, rotation about z
2 | %
3 | % Usage:
4 | % R = LFRotz( psi )
5 | %
6 |
7 | % Part of LF Toolbox v0.4 released 12-Feb-2015
8 | % Copyright (c) 2013-2015 Donald G. Dansereau
9 |
10 | function R = LFRotz(psi)
11 |
12 | c = cos(psi);
13 | s = sin(psi);
14 |
15 | R = [ c, -s, 0; ...
16 | s, c, 0; ...
17 | 0, 0, 1 ];
18 |
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/RemoveVignet.m:
--------------------------------------------------------------------------------
1 | function CurImg_rawDevignet = RemoveVignet(CurImg_White,CurImg_raw)
2 | CurImg_White = Convert2GrayImg(CurImg_White);
3 | CurImg_raw = Convert2GrayImg(CurImg_raw);
4 |
5 | CurImg_rawDevignet = CurImg_raw./CurImg_White ;
6 | CurImg_rawDevignet(CurImg_rawDevignet==inf)=0;
7 | CurImg_rawDevignet(CurImg_rawDevignet>1)=1;
8 | end
9 |
--------------------------------------------------------------------------------
/MyPlenopticTool/ProcessWhiteImg/ValidateLensLetGridModel.m:
--------------------------------------------------------------------------------
1 | function [GridCoords,LensletGridModel]= ValidateLensLetGridModel(GridCoords,LensletGridModel,ImgSizeX,ImgSizeY)
2 | GridCoordsX = GridCoords(:,:,1);
3 | GridCoordsY = GridCoords(:,:,2);
4 | Radius = LensletGridModel.HSpacing/2;
5 |
6 | % check the edge of the MLA.
7 | if sum( GridCoordsX(:,end)>(ImgSizeX-Radius) ) > 1
8 | GridCoords(:,end,:)=[];
9 | end
10 | if sum( GridCoordsY(end,:)>(ImgSizeY-Radius) ) > 1
11 | GridCoords(end,:,:)=[];
12 | end
13 | if sum( GridCoordsX(:,1)<(Radius) ) > 1
14 | GridCoords(:,1,:)=[];
15 | end
16 | if sum( GridCoordsY(1,:)<(Radius) ) > 1
17 | GridCoords(1,:,:)=[];
18 | end
19 | % update the LensletGridModel
20 | LensletGridModel.UMax = size(GridCoords,2);
21 | LensletGridModel.VMax = size(GridCoords,1);
22 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/GetAxis.m:
--------------------------------------------------------------------------------
1 | function Params=GetAxis(Matrix)
2 |
3 | Params=zeros(1,6);
4 | cosb=(3-Matrix(1,1)-Matrix(2,2)-Matrix(3,3))/2;
5 | if cosb<=0
6 | Params(1)=0;
7 | Params(2)=0;
8 | Params(3)=0;
9 | elseif cosb>=2
10 | Params(1)=0.5*(1+Matrix(1,1))*pi;
11 | Params(2)=0.5*(1+Matrix(2,2))*pi;
12 | Params(3)=0.5*(1+Matrix(3,3))*pi;
13 | else
14 | b=acos(1-cosb);
15 | sinb=sin(b);
16 | if b~=0 && sinb~=0
17 | Params(1)=(Matrix(3,2)-Matrix(2,3))/(2*sinb)*b;
18 | Params(2)=(Matrix(1,3)-Matrix(3,1))/(2*sinb)*b;
19 | Params(3)=(Matrix(2,1)-Matrix(1,2))/(2*sinb)*b;
20 | end
21 | end
22 | Params(4)=Matrix(1,4);
23 | Params(5)=Matrix(2,4);
24 | Params(6)=Matrix(3,4);
25 |
26 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/GetAxisSam.m:
--------------------------------------------------------------------------------
1 | function Params=GetAxisSam(Matrix)
2 |
3 | if Matrix(3,1)~=1 && Matrix(3,1)~=-1
4 | theta = -asin(Matrix(3,1));
5 | gelma = atan2( Matrix(3,2)/cos(theta) , Matrix(3,3)/cos(theta) );
6 | faile = atan2( Matrix(2,1)/cos(theta) , Matrix(1,1)/cos(theta) );
7 | else
8 | faile = 0;
9 | if Matrix(3,1)==-1
10 | theta = pi/2;
11 | gelma = atan2( Matrix(1,2),Matrix(1,3) );
12 | else
13 | theta = -pi/2;
14 | gelma = atan2( -Matrix(1,2),-Matrix(1,3) );
15 | end
16 | end
17 | Params(1)=gelma;
18 | Params(2)=theta;
19 | Params(3)=faile;
20 | Params(4)=Matrix(1,4);
21 | Params(5)=Matrix(2,4);
22 | Params(6)=Matrix(3,4);
23 | end
24 |
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/LFDefaultField.m:
--------------------------------------------------------------------------------
1 | % LFDefaultField - Convenience function to set up structs with default field values
2 | %
3 | % Usage:
4 | %
5 | % ParentStruct = LFDefaultField( ParentStruct, FieldName, DefaultVal )
6 | %
7 | % This provides an elegant way to establish default field values in a struct. See LFDefaultValue for
8 | % setting up non-struct variables with default values.
9 | %
10 | % Inputs:
11 | %
12 | % ParentStruct: string giving the name of the struct; the struct need not already exist
13 | % FieldName: string giving the name of the field
14 | % DefaultVal: default value for the field
15 | %
16 | % Outputs:
17 | %
18 | % ParentStruct: if the named struct and field already existed, the output matches the struct's
19 | % original value; otherwise the output is a struct with an additional field taking
20 | % on the specified default value
21 | %
22 | % Example:
23 | %
24 | % clearvars
25 | % ExistingStruct.ExistingField = 42;
26 | % ExistingStruct = LFDefaultField( 'ExistingStruct', 'ExistingField', 3 )
27 | % ExistingStruct = LFDefaultField( 'ExistingStruct', 'NewField', 36 )
28 | % OtherStruct = LFDefaultField( 'OtherStruct', 'Cheese', 'Indeed' )
29 | %
30 | %
31 | % Results in :
32 | % ExistingStruct =
33 | % ExistingField: 42
34 | % NewField: 36
35 | % OtherStruct =
36 | % Cheese: 'Indeed'
37 | %
38 | % Usage for setting up default function arguments is demonstrated in most of the LF Toolbox
39 | % functions.
40 | %
41 | % See also: LFDefaultVal
42 |
43 | % Part of LF Toolbox v0.4 released 12-Feb-2015
44 | % Copyright (c) 2013-2015 Donald G. Dansereau
45 |
46 | function ParentStruct = LFDefaultField( ParentStruct, FieldName, DefaultVal )
47 |
48 | %---First make sure the struct exists---
49 | CheckIfExists = sprintf('exist(''%s'', ''var'') && ~isempty(%s)', ParentStruct, ParentStruct);
50 | VarExists = evalin( 'caller', CheckIfExists );
51 | if( ~VarExists )
52 | ParentStruct = [];
53 | else
54 | ParentStruct = evalin( 'caller', ParentStruct );
55 | end
56 |
57 | %---Now make sure the field exists---
58 | if( ~isfield( ParentStruct, FieldName ) )
59 | ParentStruct.(FieldName) = DefaultVal;
60 | end
61 |
62 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/LFDefaultVal.m:
--------------------------------------------------------------------------------
1 | % LFDefaultVal - Convenience function to set up default parameter values
2 | %
3 | % Usage:
4 | %
5 | % Var = LFDefaultVal( Var, DefaultVal )
6 | %
7 | %
8 | % This provides an elegant way to establish default parameter values. See LFDefaultField for setting
9 | % up structs with default field values.
10 | %
11 | % Inputs:
12 | %
13 | % Var: string giving the name of the parameter
14 | % DefaultVal: default value for the parameter
15 | %
16 | %
17 | % Outputs:
18 | %
19 | % Var: if the parameter already existed, the output matches its original value, otherwise the
20 | % output takes on the specified default value
21 | %
22 | % Example:
23 | %
24 | % clearvars
25 | % ExistingVar = 42;
26 | % ExistingVar = LFDefaultVal( 'ExistingVar', 3 )
27 | % OtherVar = LFDefaultVal( 'OtherVar', 3 )
28 | %
29 | % Results in :
30 | % ExistingVar =
31 | % 42
32 | % OtherVar =
33 | % 3
34 | %
35 | % Usage for setting up default function arguments is demonstrated in most of the LF Toolbox
36 | % functions.
37 | %
38 | % See also: LFDefaultField
39 |
40 | % Part of LF Toolbox v0.4 released 12-Feb-2015
41 | % Copyright (c) 2013-2015 Donald G. Dansereau
42 |
43 | function Var = LFDefaultVal( Var, DefaultVal )
44 |
45 | CheckIfExists = sprintf('exist(''%s'', ''var'') && ~isempty(%s)', Var, Var);
46 | VarExists = evalin( 'caller', CheckIfExists );
47 |
48 | if( ~VarExists )
49 | Var = DefaultVal;
50 | else
51 | Var = evalin( 'caller', Var );
52 | end
53 |
54 | end
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/LFFindFilesRecursive.m:
--------------------------------------------------------------------------------
1 | % LFFindFilesRecursive - Recursively searches a folder for files matching one or more patterns
2 | %
3 | % Usage:
4 | %
5 | % [AllFiles, BasePath, FolderList, PerFolderFiles] = LFFindFilesRecursive( InputPath )
6 | %
7 | % Inputs:
8 | %
9 | % InputPath: the folder to recursively search
10 | %
11 | % Outputs:
12 | %
13 | % Allfiles : A list of all files found
14 | % BasePath : Top of the searched tree, excluding wildcards
15 | % FolderList : A list of all the folders explored
16 | % PerFolderFiles : A list of files organied by folder -- e.g. PerFolderFiles{1} are all the files
17 | % found in FolderList{1}
18 | %
19 | % Examples:
20 | %
21 | % LFFindFilesRecursive('Images')
22 | % LFFindFilesRecursive({'*.lfr','*.lfp'})
23 | % LFFindFilesRecursive({'Images','*.lfr','*.lfp'})
24 | % LFFindFilesRecursive('Images/*.lfr')
25 | % LFFindFilesRecursive('*.lfr')
26 | % LFFindFilesRecursive('Images/IMG_0001.LFR')
27 | % LFFindFilesRecursive('IMG_0001.LFR')
28 | %
29 |
30 | % Part of LF Toolbox v0.4 released 12-Feb-2015
31 | % Copyright (c) 2013-2015 Donald G. Dansereau
32 |
33 | function [AllFiles, BasePath, FolderList, PerFolderFiles] = LFFindFilesRecursive( InputPath, DefaultFileSpec, DefaultPath )
34 |
35 | PerFolderFiles = [];
36 | AllFiles = [];
37 |
38 | %---Defaults---
39 | DefaultFileSpec = LFDefaultVal( 'DefaultFileSpec', {'*'} );
40 | DefaultPath = LFDefaultVal( 'DefaultPath', '.' );
41 | InputPath = LFDefaultVal( 'InputPath', '.' );
42 |
43 | PathOnly = '';
44 | if( ~iscell(InputPath) )
45 | InputPath = {InputPath};
46 | end
47 | if( ~iscell(DefaultFileSpec) )
48 | DefaultFileSpec = {DefaultFileSpec};
49 | end
50 | InputFileSpec = DefaultFileSpec;
51 |
52 | if( exist(InputPath{1}, 'dir') ) % try interpreting first param as a folder, if it exists, grab is as such
53 | PathOnly = InputPath{1};
54 | InputPath(1) = [];
55 | end
56 | if( numel(InputPath) > 0 ) % interpret remaining elements as filespecs
57 | % Check if the filespec includes a folder name, and crack it out as part of the input path
58 | [MorePath, Stripped, Ext] = fileparts(InputPath{1});
59 | PathOnly = fullfile(PathOnly, MorePath);
60 | InputPath{1} = [Stripped,Ext];
61 | InputFileSpec = InputPath;
62 | end
63 | PathOnly = LFDefaultVal('PathOnly', DefaultPath);
64 | InputPath = PathOnly;
65 |
66 | % Clean up the inputpath to omit trailing slashes
67 | while( InputPath(end) == filesep )
68 | InputPath = InputPath(1:end-1);
69 | end
70 | BasePath = InputPath;
71 |
72 | %---Crawl folder structure locating raw lenslet images---
73 | fprintf('Searching for files [ ');
74 | fprintf('%s ', InputFileSpec{:});
75 | fprintf('] in %s\n', InputPath);
76 |
77 | %---
78 | FolderList = genpath(InputPath);
79 | if( isempty(FolderList) )
80 | error(['Input path not found... are you running from the correct folder? ' ...
81 | 'Current folder: %s'], pwd);
82 | end
83 | FolderList = textscan(FolderList, '%s', 'Delimiter', pathsep);
84 | FolderList = FolderList{1};
85 |
86 | %---Compile a list of all files---
87 | PerFolderFiles = cell(length(FolderList),1);
88 | for( iFileSpec=1:length(InputFileSpec) )
89 | FilePattern = InputFileSpec{iFileSpec};
90 | for( iFolder = 1:length(FolderList) )
91 |
92 | %---Search each subfolder for raw lenslet files---
93 | CurFolder = FolderList{iFolder};
94 | CurDirList = dir(fullfile(CurFolder, FilePattern));
95 |
96 | CurDirList = CurDirList(~[CurDirList.isdir]);
97 | CurDirList = {CurDirList.name};
98 | PerFolderFiles{iFolder} = [PerFolderFiles{iFolder}, CurDirList];
99 |
100 | % Prepend the current folder name for a complete path to each file
101 | % but fist strip off the leading InputPath so that all files are expressed relative to InputPath
102 | CurFolder = CurFolder(length(InputPath)+1:end);
103 | while( ~isempty(CurFolder) && CurFolder(1) == filesep )
104 | CurFolder = CurFolder(2:end);
105 | end
106 |
107 | CurDirList = cellfun(@(Fname) fullfile(CurFolder, Fname), CurDirList, 'UniformOutput',false);
108 |
109 | AllFiles = [AllFiles; CurDirList'];
110 |
111 | end
112 | end
113 |
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/SetAxis.m:
--------------------------------------------------------------------------------
1 | function Matrix=SetAxis(Params)
2 |
3 | Matrix=diag([1,1,1,1]);
4 | r=[Params(1),Params(2),Params(3)];
5 | b=sqrt(r*r');
6 | if b~=0
7 | B=1/b;
8 | x=Params(1)*B;
9 | y=Params(2)*B;
10 | z=Params(3)*B;
11 | sinb=sin(b);
12 | cosb=1-cos(b);
13 | Matrix(1,1)=1-(y*y+z*z)*cosb;
14 | Matrix(1,2)=-z*sinb+x*y*cosb;
15 | Matrix(1,3)=y*sinb+x*z*cosb;
16 | Matrix(2,1)=z*sinb+x*y*cosb;
17 | Matrix(2,2)=1-(x*x+z*z)*cosb;
18 | Matrix(2,3)=-x*sinb+y*z*cosb;
19 | Matrix(3,1)=-y*sinb+x*z*cosb;
20 | Matrix(3,2)=x*sinb+y*z*cosb;
21 | Matrix(3,3)=1-(x*x+y*y)*cosb;
22 | end
23 | Matrix(1,4)=Params(4);
24 | Matrix(2,4)=Params(5);
25 | Matrix(3,4)=Params(6);
26 |
27 | end
28 |
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/SetAxisSam.m:
--------------------------------------------------------------------------------
1 | function Matrix=SetAxisSam(Params)
2 | gelma = Params(1);
3 | theta = Params(2);
4 | faile = Params(3);
5 | cos_gelma = cos(gelma);
6 | sin_gelma = sin(gelma);
7 | cos_theta = cos(theta);
8 | sin_theta = sin(theta);
9 | cos_faile = cos(faile);
10 | sin_faile = sin(faile);
11 |
12 | Matrix = zeros(4,4);
13 | Matrix(1,1) = cos_theta*cos_faile;
14 | Matrix(1,2) = sin_gelma*sin_theta*cos_faile - cos_gelma*sin_faile;
15 | Matrix(1,3) = cos_gelma*sin_theta*cos_faile + sin_gelma*sin_faile;
16 | Matrix(2,1) = cos_theta*sin_faile;
17 | Matrix(2,2) = sin_gelma*sin_theta*sin_faile + cos_gelma*cos_faile;
18 | Matrix(2,3) = cos_gelma*sin_theta*sin_faile - sin_gelma*cos_faile;
19 | Matrix(3,1) = -sin_theta;
20 | Matrix(3,2) = sin_gelma*cos_theta;
21 | Matrix(3,3) = cos_gelma*cos_theta;
22 |
23 | Matrix(1,4)=Params(4);
24 | Matrix(2,4)=Params(5);
25 | Matrix(3,4)=Params(6);
26 |
27 | Matrix(4,4)=1;
28 | end
29 |
--------------------------------------------------------------------------------
/MyPlenopticTool/Utility/xml2struct.m:
--------------------------------------------------------------------------------
1 | function theStruct = xml2struct(filename)
2 | % XML2STRUCT Convert an XML file into a MATLAB structure.
3 |
4 | % Copyright 2003-2007 The MathWorks, Inc.
5 |
6 |
7 | % Based on an idea by Douglas M. Schwarz, Eastman Kodak Company
8 |
9 | try
10 | tree = xmlread(filename);
11 | catch
12 | error(message('bioinfo:xml2struct:FileReadError', filename));
13 | end
14 |
15 | % Recurse over child nodes
16 | % This could run into problems with very deeply nested trees...
17 | try
18 | theStruct = parseChildNodes(tree);
19 | catch
20 | error(message('bioinfo:xml2struct:XMLParseError', filename));
21 | end
22 |
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 | function nodeStruct = makeStructFromNode(theNode)
25 |
26 | nodeStruct = struct('Name',char(theNode.getNodeName),...
27 | 'Attributes',parseAttributes(theNode),'Data','',...
28 | 'Children',parseChildNodes(theNode));
29 |
30 | if any(strcmp(methods(theNode),'getData'))
31 | nodeStruct.Data = char(theNode.getData);
32 | else
33 | nodeStruct.Data = '';
34 | end
35 |
36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 | function attributes = parseAttributes(theNode)
38 | % Create attributes struct
39 | attributes = [];
40 | if theNode.hasAttributes
41 | theAttributes = theNode.getAttributes;
42 | numAttributes = theAttributes.getLength;
43 | allocCell = cell(1,numAttributes);
44 | attributes = struct('Name',allocCell,'Value',allocCell);
45 | for count = 1:numAttributes
46 | attrib = theAttributes.item(count-1);
47 | attributes(count).Name = char(attrib.getName);
48 | attributes(count).Value = char(attrib.getValue);
49 | end
50 | end
51 |
52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 | function children = parseChildNodes(theNode)
54 | % Recurse over node children
55 | children = [];
56 | if theNode.hasChildNodes
57 | childNodes = theNode.getChildNodes;
58 | numChildNodes = childNodes.getLength;
59 | allocCell = cell(1,numChildNodes);
60 | children = struct('Name',allocCell,'Attributes',allocCell,...
61 | 'Data',allocCell,'Children',allocCell);
62 | for count = 1:numChildNodes
63 | theChild = childNodes.item(count-1);
64 | children(count) = makeStructFromNode(theChild);
65 | end
66 | end
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Light-Field-Simulation
2 |
3 | # Installation
4 | Run the manuscript AddToolboxPath.m in folder MyPlenopticTool.
5 |
6 | # Demo
7 | There are two demos for simulation of plenoptic cameras(focused and unfocused).
8 |
9 | Run RunSimulateLytroImage.m to simulate the imaging process of Lytro.
10 |
11 | Run RunSimulateRaytrixImage.m to simulate the imaging process of Raytrix.
12 |
13 | # Simulated Image Size
14 | You can change the simulated image size in Line 48 and 49 of RunSimulateRaytrixImage.m.
15 |
16 | `
17 | InfoBag.pixelY = 70;
18 | InfoBag.pixelX = 70;
19 | `
20 |
21 | You can also change the simulated image size in Line 76 and 77 of RunSimulateLytroImage.m.
22 |
23 | `
24 | InfoBag.pixelY = 100;
25 | InfoBag.pixelX = 100;
26 | `
27 |
--------------------------------------------------------------------------------