forked from jdieringer/LightField-in-MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlfm.m
102 lines (96 loc) · 4.1 KB
/
lfm.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
classdef (ConstructOnLoad = true) lfm
properties (Access = public)
automation;
addinbase;
application;
experiment;
end
methods
function out = lfm(visible)
out.addinbase = PrincetonInstruments.LightField.AddIns.AddInBase();
out.automation = PrincetonInstruments.LightField.Automation.Automation(visible,[]);
out.application = out.automation.LightFieldApplication;
out.experiment = out.application.Experiment;
end
function close(obj)
obj.automation.Dispose();
end
function set(obj,setting,value)
if obj.experiment.Exists(setting)
if obj.experiment.IsValid(setting,value)
obj.experiment.SetValue(setting,value);
else
disp('value not valid')
end
else
disp('operation not found/defined');
end
end
function return_value = get(obj,setting)
if obj.experiment.Exists(setting)
return_value = obj.experiment.GetValue(setting);
end
end
function load_experiment(obj,value)
obj.experiment.Load(value);
end
function set_exposure(obj,value)
obj.set(PrincetonInstruments.LightField.AddIns.CameraSettings.ShutterTimingExposureTime,value);
end
function set_frames(obj,value)
obj.set(PrincetonInstruments.LightField.AddIns.ExperimentSettings.FrameSettingsFramesToStore,value);
end
function [data, wavelength] = acquire(obj)
import System.IO.FileAccess;
obj.experiment.Acquire();
accessed_wavelength = 0;
while obj.experiment.IsRunning % During acquisition...
% Case where wavelength is empty
if accessed_wavelength == 0 && isempty(obj.experiment.SystemColumnCalibration)
fprintf('Wavelength information not available\n');
wavelength = [];
accessed_wavelength = 1;
elseif accessed_wavelength == 0
wavelen_len = obj.experiment.SystemColumnCalibration.Length;
assert(wavelen_len >= 1);
wavelength = zeros(wavelen_len, 1);
for i = 0:wavelen_len-1 % load wavelength info directly from LightField instance
wavelength(i+1) = obj.experiment.SystemColumnCalibration.Get(i);
end
accessed_wavelength = 1;
end
end
lastfile = obj.application.FileManager.GetRecentlyAcquiredFileNames.GetItem(0);
imageset = obj.application.FileManager.OpenFile(lastfile,FileAccess.Read);
if imageset.Regions.Length == 1
if imageset.Frames == 1
frame = imageset.GetFrame(0,0);
data = reshape(frame.GetData().double,frame.Width,frame.Height)';
return;
else
data = [];
for i = 0:imageset.Frames-1
frame = imageset.GetFrame(0,i);
data = cat(3,data,reshape(frame.GetData().double,frame.Width,frame.Height,1)');
end
return;
end
else
data = cell(imageset.Regions.Length,1);
for j = 0:imageset.Regions.Length-1
if imageset.Frames == 1
frame = imageset.GetFrame(j,0);
buffer = reshape(frame.GetData().double,frame.Width,frame.Height)';
else
buffer = [];
for i = 0:imageset.Frames-1
frame = imageset.GetFrame(j,i);
buffer = cat(3,buffer,reshape(frame.GetData().double,frame.Width,frame.Height,1)');
end
end
data{j+1} = buffer;
end
end
end
end
end