Ignore:
Timestamp:
Dec 19, 2011, 10:12:56 AM (12 years ago)
Author:
sommeria
Message:

name2display replaced by fileparts_uvmat and find_file_series in series.
name2display partially replaced in civ.m (to be continued)
series.fig reorganized with panels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_file_series.m

    r334 r339  
    11%'find_file_series': check the content onf an input field and find the corresponding file series
    22%--------------------------------------------------------------------------
    3 % function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput)
     3% function [RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object]=find_file_series(fileinput)
    44%
    55% OUTPUT:
    6 % i1,i2,j1,j2: set of i1 indices, respectively i2,j1,j2,  of the detected files
     6% RootPath,RootFile: root path and root name detected in fileinput, possibly modified for movies (indexing is then done on image view, not file)
     7% i1_series(ref_i, ref_j,pair),i2_series,j1_series,j2_series: set of indices (i1,i2,j1,j2) sorted by ref index ref_i, ref_j, and pairindex in case of multiple pairs with the same ref
    78% NomType: nomenclature type corrected after checking the first file (problem of 0 before the number string)
    89% FileType: type of file, =
     
    3435%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    3536
    36 function [i1,i2,j1,j2,NomType,FileType,Object]=find_file_series(fileinput)
     37function [RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object]=find_file_series(fileinput)
    3738%------------------------------------------------------------------------
    38 i1=[];%default
    39 i2=[];%default
    40 j1=[];%default
    41 j2=[];%default
    4239
    4340%% get input root name and nomenclature type
    4441% [RootPath,RootFile,~,~,~,~,FileExt,NomType,SubDir]=name2display(fileinput);
    45 [RootPath,SubDir,RootFile,~,~,~,~,FileExt,NomType]=fileparts_uvmat(fileinput);
     42[RootPath,SubDir,RootFile,~,i2_input,j1_input,j2_input,FileExt,NomType]=fileparts_uvmat(fileinput);
    4643
    4744%% check for particular file types: images, movies, civ data
    4845FileType='';
    4946Object=[];
     47i1_series=zeros(1,1,1);
     48i2_series=zeros(1,1,1);
     49j1_series=zeros(1,1,1);
     50j2_series=zeros(1,1,1);
    5051switch FileExt
    5152    % ancillary files, no field indexing
     
    6465    otherwise
    6566        if ~isempty(FileExt)&& ~isempty(imformats(FileExt(2:end)))
    66             imainfo=imfinfo(fileinput);
    67             FileType='image';
    68             if length(imainfo) >1 %case of image with multiple frames
    69                 NomType='*';
    70                 FileType='multimage';
    71                 i1=1;
    72                 i2=length(imainfo);
    73                 [RootPath,RootFile]=fileparts(fileinput);
     67            try
     68                imainfo=imfinfo(fileinput);
     69                FileType='image';
     70                if length(imainfo) >1 %case of image with multiple frames
     71                    NomType='*';
     72                    FileType='multimage';
     73                    i1_series=1:length(imainfo);
     74                    [RootPath,RootFile]=fileparts(fileinput);
     75                end
    7476            end
    7577        else
     
    8890                NomType='*';
    8991                FileType='video';
    90                 i1=1;
    91                 i2=get(Object,'NumberOfFrames');
     92                i1_series=[1:get(Object,'NumberOfFrames')];
    9293                [RootPath,RootFile]=fileparts(fileinput);
    9394            end
    9495        end
    9596end
     97
     98%% get the list of existing files when relevant
    9699if strcmp(NomType,'')||strcmp(NomType,'*')
     100    if exist(fileinput,'file')
    97101    [RootPath,RootFile]=fileparts(fileinput);% case of constant name (no indexing)
    98 %% get the list of existing files
     102    else
     103       RootPath='';
     104       RootFile='';
     105    end
    99106else
    100107    if strcmp(SubDir,'')
     
    113120    end
    114121    dirpair=dir([filebasesub detect_string FileExt]);
    115     for ifile=1:length(dirpair)
    116        % [~,~,str_1,str_2,str_a,str_b]=name2display(dirpair(ifile).name);
    117        dirpair(ifile).name
    118         [~,~,~,i1_ifile,i2_ifile,j1_ifile,j2_ifile]=fileparts_uvmat(dirpair(ifile).name); 
    119         if isempty(i1_ifile)
    120             i1(ifile)=1;
     122    nbpair=numel(dirpair);
     123    ref_i_list=zeros(1,nbpair);
     124    ref_j_list=zeros(1,nbpair);
     125    if nbpair==0% no detected file
     126        RootPath='';
     127        RootFile='';
     128    end
     129    for ifile=1:nbpair
     130        [~,~,~,i1,i2,j1,j2]=fileparts_uvmat(dirpair(ifile).name);
     131        %             i1_series(ifile)=i1;
     132        ref_i=i1;
     133        if isempty(i2_input)
     134            if ~isempty(i2)% invalid file name if i2 does not exist in the input file
     135                break
     136            end
    121137        else
    122             i1(ifile)=i1_ifile;
    123         end
    124         if isempty(i2_ifile)
    125             i2(ifile)=i1(ifile);
     138            ref_i=floor((i1+i2)/2);
     139        end
     140        ref_j=1;
     141        if isempty(j1_input)
     142            if  ~isempty(j1)% invalid file name if j1 does not exist in the input file
     143                break
     144            end
    126145        else
    127             i2(ifile)=i2_ifile;
    128         end
    129         end
    130         if isempty(j1_ifile)
    131             j1(ifile)=1;
    132         else
    133             j1(ifile)=j1_ifile;
    134         end
    135         if isempty(j2_ifile)
    136             j2(ifile)=j1(ifile);
    137         else
    138             j2(ifile)=j2_ifile;
    139         end
    140     end 
    141     % TODO : sort by reference index
    142     % update the NomType from the minimal index detected (to deal with number strings beginning by 0)
    143     [~,ifile]=min(i1);
    144     %[~,~,~,~,~,~,~,NomType]=name2display(dirpair(ifile).name);
    145     if ~isempty(i1)
    146            [~,ifile]=min(i1);
     146            ref_j=j1;
     147            if isempty(j2_input)
     148                if  ~isempty(j2)% invalid file name if j2 does not exist in the input file
     149                    break
     150                end
     151            else
     152                ref_j=floor((j1+j2)/2);
     153            end
     154        end
     155        % update the detected index series
     156        ref_i_list(ifile)=ref_i;
     157        ref_j_list(ifile)=ref_j;
     158        nb_pairs=0;
     159        if ~isempty(i2_input)|| ~isempty(j2_input) %deals with  pairs
     160            if size(i1_series,1)>=ref_i && size(i1_series,2)>=ref_j
     161                nb_pairs=numel(find(i1_series(ref_i,ref_j,:)~=0));
     162            end
     163        end
     164        i1_series(ref_i,ref_j,nb_pairs+1)=i1;
     165        if ~isempty(i2_input)
     166            i2_series(ref_i,ref_j,nb_pairs+1)=i2;
     167        end
     168        if ~isempty(j1_input)
     169            j1_series(ref_i,ref_j,nb_pairs+1)=j1;
     170        end
     171        if ~isempty(j2_input)
     172            j1_series(ref_i,ref_j,nb_pairs+1)=j1;
     173            j2_series(ref_i,ref_j,nb_pairs+1)=j2;
     174        end
     175    end
     176    % look for the numerical string of the first files to update the NomType (take into account the 0 before the number)
     177    max_j=max(ref_j_list);
     178    ref_ij=ref_i_list*max_j+ref_j_list; % ordered by index i, then by j for a given i.
     179    [~,ifile]=min(ref_ij(ref_ij>0));
    147180    [~,~,~,~,~,~,~,~,NomType]=fileparts_uvmat(dirpair(ifile).name);
    148     end
    149181end
     182
     183%% set to empty array the irrelevant index series
     184if isequal(i1_series,0), i1_series=[]; end
     185if isequal(i2_series,0), i2_series=[]; end
     186if isequal(j1_series,0), j1_series=[]; end
     187if isequal(j2_series,0), j2_series=[]; end
     188
     189%% sort pairs by decreasing index differences in case of multiple pairs at the same reference index
     190if size(i2_series,3)>1 %pairs i1 -i2
     191    diff_index=abs(i2_series-i1_series);
     192    [~,ind_pair]=sort(diff_index,3,'descend');
     193    for ref_i=1:size(i1_series,1)
     194        for ref_j=1:size(j1_series,2)
     195            i1_series(ref_i,ref_j,:)=i1_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     196            i2_series(ref_i,ref_j,:)=i2_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     197            if ~isempty(j1_series)
     198                j1_series(ref_i,ref_j,:)=j1_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     199            end
     200        end
     201    end
     202elseif size(j2_series,3)>1 %pairs j1 -j2
     203    diff_index=abs(j2_series-j1_series);
     204    [~,ind_pair]=sort(diff_index,3,'descend');
     205    for ref_i=1:size(i1_series,1)
     206        for ref_j=1:size(j1_series,2)
     207            i1_series(ref_i,ref_j,:)=i1_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     208            if ~isempty(i2_series)
     209                i2_series(ref_i,ref_j,:)=i2_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     210            end
     211            j1_series(ref_i,ref_j,:)=j1_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     212            j2_series(ref_i,ref_j,:)=j2_series(ref_i,ref_j,ind_pair(ref_i,ref_j,:));
     213        end
     214    end
     215end
     216
Note: See TracChangeset for help on using the changeset viewer.