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-2019, 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 {'.xml','.xls','.dat','.bin'} |
---|
72 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
73 | case {'.seq','.sqb'} |
---|
74 | [A,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]); |
---|
75 | case '.im7' |
---|
76 | try |
---|
77 | Input=readimx(fileinput); |
---|
78 | Image=Input.Frames{1}.Components{1}.Planes{1}; |
---|
79 | FileInfo.FileType='image_DaVis'; |
---|
80 | FileInfo.NumberOfFrames=numel(Input.Frames); |
---|
81 | FileInfo.Height=size(Image,2); |
---|
82 | FileInfo.Width=size(Image,1); |
---|
83 | FileInfo.TimeName='timestamp'; |
---|
84 | for ilist=1:numel(Input.Attributes) |
---|
85 | if strcmp(Input.Attributes{ilist}.Name,'_Date') |
---|
86 | DateString=Input.Attributes{ilist}.Value; |
---|
87 | end |
---|
88 | if strcmp(Input.Attributes{ilist}.Name,'_Time') |
---|
89 | TimeString=Input.Attributes{ilist}.Value; |
---|
90 | end |
---|
91 | end |
---|
92 | catch ME |
---|
93 | msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is possible only with Matlab version 2013 or earlier'}) |
---|
94 | return |
---|
95 | end |
---|
96 | case '.h5' |
---|
97 | hinfo=hdf5info(fileinput); |
---|
98 | if strcmp(hinfo.GroupHierarchy.Attributes(1).Value.Data,'MultipassPIVResults') |
---|
99 | FileInfo.FileType='pivdata_fluidimage'; |
---|
100 | FileInfo.CivStage=6; % A MODIFIER |
---|
101 | end |
---|
102 | case '.cine' |
---|
103 | [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput); |
---|
104 | FileInfo.FileType='cine_phantom'; |
---|
105 | FileInfo.NumberOfFrames=FileInfo.ImageCount; |
---|
106 | FileInfo.FrameRate=CameraSetup.FrameRate; |
---|
107 | FileInfo.Height=BitmapInfoHeader.biHeight; |
---|
108 | FileInfo.Width=BitmapInfoHeader.biWidth; |
---|
109 | FileInfo.BitDepth=BitmapInfoHeader.biBitCount; |
---|
110 | FileInfo.TimeName='video'; |
---|
111 | otherwise |
---|
112 | if ~isempty(FileExt)% exclude empty extension |
---|
113 | FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension |
---|
114 | if ~isempty(FileExt) |
---|
115 | if ~isempty(imformats(FileExt))%case of images |
---|
116 | try |
---|
117 | imainfo=imfinfo(fileinput); |
---|
118 | if length(imainfo) >1 %case of image with multiple frames |
---|
119 | FileInfo=imainfo(1);%take info from the first frame |
---|
120 | FileInfo.NumberOfFrames=length(imainfo); |
---|
121 | FileInfo.FileType='multimage'; |
---|
122 | else |
---|
123 | FileInfo=imainfo; |
---|
124 | FileInfo.NumberOfFrames=1; |
---|
125 | FileInfo.FileType='image'; |
---|
126 | end |
---|
127 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
128 | nbfield=numel(fieldnames(FileInfo)); |
---|
129 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
130 | end |
---|
131 | else |
---|
132 | error_nc=0; |
---|
133 | try |
---|
134 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
135 | if ~isempty(errormsg) |
---|
136 | error_nc=1; |
---|
137 | else |
---|
138 | if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
139 | FileInfo.FileType='civx'; |
---|
140 | if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
141 | FileInfo.CivStage=6; |
---|
142 | elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
143 | FileInfo.CivStage=5; |
---|
144 | elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
145 | FileInfo.CivStage=4; |
---|
146 | elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
147 | FileInfo.CivStage=3; |
---|
148 | elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
149 | FileInfo.CivStage=2; |
---|
150 | else |
---|
151 | FileInfo.CivStage=1; |
---|
152 | end |
---|
153 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
154 | FileInfo.FileType='civdata'; % test for civx velocity fields |
---|
155 | FileInfo.CivStage=Data.CivStage; |
---|
156 | else |
---|
157 | FileInfo.FileType='netcdf'; |
---|
158 | FileInfo.ListVarName=Data.ListVarName; |
---|
159 | end |
---|
160 | end |
---|
161 | catch ME |
---|
162 | error_nc=1; |
---|
163 | end |
---|
164 | if error_nc |
---|
165 | try |
---|
166 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
167 | VideoObject=VideoReader(fileinput); |
---|
168 | FileInfo=get(VideoObject); |
---|
169 | FileInfo.FileType='video'; |
---|
170 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
171 | VideoObject=mmreader(fileinput); |
---|
172 | FileInfo=get(VideoObject); |
---|
173 | FileInfo.FileType='mmreader'; |
---|
174 | end |
---|
175 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
176 | FileInfo.ColorType='truecolor'; |
---|
177 | FileInfo.TimeName='video'; |
---|
178 | FileInfo.FileName=fileinput; |
---|
179 | nbfield=numel(fieldnames(FileInfo)); |
---|
180 | FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity |
---|
181 | if ~isfield(FileInfo,'NumberOfFrames') |
---|
182 | FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate); |
---|
183 | end |
---|
184 | end |
---|
185 | end |
---|
186 | end |
---|
187 | end |
---|
188 | end |
---|
189 | end |
---|
190 | |
---|
191 | if ismember (FileInfo.FileType,{'image','image_DaVis','multimage','mmreader','cine_phantom','video','netcdf','civdata'}) |
---|
192 | FileInfo.FileIndexing='on'; % allow to detect file index for scanning series |
---|
193 | else |
---|
194 | FileInfo.FileIndexing='off'; |
---|
195 | end |
---|
196 | FileInfo.FieldType=FileInfo.FileType;%default |
---|
197 | switch FileInfo.FileType |
---|
198 | case {'image','multimage','video','mmreader','rdvision','image_DaVis','cine_phantom'} |
---|
199 | FileInfo.FieldType='image'; |
---|
200 | case {'civx','civdata','pivdata_fluidimage'} |
---|
201 | FileInfo.FieldType='civdata'; |
---|
202 | end |
---|
203 | |
---|