[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 |
---|
| 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 | function [FileInfo,VideoObject]=get_file_info(fileinput) |
---|
| 19 | VideoObject=[]; |
---|
| 20 | if exist(fileinput,'file') |
---|
| 21 | FileInfo.FileName=fileinput; |
---|
| 22 | FileInfo.FileType='txt'; %default |
---|
| 23 | else |
---|
| 24 | FileInfo.FileType=''; |
---|
| 25 | return |
---|
| 26 | end |
---|
| 27 | [tild,tild,FileExt]=fileparts(fileinput);%get the file extension FileExt |
---|
| 28 | |
---|
| 29 | switch FileExt |
---|
| 30 | case '.fig' |
---|
| 31 | FileInfo.FileType='figure'; |
---|
| 32 | case {'.xml','.xls','.dat','.bin'} |
---|
| 33 | FileInfo.FileType=regexprep(FileExt,'^.','');% eliminate the dot of the extension; |
---|
| 34 | case '.seq' |
---|
| 35 | FileInfo=ini2struct(fileinput); |
---|
| 36 | if isfield(FileInfo,'sequenceSettings')&& isfield(FileInfo.sequenceSettings,'numberoffiles') |
---|
| 37 | FileInfo.NumberOfFrames=str2double(FileInfo.sequenceSettings.numberoffiles); |
---|
| 38 | FileInfo.FrameRate=str2double(FileInfo.sequenceSettings.framepersecond); |
---|
| 39 | FileInfo.ColorType='grayscale'; |
---|
| 40 | else |
---|
| 41 | FileInfo.FileType=''; |
---|
| 42 | return |
---|
| 43 | end |
---|
| 44 | FileInfo.FileType='rdvision'; % file used to store info from image acquisition systems of rdvision |
---|
| 45 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 46 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
| 47 | otherwise |
---|
| 48 | if ~isempty(FileExt)% exclude empty extension |
---|
| 49 | FileExt=regexprep(FileExt,'^.','');% eliminate the dot of the extension |
---|
| 50 | if ~isempty(FileExt) |
---|
| 51 | if ~isempty(imformats(FileExt))%case of images |
---|
| 52 | try |
---|
| 53 | imainfo=imfinfo(fileinput); |
---|
| 54 | if length(imainfo) >1 %case of image with multiple frames |
---|
| 55 | FileInfo=imainfo(1);%take info from the first frame |
---|
| 56 | FileInfo.NumberOfFrames=length(imainfo); |
---|
| 57 | FileInfo.FileType='multimage'; |
---|
| 58 | else |
---|
| 59 | FileInfo=imainfo; |
---|
| 60 | FileInfo.NumberOfFrames=1; |
---|
| 61 | FileInfo.FileType='image'; |
---|
| 62 | end |
---|
| 63 | FileInfo.FileName=FileInfo.Filename; %correct the info given by imfinfo |
---|
| 64 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 65 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity |
---|
| 66 | end |
---|
| 67 | else |
---|
| 68 | error_nc=0; |
---|
| 69 | try |
---|
| 70 | [Data,tild,tild,errormsg]=nc2struct(fileinput,[]); |
---|
| 71 | if ~isempty(errormsg) |
---|
| 72 | error_nc=1; |
---|
| 73 | else |
---|
| 74 | if isfield(Data,'absolut_time_T0') && isfield(Data,'hart') && ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart) |
---|
| 75 | FileInfo.FileType='civx'; |
---|
| 76 | if isfield(Data,'patch2') && isequal(Data.patch2,1) |
---|
| 77 | FileInfo.CivStage=6; |
---|
| 78 | elseif isfield(Data,'fix2') && isequal(Data.fix2,1) |
---|
| 79 | FileInfo.CivStage=5; |
---|
| 80 | elseif isfield(Data,'civ2')&& isequal(Data.civ2,1) |
---|
| 81 | FileInfo.CivStage=4; |
---|
| 82 | elseif isfield(Data,'patch')&&isequal(Data.patch,1) |
---|
| 83 | FileInfo.CivStage=3; |
---|
| 84 | elseif isfield(Data,'fix')&&isequal(Data.fix,1) |
---|
| 85 | FileInfo.CivStage=2; |
---|
| 86 | else |
---|
| 87 | FileInfo.CivStage=1; |
---|
| 88 | end |
---|
| 89 | elseif isfield(Data,'Conventions') && strcmp(Data.Conventions,'uvmat/civdata') |
---|
| 90 | FileInfo.FileType='civdata'; % test for civx velocity fields |
---|
| 91 | FileInfo.CivStage=Data.CivStage; |
---|
| 92 | else |
---|
| 93 | FileInfo.FileType='netcdf'; |
---|
| 94 | FileInfo.ListVarName=Data.ListVarName; |
---|
| 95 | end |
---|
| 96 | end |
---|
| 97 | catch ME |
---|
| 98 | error_nc=1; |
---|
| 99 | end |
---|
| 100 | if error_nc |
---|
| 101 | try |
---|
| 102 | if exist('VideoReader.m','file')%recent version of Matlab |
---|
| 103 | VideoObject=VideoReader(fileinput); |
---|
| 104 | FileInfo=get(VideoObject); |
---|
| 105 | FileInfo.FileType='video'; |
---|
| 106 | elseif exist('mmreader.m','file')% Matlab 2009a |
---|
| 107 | VideoObject=mmreader(fileinput); |
---|
| 108 | FileInfo=get(VideoObject); |
---|
| 109 | FileInfo.FileType='mmreader'; |
---|
| 110 | end |
---|
| 111 | FileInfo.BitDepth=FileInfo.BitsPerPixel/3; |
---|
| 112 | FileInfo.ColorType='truecolor'; |
---|
| 113 | FileInfo.FileName=fileinput; |
---|
| 114 | nbfield=numel(fieldnames(FileInfo)); |
---|
| 115 | FileInfo=orderfields(FileInfo,[nbfield nbfield-3 nbfield-1 nbfield-2 (1:nbfield-4)]); %reorder the fields of fileInfo for clarity |
---|
| 116 | end |
---|
| 117 | end |
---|
| 118 | end |
---|
| 119 | end |
---|
| 120 | end |
---|
| 121 | end |
---|