source: trunk/src/get_file_info.m @ 1198

Last change on this file since 1198 was 1196, checked in by sommeria, 4 days ago

bugs repaired

File size: 14.2 KB
Line 
1%'gext_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%     .FileName: confirms the file name, ='' if the file is not detected 
8%     .FileType: type of file, needed as input of read_field.m
9%               ='': unknown format
10%               ='bin': binary file without specific organisation
11%               ='dat': text file for data
12%               ='figure': Matlab figure file, ext .fig
13%               ='mat': Matlab data file
14%               ='netcdf': generic netcdf file
15%               ='xml': xml file
16%               ='xls': Excel file
17%               ='civdata': netcdf files provided by civ_series
18%               ='pivdata_fluidimage': PIV data from software 'fluidimage'
19%   different image and movie formats:
20%               ='image': image format recognised by Matlab
21%               ='multimage': image format recognised by Matlab with  multiple frames
22%               ='video': video movie file
23%               ='mmreader': video from old versions of Matlab (<2009)
24%               ='rdvision': images in binary format from company rdvision
25%               ='image_DaVis': images from softwar DaVis (company LaVision), requires specific conditions of Matlab version and computer system
26%               ='cine_phantom': images from fast camera Phantom
27%               ='telopsIR': Infrared images from  company Telops
28%      .FieldType='image' for all kinds of images and movies, =FileType  else
29%      .FileIndexing='on'/'off', = 'on' for series of indexed files or frames to scan
30%      .Height: image height in pixels
31%      .Width:  image width in pixels
32%      .BitDepth: nbre of bits per pixel  (8 of 16)
33%      .ColorType: 'greyscale' or 'color'
34%      .NumberOfFrames: defined for images or movies
35%      .FrameRate: nbre of frames per second, =[] if not documented
36% VideoObject: in case of video
37%
38% INPUT:
39% fileinput: name, including path, of the file to analyse
40
41%=======================================================================
42% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
43%   http://www.legi.grenoble-inp.fr
44%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
45%
46%     This file is part of the toolbox UVMAT.
47%
48%     UVMAT is free software; you can redistribute it and/or modify
49%     it under the terms of the GNU General Public License as published
50%     by the Free Software Foundation; either version 2 of the license,
51%     or (at your option) any later version.
52%
53%     UVMAT is distributed in the hope that it will be useful,
54%     but WITHOUT ANY WARRANTY; without even the implied warranty of
55%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56%     GNU General Public License (see LICENSE.txt) for more details.
57%=======================================================================
58
59function [FileInfo,VideoObject]=get_file_info(fileinput)
60
61VideoObject=[];
62FileInfo.FileName='';% file doe not exist, defautlt
63FileInfo.FileType='';% input file type not detected
64FileInfo.FieldType=''; %default output
65if ~ischar(fileinput)
66    return
67end
68
69%% check the existence (not possible for OpenDAP data)
70if ~isempty(regexp(fileinput,'^http://','once'))|| exist(fileinput,'file')
71    FileInfo.FileName=fileinput;
72%     FileInfo.FileType='txt'; %default
73else
74    return %input file does not exist.
75end
76[~,~,FileExt]=fileparts(fileinput);%get the file extension FileExt
77
78%% look according to file extension
79switch FileExt
80    case '.fig'% Matlab figure assumed
81        FileInfo.FileType='figure';
82    case '.mat'% Matlab data format
83        FileInfo.FileType='mat';
84    case {'.txt','.log','.stdout','.stderr','.sh'}
85        FileInfo.FileType='txt';
86    case {'.xml','.xls','.dat','.bin'}
87        FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension;
88    case {'.seq','.sqb'}% data from rdvision
89        [~,FileInfo]=read_rdvision(fileinput,[]);
90    case '.im7'% data from LaVision (DaVis), requires specific conditions of Matlab version and computer system
91        try
92            Input=readimx(fileinput);
93            Image=Input.Frames{1}.Components{1}.Planes{1};
94            FileInfo.FileType='image_DaVis';
95            FileInfo.NumberOfFrames=numel(Input.Frames);
96            FileInfo.Height=size(Image,2);
97            FileInfo.Width=size(Image,1);
98            FileInfo.TimeName='timestamp';
99            for ilist=1:numel(Input.Attributes)
100                % if strcmp(Input.Attributes{ilist}.Name,'_Date')
101                %     DateString=Input.Attributes{ilist}.Value;
102                % end
103                % if strcmp(Input.Attributes{ilist}.Name,'_Time')
104                %     TimeString=Input.Attributes{ilist}.Value;
105                % end
106            end
107        catch ME
108            msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is not possible with this Matlab version and system'})
109            return
110        end
111    case '.h5'% format hdf5, used for specific case of PIV data from 'Fluidimage'
112        hinfo=h5info(fileinput);
113        FileInfo.CivStage=0;
114        for igroup=1:numel(hinfo.Groups)
115            if strcmp(hinfo.Groups(igroup).Name,'/piv0')
116                FileInfo.CivStage=3;
117            end
118            if strcmp(hinfo.Groups(igroup).Name,'/piv1')
119                FileInfo.CivStage=6;
120                break
121            end
122        end
123        if FileInfo.CivStage~=0
124            FileInfo.FileType='pivdata_fluidimage';
125        else
126            FileInfo.FileType='h5';
127        end
128    case '.cine'
129        [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput);
130        FileInfo.FileType='cine_phantom';
131        FileInfo.NumberOfFrames=FileInfo.ImageCount;
132        FileInfo.FrameRate=CameraSetup.FrameRate;
133        FileInfo.Height=BitmapInfoHeader.biHeight;
134        FileInfo.Width=BitmapInfoHeader.biWidth;
135        FileInfo.BitDepth=BitmapInfoHeader.biBitCount;
136        FileInfo.TimeName='video';
137    case '.hcc' % infrared camera Telops
138        installToolboxIRCAM
139        [~,InfoArray]=readIRCam(fileinput,'HeadersOnly',true);
140        FileInfo.FileType='telopsIR';
141        FileInfo.Height=InfoArray(1).Height;
142        FileInfo.Width=InfoArray(1).Width;
143        FileInfo.FrameRate=InfoArray(1).AcquisitionFrameRate;
144        FileInfo.NumberOfFrames=numel(InfoArray);
145        FileInfo.TimeName='video';
146        Path=fileparts(fileinput);% look for the xml file to document theb file series
147        [RootPath,SubDir,DirExt]=fileparts(Path);
148        if ~isempty(DirExt)
149            disp(['ERROR: change the name of the folder containing the image files: no file extension ' DirExt])
150            FileInfo.FileType='error';
151            return
152        end
153%         XmlFile=fullfile(RootPath,[SubDir '.xml']);
154%         CheckWriteImaDoc=true;
155%         if exist(XmlFile,'file')
156%             [XmlData,~,errormsg]=xml2struct(XmlFile);
157%             if ~isempty(errormsg)
158%                 disp(errormsg)
159%                 FileInfo.FileType='error';
160%                 return
161%             elseif isfield(XmlData,'FileSeries')
162%                 CheckWriteImaDoc=false;
163%             end
164%         end
165%         if CheckWriteImaDoc
166%             DirContent=dir(Path);
167%             NbFiles=0;
168%             FileSeries.Convention='telopsIR';
169%             for ilist=1:numel(DirContent)
170%                 FName=DirContent(ilist).name;
171%                 if ~isempty(regexp(FName,'.hcc$', 'once'))
172%                     NbFiles=NbFiles+1;
173%                     FileSeries.FileName{NbFiles,1}=FName;
174%                 end
175%             end
176%             FileSeries.NbFramePerFile=FileInfo.NumberOfFrames;
177%             [checkupdate,xmlfile,errormsg]=update_imadoc(RootPath,SubDir,'FileSeries',FileSeries);
178%         end
179
180    otherwise
181        if ~isempty(FileExt)% exclude empty extension
182            FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension
183            if ~isempty(FileExt)
184                if ~isempty(imformats(FileExt))%case of images
185                    FileInfo.FileType='image';
186                    try
187                        imainfo=imfinfo(fileinput);
188                        if length(imainfo) >1 %case of image with multiple frames
189                            FileInfo=imainfo(1);%take info from the first frame
190                            FileInfo.NumberOfFrames=length(imainfo);
191                            FileInfo.FileType='multimage';
192                        else
193                            FileInfo=imainfo;
194                            FileInfo.NumberOfFrames=1;
195                            FileInfo.FileType='image';
196                        end
197                        FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo
198                        nbfield=numel(fieldnames(FileInfo));
199                        FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity
200                    catch ME
201                        FileInfo.error=ME.message;
202                    end
203
204                else
205                    error_nc=0;
206                    try %try netcdf file
207                        [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
208                        if isempty(errormsg)
209                            if isfield(Data,'Conventions') && ismember(Data.Conventions,{'uvmat/civdata','uvmat/civdata/compress'})
210                               if strcmp(Data.Conventions,'uvmat/civdata')
211                                FileInfo.FileType='civdata'; % test for civ velocity fields
212                               else
213                                   FileInfo.FileType='civdata_compress'; % test for civ velocity fields
214                               end
215                                FileInfo.CivStage=Data.CivStage;
216                                MaskFile='';
217                                if isfield(Data,'Civ2_Mask')
218                                    MaskFile=Data.Civ2_Mask;
219                                    if isfield(Data,'Civ2_NbSlice')
220                                        FileInfo.MaskNbSlice=Data.Civ2_NbSlice;
221                                    end
222                                elseif isfield(Data,'Civ1_Mask')
223                                    MaskFile=Data.Civ1_Mask;
224                                    if isfield(Data,'Civ1_NbSlice')
225                                        FileInfo.MaskNbSlice=Data.Civ1_NbSlice;
226                                    end
227                                end
228                                if isfield(Data,'VolumeScan')
229                                    FileInfo.VolumeScan=Data.VolumeScan;
230                                end
231                                if ~isempty(MaskFile)
232                                    [RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(MaskFile);
233                                    if strcmp(NomType,'_1')&& isfield(FileInfo,'MaskNbSlice')
234                                        FileInfo.MaskFile=fullfile(RootPath,SubDir,RootFile);
235                                    else
236                                        FileInfo.MaskFile=MaskFile;% single mask for the series (no indexing)
237                                    end
238                                    FileInfo.MaskExt=FileExt;
239                                end
240                            elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata_3D')
241                                FileInfo.FileType='civdata_3D'; % test for 3D volume civ velocity fields
242                                FileInfo.CivStage=Data.CivStage;
243                                z_dim_index=find(strcmp(Data.ListDimName,'npz'));
244                                FileInfo.NumberOfFrames=Data.DimValue(z_dim_index);
245                            else
246                                FileInfo.FileType='netcdf';
247                                FileInfo.ListVarName=Data.ListVarName;
248                                FileInfo.VarAttribute={};
249                                if isfield(Data,'VarAttribute')
250                                    FileInfo.VarAttribute=Data.VarAttribute;
251                                end
252                                FileInfo.ListDimName=Data.ListDimName;
253                                %                                 FileInfo.NumberOfFrames=Data.DimValue;
254                            end
255                        else
256                            error_nc=1;
257                        end
258                    catch ME
259                        error_nc=1;
260                    end
261                    if error_nc
262                        try
263                            if exist('mmreader.m','file')% Matlab 2009a
264                                INFO=mmfileinfo (fileinput);
265                                if  ~isempty(INFO.Video.Format)
266                                    VideoObject=mmreader(fileinput);
267                                    FileInfo=get(VideoObject);
268                                    FileInfo.FileType='mmreader';
269                                end
270                            end
271                            FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
272                            FileInfo.ColorType='truecolor';
273                            FileInfo.TimeName='video';
274                            FileInfo.FileName=fileinput;
275                            nbfield=numel(fieldnames(FileInfo));
276                            FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity
277                            if ~isfield(FileInfo,'NumberOfFrames')
278                                FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate);
279                            end
280                        end
281                    end
282                end
283            end
284        end
285end
286
287FileInfo.FieldType=FileInfo.FileType;%default
288switch FileInfo.FileType
289    case {'image','multimage','video','mmreader','rdvision','image_DaVis','cine_phantom','telopsIR'}
290        FileInfo.FieldType='image';
291    case {'civdata','civdata_compress','pivdata_fluidimage'}
292        FileInfo.FieldType='civdata';
293end
294
295if strcmp(FileInfo.FieldType,'image') || ismember (FileInfo.FileType,{'mat','netcdf','civdata','civdata_compress'})
296    FileInfo.FileIndexing='on'; % allow to detect file index for scanning series
297else
298    FileInfo.FileIndexing='off';
299end
300
301
Note: See TracBrowser for help on using the repository browser.