source: trunk/src/get_file_info.m @ 1180

Last change on this file since 1180 was 1180, checked in by sommeria, 3 weeks ago

various bugs repaired,Relabeling frames installed for multitif

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