source: trunk/src/get_file_info.m @ 1199

Last change on this file since 1199 was 1199, checked in by sommeria, 5 hours ago

bugs repaired

File size: 14.2 KB
RevLine 
[1181]1%'gext_file_info': determine info about a file (image, multimage, civdata,...) .
[784]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
[1181]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
[1089]13%               ='mat': Matlab data file
[1181]14%               ='netcdf': generic netcdf file
[1033]15%               ='xml': xml file
16%               ='xls': Excel file
[1181]17%               ='civdata': netcdf files provided by civ_series
18%               ='pivdata_fluidimage': PIV data from software 'fluidimage'
19%   different image and movie formats:
[1033]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
[1181]25%               ='image_DaVis': images from softwar DaVis (company LaVision), requires specific conditions of Matlab version and computer system
[1033]26%               ='cine_phantom': images from fast camera Phantom
[1181]27%               ='telopsIR': Infrared images from  company Telops
[1040]28%      .FieldType='image' for all kinds of images and movies, =FileType  else
[1181]29%      .FileIndexing='on'/'off', = 'on' for series of indexed files or frames to scan
[784]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'
[1040]34%      .NumberOfFrames: defined for images or movies
[1181]35%      .FrameRate: nbre of frames per second, =[] if not documented
[784]36% VideoObject: in case of video
37%
38% INPUT:
39% fileinput: name, including path, of the file to analyse
[809]40
41%=======================================================================
[1126]42% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]43%   http://www.legi.grenoble-inp.fr
[1127]44%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[809]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
[784]59function [FileInfo,VideoObject]=get_file_info(fileinput)
[1162]60
[784]61VideoObject=[];
[1181]62FileInfo.FileName='';% file doe not exist, defautlt
63FileInfo.FileType='';% input file type not detected
[1041]64FileInfo.FieldType=''; %default output
[1122]65if ~ischar(fileinput)
66    return
67end
[1181]68
69%% check the existence (not possible for OpenDAP data)
[1134]70if ~isempty(regexp(fileinput,'^http://','once'))|| exist(fileinput,'file')
[784]71    FileInfo.FileName=fileinput;
[1181]72%     FileInfo.FileType='txt'; %default
[1162]73else
74    return %input file does not exist.
[784]75end
[1180]76[~,~,FileExt]=fileparts(fileinput);%get the file extension FileExt
[784]77
[1181]78%% look according to file extension
[784]79switch FileExt
[1181]80    case '.fig'% Matlab figure assumed
[784]81        FileInfo.FileType='figure';
[1181]82    case '.mat'% Matlab data format
[1088]83        FileInfo.FileType='mat';
[1181]84    case {'.txt','.log','.stdout','.stderr','.sh'}
85        FileInfo.FileType='txt';
[784]86    case {'.xml','.xls','.dat','.bin'}
87        FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension;
[1181]88    case {'.seq','.sqb'}% data from rdvision
[1178]89        [~,FileInfo]=read_rdvision(fileinput,[]);
[1181]90    case '.im7'% data from LaVision (DaVis), requires specific conditions of Matlab version and computer system
[1007]91        try
[1162]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
[1007]107        catch ME
[1181]108            msgbox_uvmat('ERROR',{ME.message;'reading image from DaVis is not possible with this Matlab version and system'})
[1007]109            return
110        end
[1181]111    case '.h5'% format hdf5, used for specific case of PIV data from 'Fluidimage'
[1134]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
[946]124            FileInfo.FileType='pivdata_fluidimage';
[1134]125        else
126            FileInfo.FileType='h5';
[946]127        end
[979]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;
[1162]135        FileInfo.BitDepth=BitmapInfoHeader.biBitCount;
136        FileInfo.TimeName='video';
[1181]137    case '.hcc' % infrared camera Telops
[1180]138        installToolboxIRCAM
[1170]139        [~,InfoArray]=readIRCam(fileinput,'HeadersOnly',true);
[1180]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
[1195]153%         XmlFile=fullfile(RootPath,[SubDir '.xml']);
154%         CheckWriteImaDoc=true;
[1191]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
[1180]179
[784]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
[1120]185                    FileInfo.FileType='image';
[784]186                    try
187                        imainfo=imfinfo(fileinput);
[1162]188                        if length(imainfo) >1 %case of image with multiple frames
[784]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
[1165]200                    catch ME
[1178]201                        FileInfo.error=ME.message;
[784]202                    end
[1180]203
[784]204                else
205                    error_nc=0;
[1162]206                    try %try netcdf file
207                        [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
208                        if isempty(errormsg)
[1196]209                            if isfield(Data,'Conventions') && ismember(Data.Conventions,{'uvmat/civdata','uvmat/civdata/compress'})
210                               if strcmp(Data.Conventions,'uvmat/civdata')
[1161]211                                FileInfo.FileType='civdata'; % test for civ velocity fields
[1196]212                               else
213                                   FileInfo.FileType='civdata_compress'; % test for civ velocity fields
214                               end
[784]215                                FileInfo.CivStage=Data.CivStage;
[1164]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
[1161]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;
[1162]243                                z_dim_index=find(strcmp(Data.ListDimName,'npz'));
244                                FileInfo.NumberOfFrames=Data.DimValue(z_dim_index);
[784]245                            else
246                                FileInfo.FileType='netcdf';
247                                FileInfo.ListVarName=Data.ListVarName;
[1162]248                                FileInfo.VarAttribute={};
249                                if isfield(Data,'VarAttribute')
250                                    FileInfo.VarAttribute=Data.VarAttribute;
251                                end
252                                FileInfo.ListDimName=Data.ListDimName;
[1180]253                                %                                 FileInfo.NumberOfFrames=Data.DimValue;
[784]254                            end
[1162]255                        else
256                            error_nc=1;
[784]257                        end
258                    catch ME
259                        error_nc=1;
260                    end
261                    if error_nc
262                        try
[1199]263                            % if exist('mmreader.m','file')% OBSOLETE Matlab 2009a
[1162]264                                INFO=mmfileinfo (fileinput);
265                                if  ~isempty(INFO.Video.Format)
[1199]266                                    VideoObject=VideoReader(fileinput);
[1162]267                                    FileInfo=get(VideoObject);
[1199]268                                    FileInfo.FileType='video';
[1162]269                                end
[1199]270                            % end
[784]271                            FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
272                            FileInfo.ColorType='truecolor';
[1032]273                            FileInfo.TimeName='video';
[784]274                            FileInfo.FileName=fileinput;
275                            nbfield=numel(fieldnames(FileInfo));
[1199]276                            %FileInfo=orderfields(FileInfo,[nbfield nbfield-4 nbfield-3 nbfield-1 nbfield-2 (1:nbfield-5)]); %reorder the fields of fileInfo for clarity
[1025]277                            if ~isfield(FileInfo,'NumberOfFrames')
278                                FileInfo.NumberOfFrames=floor(FileInfo.Duration*FileInfo.FrameRate);
279                            end
[784]280                        end
281                    end
282                end
283            end
284        end
[790]285end
[1041]286
[1033]287FileInfo.FieldType=FileInfo.FileType;%default
288switch FileInfo.FileType
[1199]289    case {'image','multimage','video','rdvision','image_DaVis','cine_phantom','telopsIR'}
[1162]290        FileInfo.FieldType='image';
[1196]291    case {'civdata','civdata_compress','pivdata_fluidimage'}
[1041]292        FileInfo.FieldType='civdata';
[1033]293end
294
[1196]295if strcmp(FileInfo.FieldType,'image') || ismember (FileInfo.FileType,{'mat','netcdf','civdata','civdata_compress'})
[1181]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.