-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCaptureFrames.m
91 lines (70 loc) · 2.54 KB
/
CaptureFrames.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
clear all; close all;
%%%% This routine captures an image sequence from a Princeton Instruments Camera by calling an executeable which uses the PICAM Library.
%%%% We pass several parameters to the executeable:
%%%% FileDir --- The directory in which to save the image files
%%%% FileName --- The filename to save as
%%%% int2str(x0) --- The start pixel in the x-direction (relevant for using ROI).
%%%% int2str(y0) --- The start pixel in the y-direction (relevant for using ROI).
%%%% int2str(dx) --- The width in x-direction (relevant for using ROI).
%%%% int2str(dy) --- The width in y-direction (relevant for using ROI).
%%%% num2str(DT) --- The exposure time in milliseconds
%%%% int2str(NFrames)] --- The number of frames to capture
display(['Beginning acquisition at: ' datestr(now,'yyyy-mm-dd HH:MM:SS')]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Image Acquisition Params %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ROI Parameters
tic;
dx = 1024;
dy = 1024;
x0 = 0;
y0 = 0;
% Number of Frames
NFrames = 5;
% Exposure time in msec
DT = 6;
%%%%%%%%%%%%%%%
%%% Options %%%
%%%%%%%%%%%%%%%
%% Create Tiff File
% Default: do not create tiff file (to save disk space)
% In the future you may want to create TIFFs for compatibility reason. Or
% modify the executeable to save TIFFs (not sure how to do that yet).
CreateTiffFile = true;
%% Display Images
% Default: do not display images (allow processing function to display
% images)
DisplayImages = false;
CheckNoise = false;
%% File Naming Parameters
today = datestr(now,'yyyy-mm-dd');
year = datestr(now,'yyyy');
RootFileDir = ['C:\SPECIFY ROOT DIRECTORY TO SAVE YOUR DATA HERE\' year '\'];
FileDir = [RootFileDir today '\'];
%%%%%%%%%%%%%%%%%
%%% Execution %%%
%%%%%%%%%%%%%%%%%
%%%
% Determine file name
%%%
[ FileName TiffName FilePath TiffPath filenamecounter] = NewFilePath( FileDir );
display(['Waiting for acquisition of ' FilePath]);
doscmd = ['start /MIN CaptureFrames.bat ' FileDir ' ' FileName ' ' int2str(x0) ' ' int2str(y0) ' ' int2str(dx) ' ' int2str(dy) ' ' num2str(DT) ' ' int2str(NFrames)];
[status,stdout] = dos(doscmd);
disp('Waiting for file to arrive... ')
while(exist(FilePath) == 0)
pause(0.75)
end
% Load raw data into Matlab.
FileID = fopen(FilePath);
for kk = 1:NFrames
ImageMatrix(:,:,kk) = fread(FileID, [dx, dy], '*uint16')';
end
fclose(FileID);
% Optionally write TIFF file
if(CreateTiffFile)
for kk = 1:NFrames
imwrite(ImageMatrix(:,:,kk),TiffPath,'writemode','append');
end
end
display(['Completed acquisition of ' TiffName ' at: ' datestr(now,'yyyy-mm-dd HH:MM:SS')]);