-
Notifications
You must be signed in to change notification settings - Fork 0
/
nd2open.m
39 lines (31 loc) · 1001 Bytes
/
nd2open.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
function [data,dt,fname]=nd2open(source)
% Nikon ND2 READER
% Rafael Jaimes, PhD
% 2016-04-29
% 2018-07-24 - updated to take a path in the filename
switch nargin
case 0 % source was unspecified
[fname,pname]=uigetfile({'*.nd2'},'Select a Nikon .nd2 file','');
source=[pname,fname];
case 1 % file source was specified
fname=[]; % these output vars will be blank, since source was specified
pname=[]; % these output vars will be blank, since source was specified
end
addpath(genpath('dependencies'))
header = bfopen(source);
first=header{1,1}(1,1);
nframes=length(header{1,1}(:,1));
xy=size(first{1,1});
data=zeros(xy(1),xy(2),nframes);
metadata=header{1,2};
time2 = metadata.get('timestamp #0002');
time1 = metadata.get('timestamp #0001');
if isempty(time1)
time2 = metadata.get('timestamp #00002');
time1 = metadata.get('timestamp #00001');
end
dt=time2-time1;
for p=1:nframes
predata=header{1,1}(p,1);
data(:,:,p)=predata{1,1};
end