1 | %'get_file_info': determine info about a file (image, multimage, civdata,...) . |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
4 | % |
---|
5 | % OUTPUT: |
---|
6 | % FileInfo: structure containing info on the file (case of images or video), in particular |
---|
7 | % .FileType: type of file, needed as input of read_field.m |
---|
8 | % ='figure': Matlab figure |
---|
9 | % ='xml': xml file |
---|
10 | % ='xls': Excel file |
---|
11 | % ='dat': text file for data, |
---|
12 | % ='image': image format recognised by Matlab |
---|
13 | % ='multimage': image format recognised by Matlab with multiple frames |
---|
14 | % ='video': video movie file |
---|
15 | % ='mmreader': video from old versions of Matlab (<2009) |
---|
16 | % ='rdvision': images in binary format from company rdvision |
---|
17 | % ='image_DaVis': images from softwar DaVis (company LaVision) |
---|
18 | % ='cine_phantom': images from fast camera Phantom |
---|
19 | % ='bin': binary file without specific organisation |
---|
20 | % ='netcdf': netcdf file |
---|
21 | % ='civdata': netcdf files provided by civ_series |
---|
22 | % ='civx': netcdf files provided by the obsolete program civx (in fortran) |
---|
23 | % ='pivdata_fluidimage': PIV data from software 'fluidimage' |
---|
24 | % .FieldType='image' for all kinds of images and movies, =FileType else |
---|
25 | % .FileIndexing='on'/'off', for data files (when series of indexed files are expected) |
---|
26 | % .Height: image height in pixels |
---|
27 | % .Width: image width in pixels |
---|
28 | % .BitDepth: nbre of bits per pixel (8 of 16) |
---|
29 | % .ColorType: 'greyscale' or 'color' |
---|
30 | % .NumberOfFrames: defined for images or movies |
---|
31 | % .FrameRate: nbre of frames per second, =[] for images |
---|
32 | % VideoObject: in case of video |
---|
33 | % |
---|
34 | % INPUT: |
---|
35 | % fileinput: name, including path, of the file to analyse |
---|
36 | |
---|
37 | %======================================================================= |
---|
38 | % Copyright 2008-2020, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
39 | % http://www.legi.grenoble-inp.fr |
---|
40 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
41 | % |
---|
42 | % This file is part of the toolbox UVMAT. |
---|
43 | % |
---|
44 | % UVMAT is free software; you can redistribute it and/or modify |
---|
45 | % it under the terms of the GNU General Public License as published |
---|
46 | % by the Free Software Foundation; either version 2 of the license, |
---|
47 | % or (at your option) any later version. |
---|
48 | % |
---|
49 | % UVMAT is distributed in the hope that it will be useful, |
---|
50 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
51 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
52 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
53 | %======================================================================= |
---|
54 | |
---|
55 | function [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
56 | VideoObject=[]; |
---|
57 | FileInfo.FileType='';% input file does not exist |
---|
58 | FileInfo.FieldType=''; %default output |
---|
59 | % check the existence (not possible for OpenDAP data) |
---|
60 | if ~isempty(regexp(fileinput,'^http://'))|| exist(fileinput,'file') |
---|
61 | FileInfo.FileName=fileinput; |
---|
62 | FileInfo.FileType='txt'; %default |
---|
63 | else |
---|
64 | return %input file does not exist. |
---|
65 | end |
---|
66 | [tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt |
---|
67 | |
---|
68 | switch FileExt |
---|
69 | case '.fig' |
---|
70 | FileInfo.FileType='figure'; |
---|
71 | case '.mat' |
---|
72 | FileInfo.FileType='mat'; |
---|
73 | case {'.xml','.xls','.dat','.bin'} |
---|
74 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
75 | case {'.seq','.sqb'} |
---|
76 | [A,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]); |
---|
77 | case '.im7' |
---|
78 | try |
---|
79 | Input=readimx(fileinput); |
---|
80 | Image=Input.Frames{1}.Components{1}.Planes{1}; |
---|
81 | FileInfo.FileType='image_DaVis'; |
---|
82 | FileInfo.NumberOfFrames=numel(Input.Frames); |
---|
83 | FileInfo.Height=size(Image,2); |
---|
84 | FileInfo.Width=size(Image,1); |
---|
85 | FileInfo.TimeName='timestamp'; |
---|
86 | for ilist=1:numel(Input.Attributes) |
---|
87 | if strcmp(Input.Attributes{ilist}.Name,'_Date') |
---|
88 | DateString=Input.Attributes{ilist}.Value; |
---|
89 | end |
---|
90 | if strcmp(Input.Attributes{ilist}.Name,'_Time') |
---|
91 | TimeString=Input.Attributes{ilist}.Value; |
---|
92 | end |
---|
93 | end |
---|
94 | catch ME |
---|
95 | msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is possible only with Matlab version 2013 or earlier'}) |
---|
96 | return |
---|
97 | end |
---|
98 | case '.h5' |
---|
99 | hinfo=hdf5info(fileinput); |
---|
100 | if strcmp(hinfo.GroupHierarchy.Attributes(1).Value.Data,'MultipassPIVResults') |
---|
101 | FileInfo.FileType='pivdata_fluidimage'; |
---|
102 | FileInfo.CivStage=6; % A MODIFIER |
---|
103 | end |
---|
104 | case '.cine' |
---|
105 | [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput); |
---|
106 | FileInfo.FileType='cine_phantom'; |
---|
107 | FileInfo.NumberOfFrames=FileInfo.ImageCount; |
---|
108 | FileInfo.FrameRate=CameraSetup.FrameRate; |
---|
109 | FileInfo.Height=BitmapInfoHeader.biHeight; |
---|
110 | FileInfo.Width=BitmapInfoHeader.biWidth; |
---|
111 | FileInfo.BitDepth=BitmapInfoHeader.biBitCount; |
---|
112 | FileInfo.TimeName='video'; |
---|
113 | otherwise |
---|
114 | if ~isempty(FileExt)% exclude empty extension |
---|
115 | FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension |
---|
116 | if ~isempty(FileExt) |
---|
117 | if ~isempty(imformats(FileExt))%case of images |
---|
118 | try |
---|
119 | imainfo=imfinfo(fileinput); |
---|
120 | if length(imainfo) >1 %case of image with multiple frames |
---|
121 | FileInfo=imainfo(1);%take info from the first frame |
---|
122 | FileInfo.NumberOfFrames=length(imainfo); |
---|
123 | FileInfo.FileType='multimage'; |
---|
124 | else |
---|
125 | FileInfo=imainfo; |
---|
126 | FileInfo.NumberOfFrames=1; |
---|
127 | FileInfo.FileType='image'; |
---|
128 | end |
---|
129 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
130 | nbfield=numel(fieldnames(FileInfo)); |
---|
131 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
132 | end |
---|
133 | else |
---|
134 | error_nc=0; |
---|
135 | try |
---|
136 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
137 | if ~isempty(errormsg) |
---|
138 | error_nc=1; |
---|
139 | else |
---|
140 | if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
141 | FileInfo.FileType='civx'; |
---|
142 | if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
143 | FileInfo.CivStage=6; |
---|
144 | elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
145 | FileInfo.CivStage=5; |
---|
146 | elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
147 | FileInfo.CivStage=4; |
---|
148 | elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
149 | FileInfo.CivStage=3; |
---|
150 | elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
151 | FileInfo.CivStage=2; |
---|
152 | else |
---|
153 | FileInfo.CivStage=1; |
---|
154 | end |
---|
155 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
156 | FileInfo.FileType='civdata'; % test for civx velocity fields |
---|
157 | FileInfo.CivStage=Data.CivStage; |
---|
158 | else |
---|
159 | FileInfo.FileType='netcdf'; |
---|
160 | FileInfo.ListVarName=Data.ListVarName; |
---|
161 | end |
---|
162 | end |
---|
163 | catch ME |
---|
164 | error_nc=1; |
---|
165 | end |
---|
166 | if error_nc |
---|
167 | try |
---|
168 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
169 | VideoObject=VideoReader(fileinput); |
---|
170 | FileInfo=get(VideoObject); |
---|
171 | FileInfo.FileType='video'; |
---|
172 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
173 | VideoObject=mmreader(fileinput); |
---|
174 | FileInfo=get(VideoObject); |
---|
175 | FileInfo.FileType='mmreader'; |
---|
176 | end |
---|
177 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
178 | FileInfo.ColorType='truecolor'; |
---|
179 | FileInfo.TimeName='video'; |
---|
180 | FileInfo.FileName=fileinput; |
---|
181 | nbfield=numel(fieldnames(FileInfo)); |
---|
182 | FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity |
---|
183 | if ~isfield(FileInfo,'NumberOfFrames') |
---|
184 | FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate); |
---|
185 | end |
---|
186 | end |
---|
187 | end |
---|
188 | end |
---|
189 | end |
---|
190 | end |
---|
191 | end |
---|
192 | |
---|
193 | if ismember (FileInfo.FileType,{'image','image_DaVis','multimage','mmreader','cine_phantom','video','netcdf','civdata'}) |
---|
194 | FileInfo.FileIndexing='on'; % allow to detect file index for scanning series |
---|
195 | else |
---|
196 | FileInfo.FileIndexing='off'; |
---|
197 | end |
---|
198 | FileInfo.FieldType=FileInfo.FileType;%default |
---|
199 | switch FileInfo.FileType |
---|
200 | case {'image','multimage','video','mmreader','rdvision','image_DaVis','cine_phantom'} |
---|
201 | FileInfo.FieldType='image'; |
---|
202 | case {'civx','civdata','pivdata_fluidimage'} |
---|
203 | FileInfo.FieldType='civdata'; |
---|
204 | end |
---|
205 | |
---|