source: trunk/src/get_file_info.m @ 1035

Last change on this file since 1035 was 1033, checked in by sommeria, 6 years ago

miscellaneous updates

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