source: trunk/src/readCineHeader.m @ 1116

Last change on this file since 1116 was 993, checked in by sommeria, 8 years ago

various updates

File size: 5.2 KB
Line 
1function [CineFileHeader, BitmapInfoHeader, CameraSetup, TimeOnlyBlock, ExposureOnlyBlock, TimeCodeBlock, imageLocations,  annotationSize] = readCineHeader(filePath)
2
3fid = fopen(filePath);
4
5CineFileHeader.Type = fread(fid, 1, 'uint16');
6CineFileHeader.Headersize = fread(fid, 1, 'uint16');
7CineFileHeader.Compression = fread(fid, 1, 'uint16');
8CineFileHeader.Version = fread(fid, 1, 'uint16');
9CineFileHeader.FirstMovieImage = fread(fid, 1, 'int32');
10CineFileHeader.TotalImageCount = fread(fid, 1, 'uint32');
11CineFileHeader.FirstImageNo = fread(fid, 1, 'int32');
12CineFileHeader.ImageCount = fread(fid, 1, 'uint32');
13CineFileHeader.OffImageHeader = fread(fid, 1, 'uint32');
14CineFileHeader.OffSetup = fread(fid, 1, 'uint32');
15CineFileHeader.OffImageOffsets = fread(fid, 1, 'uint32');
16CineFileHeader.TriggerTime = fread(fid, 1, 'uint64')/2^32; % Epoch time (secs since jan 1, 1970)
17%CineFileHeader.TriggerTime2 = fread(fid, 1, 'uint32');
18
19BitmapInfoHeader.biSize = fread(fid, 1, 'int32');
20BitmapInfoHeader.biWidth = fread(fid, 1, 'int32');
21BitmapInfoHeader.biHeight = fread(fid, 1, 'int32');
22BitmapInfoHeader.biPlanes = fread(fid, 1, 'uint16');
23BitmapInfoHeader.biBitCount = fread(fid, 1, 'uint16');
24BitmapInfoHeader.biCompression = fread(fid, 1, 'uint32');
25BitmapInfoHeader.biSizeImage = fread(fid, 1, 'uint32');
26BitmapInfoHeader.biXPelsPerMeter= fread(fid, 1, 'uint32');
27BitmapInfoHeader.biYPelsPerMeter= fread(fid, 1, 'int32');
28BitmapInfoHeader.biClrUsed = fread(fid, 1, 'uint32');
29BitmapInfoHeader.biClrImportant = fread(fid, 1, 'uint32');
30
31fseek(fid, hex2dec('00E2'), 'bof');
32CameraSetup.Length = fread(fid, 1, 'uint16');
33
34fseek(fid, hex2dec('0370'), 'bof');
35CameraSetup.FirmwareVersion = fread(fid, 1, 'uint32');
36
37fseek(fid, hex2dec('0374'), 'bof');
38CameraSetup.SoftwareVersion = fread(fid, 1, 'uint32');
39
40fseek(fid, hex2dec('0354'), 'bof');
41CameraSetup.FrameRate = fread(fid, 1, 'uint32');
42
43fseek(fid, hex2dec('0360'), 'bof');
44CameraSetup.PostTrigger = fread(fid, 1, 'uint32');
45
46fseek(fid, hex2dec('03D4'), 'bof');
47CameraSetup.RealBPP = fread(fid, 1, 'uint32');
48
49fseek(fid, hex2dec('16B8'), 'bof');
50CameraSetup.BlackLevel = fread(fid, 1, 'uint32');
51
52fseek(fid, hex2dec('16BC'), 'bof');
53CameraSetup.WhiteLevel = fread(fid, 1, 'uint32');
54
55fseek(fid, hex2dec('1B48'), 'bof');
56CameraSetup.fGain16_8 = fread(fid, 1, 'float32');
57
58fseek(fid, hex2dec('17CC'), 'bof');
59CameraSetup.fOffset = fread(fid, 1, 'float32');
60
61fseek(fid, hex2dec('17D0'), 'bof');
62CameraSetup.fGain = fread(fid, 1, 'float32');
63
64fseek(fid, hex2dec('17DC'), 'bof');
65CameraSetup.fGamma = fread(fid, 1, 'float32');
66
67fseek(fid, hex2dec('27D4'), 'bof');
68CameraSetup.RecBPP = fread(fid, 1, 'uint32');
69
70
71%% Tagged Information Blocks
72% AnalogDigitalSignals (ADS) -> not contained in MIRO cine-files
73% ImageTimeTaggedBlock (ITTB) -> not contained in MIRO cine-files
74
75% TimeOnlyBlock (TOB) -> Type should be 1002
76PositionTOB = CineFileHeader.OffSetup + CameraSetup.Length;
77fseek(fid, PositionTOB , 'bof');
78TimeOnlyBlock.Length = fread(fid, 1, 'uint32');
79TimeOnlyBlock.Type = fread(fid, 1, 'uint16');
80TimeOnlyBlock.Reserved = fread(fid, 1, 'uint16');
81TimeOnlyBlock.Data = transpose([1:CineFileHeader.ImageCount ; fread(fid,[2,CineFileHeader.ImageCount], 'uint32')]); % Framenumber combined with Data contained in TOB
82TimeOnlyBlock.TimestampsDatetime = datetime(TimeOnlyBlock.Data(:,3), 'ConvertFrom', 'posixtime');  % Timestamp as Datetime
83% TimeOnlyBlock.TimestampsDatestr = datestr(TimeOnlyBlock.TimestampsDatetime);  % Timestamp as String
84TimeOnlyBlock.TimestampsMillisec = TimeOnlyBlock.Data(:,2)./(2^32);    % Milliseconds of the Timestamp
85TimeOnlyBlock.ExposureTimeDelays = [0 ; TimeOnlyBlock.TimestampsMillisec(2:end)-TimeOnlyBlock.TimestampsMillisec(1:end-1)]; % Timedifference between two frames. First frame is set to have no timedifference
86
87% ExposureOnlyBlock (EOB) -> Type should be 1003
88PositionEOB = PositionTOB + TimeOnlyBlock.Length;
89fseek(fid, PositionEOB , 'bof');
90ExposureOnlyBlock.Length = fread(fid, 1, 'uint32');
91ExposureOnlyBlock.Type = fread(fid, 1, 'uint16');
92ExposureOnlyBlock.Reserved = fread(fid, 1, 'uint16');
93ExposureOnlyBlock.Data = fread(fid,CineFileHeader.ImageCount, 'uint32');
94ExposureOnlyBlock.ExposureTimesMillisec = ExposureOnlyBlock.Data ./(2^32) .*1000;
95ExposureOnlyBlock.test1 = fread(fid, 1, 'uint32');
96ExposureOnlyBlock.test2 = fread(fid, 1, 'uint16');
97ExposureOnlyBlock.test3 = fread(fid, 1, 'uint16');
98
99% RangeDataBlock (RDB) -> not contained in MIRO cine-files
100% BinSigBlock (BSB) -> not contained in MIRO cine-files
101% AnaSigBlock (ASB) -> not contained in MIRO cine-files
102
103% TimeCodeBlock (TCB)  -> Type should be 1007
104PositionTCB = PositionEOB + ExposureOnlyBlock.Length;
105fseek(fid, PositionTCB , 'bof');
106TimeCodeBlock.Length = fread(fid, 1, 'uint32');
107TimeCodeBlock.Type = fread(fid, 1, 'uint16');
108TimeCodeBlock.Reserved = fread(fid, 1, 'uint16');
109TimeCodeBlock.Data = fread(fid, 1, 'uint8');
110
111
112%% Image Locations and their Annotations
113fseek(fid, CineFileHeader.OffImageOffsets, 'bof');
114imageBlockLocations = fread(fid, CineFileHeader.ImageCount, 'int64');
115
116fseek(fid, imageBlockLocations(1), 'bof');
117annotationSize = fread(fid, 1, 'uint32');
118
119imageLocations = imageBlockLocations + annotationSize;
120
121
122%%
123fclose(fid);
Note: See TracBrowser for help on using the repository browser.