source: trunk/src/get_file_info.m @ 1032

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

reading LaVision? images improved

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