source: trunk/src/get_file_info.m @ 982

Last change on this file since 982 was 979, checked in by sommeria, 7 years ago

phantom added, series corrected

File size: 7.0 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%      .Height: image height in pixels
9%      .Width:  image width in pixels
10%      .BitDepth: nbre of bits per pixel  (8 of 16)
11%      .ColorType: 'greyscale' or 'color'
12%      .NumberOfFrames
13%      .FrameRate: nbre of frames per second, =[] for images
14% VideoObject: in case of video
15%
16% INPUT:
17% fileinput: name, including path, of the file to analyse
18
19%=======================================================================
20% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
21%   http://www.legi.grenoble-inp.fr
22%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
23%
24%     This file is part of the toolbox UVMAT.
25%
26%     UVMAT is free software; you can redistribute it and/or modify
27%     it under the terms of the GNU General Public License as published
28%     by the Free Software Foundation; either version 2 of the license,
29%     or (at your option) any later version.
30%
31%     UVMAT is distributed in the hope that it will be useful,
32%     but WITHOUT ANY WARRANTY; without even the implied warranty of
33%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34%     GNU General Public License (see LICENSE.txt) for more details.
35%=======================================================================
36
37function [FileInfo,VideoObject]=get_file_info(fileinput)
38VideoObject=[];
39if exist(fileinput,'file')==2
40    FileInfo.FileName=fileinput;
41    FileInfo.FileType='txt'; %default
42else
43    FileInfo.FileType='';
44    return
45end
46[tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt
47
48switch FileExt
49    case '.fig'
50        FileInfo.FileType='figure';
51    case {'.xml','.xls','.dat','.bin'}
52        FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension;
53    case {'.seq','.sqb'}
54        [A,FileInfo,timestamps,errormsg]=read_rdvision(fileinput,[]);
55    case '.h5'
56        hinfo=hdf5info(fileinput);
57        if strcmp(hinfo.GroupHierarchy.Attributes(1).Value.Data,'MultipassPIVResults')
58            FileInfo.FileType='pivdata_fluidimage';
59            FileInfo.CivStage=6; % A MODIFIER
60        end
61    case '.cine'
62        [FileInfo,BitmapInfoHeader, CameraSetup]=readCineHeader(fileinput);
63        FileInfo.FileType='cine_phantom';
64        FileInfo.NumberOfFrames=FileInfo.ImageCount;
65        FileInfo.FrameRate=CameraSetup.FrameRate;
66        FileInfo.Height=BitmapInfoHeader.biHeight;
67        FileInfo.Width=BitmapInfoHeader.biWidth;
68    otherwise
69        if ~isempty(FileExt)% exclude empty extension
70            FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension
71            if ~isempty(FileExt)
72                if ~isempty(imformats(FileExt))%case of images
73                    try
74                        imainfo=imfinfo(fileinput);
75                        if length(imainfo) >1 %case of image with multiple frames   
76                            FileInfo=imainfo(1);%take info from the first frame
77                            FileInfo.NumberOfFrames=length(imainfo);
78                            FileInfo.FileType='multimage';
79                        else
80                            FileInfo=imainfo;
81                            FileInfo.NumberOfFrames=1;
82                            FileInfo.FileType='image';
83                        end
84                        FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo
85                        nbfield=numel(fieldnames(FileInfo));
86                        FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity
87                    end
88                else
89                    error_nc=0;
90                    try
91                       [Data,tild,tild,errormsg]=nc2struct(fileinput,[]);
92                        if ~isempty(errormsg)
93                            error_nc=1;
94                        else
95                            if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
96                                FileInfo.FileType='civx';
97                                if isfield(Data,'patch2') && isequal(Data.patch2,1)
98                                    FileInfo.CivStage=6;
99                                elseif isfield(Data,'fix2') && isequal(Data.fix2,1)
100                                    FileInfo.CivStage=5;
101                                elseif  isfield(Data,'civ2')&& isequal(Data.civ2,1)
102                                    FileInfo.CivStage=4;
103                                elseif isfield(Data,'patch')&&isequal(Data.patch,1)
104                                    FileInfo.CivStage=3;
105                                elseif isfield(Data,'fix')&&isequal(Data.fix,1)
106                                    FileInfo.CivStage=2;
107                                else
108                                    FileInfo.CivStage=1;
109                                end
110                            elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata')
111                                FileInfo.FileType='civdata'; % test for civx velocity fields
112                                FileInfo.CivStage=Data.CivStage;
113                            else
114                                FileInfo.FileType='netcdf';
115                                FileInfo.ListVarName=Data.ListVarName;
116                            end
117                        end
118                    catch ME
119                        error_nc=1;
120                    end
121                    if error_nc
122                        try
123                            if exist('VideoReader.m','file')%recent version of Matlab
124                                VideoObject=VideoReader(fileinput);
125                                FileInfo=get(VideoObject);
126                                FileInfo.FileType='video';
127                            elseif exist('mmreader.m','file')% Matlab 2009a
128                                VideoObject=mmreader(fileinput);
129                                FileInfo=get(VideoObject);
130                                FileInfo.FileType='mmreader';
131                            end
132                            FileInfo.BitDepth=FileInfo.BitsPerPixel/3;
133                            FileInfo.ColorType='truecolor';
134                            FileInfo.FileName=fileinput;
135                            nbfield=numel(fieldnames(FileInfo));
136                            FileInfo=orderfields(FileInfo,[nbfield nbfield-3 nbfield-1 nbfield-2 (1:nbfield-4)]); %reorder the fields of fileInfo for clarity
137                        end
138                    end
139                end
140            end
141        end
142end
143switch FileInfo.FileType
144    case {'image','multimage','mmreader','video','netcdf','civdata'}
145        FileInfo.FileIndexing='on'; % allow to detect file index for scanning series
146end
Note: See TracBrowser for help on using the repository browser.