Changeset 1178 for trunk/src/series


Ignore:
Timestamp:
Mar 21, 2025, 10:17:07 AM (4 weeks ago)
Author:
sommeria
Message:

virtual frame indexing introduced

Location:
trunk/src/series
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/aver_spectral.m

    r1127 r1178  
    144144transform_fct='';%default
    145145if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
    146     addpath(Param.FieldTransform.TransformPath)
     146            currentdir=pwd;
     147    cd(Param.FieldTransform.TransformPath)
    147148    transform_fct=str2func(Param.FieldTransform.TransformName);
    148     rmpath(Param.FieldTransform.TransformPath)
     149    cd (currentdir)
    149150end
    150151
  • trunk/src/series/aver_stat.m

    r1148 r1178  
    198198transform_fct='';%default
    199199if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
    200     addpath(Param.FieldTransform.TransformPath)
     200            currentdir=pwd;
     201    cd(Param.FieldTransform.TransformPath)
    201202    transform_fct=str2func(Param.FieldTransform.TransformName);
    202     rmpath(Param.FieldTransform.TransformPath)
     203    cd (currentdir)
    203204    if isfield(Param,'TransformInput')
    204205        XmlData{1}.TransformInput=Param.TransformInput;
  • trunk/src/series/civ_series.m

    r1177 r1178  
    254254    end
    255255end
     256CheckRelabel=isfield(Param,'FileSeries' );%=true for index relabeling (PCO)
    256257
    257258%% introduce input image transform
    258259transform_fct=[];%default, no transform
    259260if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
    260        % addpath(Param.FieldTransform.TransformPath)
    261261        currentdir=pwd;
    262262    cd(Param.FieldTransform.TransformPath)
    263263    transform_fct=str2func(Param.FieldTransform.TransformName);
    264264    cd (currentdir)
    265     %rmpath(Param.FieldTransform.TransformPath)
    266265end
    267266
     
    289288    end
    290289    OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
    291 
     290    if CheckRelabel
     291         RootFileOut=index2filename(Param.FileSeries,1,1,MaxIndex_j);
     292    else
     293        RootFileOut=RootFile_A;
     294    end
    292295    if strcmp(Param.ActionInput.ListCompareMode,'PIV')
    293         ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),...
     296        ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),...
    294297            j1_series_Civ1(ifield),j2_series_Civ1(ifield));
    295298    else
    296         ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
     299        ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
    297300            j1_series_Civ1(ifield),j2_series_Civ1(ifield));
    298301    end
     
    314317        end
    315318        if strcmp(Param.ActionInput.ListCompareMode,'PIV')
    316             ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
     319            ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
    317320        else % displacement
    318             ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
     321            ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
    319322        end
    320323    end
     
    336339            if strcmp(Param.ActionInput.ListCompareMode,'displacement')
    337340                ImageName_A=Param.ActionInput.RefFile;
     341            elseif CheckRelabel
     342            [RootFile,FileIndexString,FrameIndex_A]=index2filename(Param.FileSeries,i1_series_Civ1(ifield),j1_series_Civ1(ifield),MaxIndex_j);
     343            ImageName_A=fullfile(RootPath_A,SubDir_A,[RootFile FileIndexString FileExt_A]);
    338344            else
    339345                ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
     346                FrameIndex_A=FrameIndex_A_Civ1(ifield);
    340347            end
    341348            if strcmp(FileExt_A,'.nc')% case of input images in format netcdf
     
    368375                end
    369376                tsart_input=tic;
    370                 [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(ifield));
     377                [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A);
    371378                time_input=toc(tsart_input);
    372379            end
     380if CheckRelabel
     381            [RootFile,FileIndexString,FrameIndex_B]=index2filename(Param.FileSeries,i1_series_Civ1(ifield),j1_series_Civ1(ifield),MaxIndex_j);
     382            ImageName_B=fullfile(RootPath_B,SubDir_B,[RootFile FileIndexString FileExt_B]);
     383else
    373384            ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
     385            FrameIndex_B=FrameIndex_B_Civ1(ifield);
     386end
    374387            if isempty(FileType_B)% determine the image type for the first field
    375388                [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
     
    380393                continue
    381394            end
    382             [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
     395            [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B);
    383396           
    384397        catch ME % display errors in reading input images
     
    613626        if strcmp(Param.ActionInput.ListCompareMode,'displacement')
    614627            ImageName_A_Civ2=Param.ActionInput.RefFile;
    615         else
     628        elseif CheckRelabel
     629              [RootFile,FileIndexString,FrameIndex_A_2]=index2filename(Param.FileSeries,i1_series_Civ2(ifield),j1_series_Civ2(ifield),MaxIndex_j);
     630            ImageName_A_Civ2=fullfile(RootPath_A,SubDir_A,[RootFile FileIndexString FileExt_A]);
     631            else
    616632            ImageName_A_Civ2=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_civ2,[],j1_civ2);
    617         end
    618         if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A_Civ1(ifield),FrameIndex_A_Civ2(ifield))
     633            FrameIndex_A_2=FrameIndex_A_Civ2(ifield);
     634        end
     635        if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A,FrameIndex_A_2)
    619636            par_civ2.ImageA=par_civ1.ImageA;
    620637        else
    621             [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_Civ2(ifield));
    622         end
     638            [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_2);
     639        end
     640        if CheckRelabel
     641              [RootFile,FileIndexString,FrameIndex_B_2]=index2filename(Param.FileSeries,i2_civ2,j2_civ2,MaxIndex_j);
     642            ImageName_B_Civ2=fullfile(RootPath_B,SubDir_B,[RootFile FileIndexString FileExt_B]);
     643            else
     644
     645
    623646        ImageName_B_Civ2=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_civ2,[],j2_civ2);
    624         if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_Civ1(ifield),FrameIndex_B_Civ2)
     647        FrameIndex_B_2=FrameIndex_B_Civ2(ifield);
     648        end
     649        if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_2,FrameIndex_B)
    625650            par_civ2.ImageB=par_civ1.ImageB;
    626651        else
    627             [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_Civ2(ifield));
     652            [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_2);
    628653        end
    629654        %  [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A_Civ2);
  • trunk/src/series/sub_background.m

    r1175 r1178  
    1010% Organization of image indices:
    1111    % The program is working on a series of images,
    12     % In the mode 'volume', nbfield2=1 (1 image at each level)and NbSlice (=nbfield_j)
    13     % Else nbfield2=nbfield_j =nbre of images in a burst (j index)
     12    % In the mode 'volume', nbfield2=1 (1 image at each level)and NbSlice (=NbField_j)
     13    % Else nbfield2=NbField_j =nbre of images in a burst (j index)
    1414   
    1515% function GUI_config=sub_background(Param)
     
    8383    ParamOut.OutputDirExt='.sback';%set the output dir extension
    8484    ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
    85    
    86     %% root input file(s) and type
    87     % check the existence of the first file in the series
    88         first_j=[];% note that the function will propose to cover the whole range of indices
    89     if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end
    90     last_j=[];
    91     if isfield(Param.IndexRange,'MaxIndex_j'); last_j=Param.IndexRange.MaxIndex_j; end
    92     PairString='';
    93     if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
    94     [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
    95     FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
    96         Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
    97     if ~exist(FirstFileName,'file')
    98         msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
    99     else
    100         [i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString);
    101         LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
    102         Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
    103         if ~exist(FirstFileName,'file')
    104              msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist'])
    105         end
    106     end
    10785
    10886    %% check the validity of  input file types
    109     FileInfo=get_file_info(FirstFileName);
    110     FileType=FileInfo.FileType;
    111     CheckImage=strcmp(FileInfo.FieldType,'image');% =1 for images
    112     if ~CheckImage
    113         msgbox_uvmat('ERROR',['invalid file type input: ' FileType ' not an image'])
     87    if isfield(Param,'SeriesData')&& isfield(Param.SeriesData,'FileInfo')
     88    if ~strcmp(Param.SeriesData.FileInfo{1}.FieldType,'image')
     89        msgbox_uvmat('ERROR','invalid file type input: not an image series')
    11490        return
    11591    end
    116    
     92    end
     93
    11794    %% numbers of fields
    11895    NbSlice_i=1;%default
     
    124101        incr_j=Param.IndexRange.incr_j;
    125102    end
    126     if isempty(first_j)||isempty(last_j)
    127         nbfield_j=1;
     103    if isfield(Param.IndexRange,'first_j')&&~isempty(Param.IndexRange.first_j)
     104        NbField_j=numel(Param.IndexRange.first_j:incr_j:Param.IndexRange.last_j);%nb of fields for the j index (bursts or volume slices)
    128105    else
    129         nbfield_j=numel(first_j:incr_j:last_j);%nb of fields for the j index (bursts or volume slices)
     106        NbField_j=1;
    130107    end
    131108    first_i=1;last_i=1;incr_i=1;%default
     
    136113    end
    137114    nbfield_i=numel(first_i:incr_i:last_i);%nb of fields for the i index (bursts or volume slices)
    138     nbfield=nbfield_j*nbfield_i; %total number of fields
     115    nbfield=NbField_j*nbfield_i; %total number of fields
    139116    nbfield_i=floor(nbfield/NbSlice_i);%total number of  indexes in a slice (adjusted to an integer number of slices)
    140117   
     
    143120    nbaver_init=23; %default number of images used for the sliding background: to be adjusted later to include an integer number of bursts
    144121    SaturationValue=0;
    145      if nbfield_i~=1 && nbfield_j<=nbaver_init
    146         nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
     122     if nbfield_i~=1 && NbField_j<=nbaver_init
     123        nbaver=floor(nbaver_init/NbField_j); % number of bursts used for the sliding background,
    147124        if isequal(mod(nbaver,2),0)% if nbaver is even
    148125            nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
    149126        end
    150         nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts
     127        nbaver_init=nbaver*NbField_j;%propose by default an integer number of bursts
    151128    end
    152129    BrightnessRankThreshold=0.1;
     
    161138          BrightnessRankThreshold=Param.ActionInput.BrightnessRankThreshold;
    162139        end
    163 %         if isfield(Param.ActionInput,'CheckSubmedian') && Param.ActionInput.CheckSubmedian
    164 %         CheckSubmedian='Yes';
    165 %         end
    166140        if isfield(Param.ActionInput,'SaturationValue')
    167141            SaturationValue=Param.ActionInput.SaturationValue;
     
    190164        ParamOut.NbSlice=1; %nbre of slices displayed
    191165    else
    192         step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
    193     end
    194     ParamOut.ActionInput.SlidingSequenceLength=adjust_slidinglength(str2num(answer{2}),step);
     166        step=NbField_j;%case of bursts: the sliding background is shifted by the length of one burst
     167    end
     168    ParamOut.ActionInput.SlidingSequenceLength=adjust_slidinglength(str2double(answer{2}),step);
    195169    ParamOut.ActionInput.CheckVolume=strcmp(answer{1},'Yes');
    196170    ParamOut.ActionInput.BrightnessRankThreshold=str2double(answer{3});
     
    205179
    206180%% read input parameters from an xml file if input is a file name (batch mode)
    207 checkrun=1;
     181% checkrun=1;
    208182RUNHandle=[];
    209 WaitbarHandle=[];
     183% WaitbarHandle=[];
    210184if ischar(Param)
    211185    Param=xml2struct(Param);% read Param as input file (batch case)
    212     checkrun=0;
    213 else
    214 hseries=findobj(allchild(0),'Tag','series');
     186else
     187 hseries=findobj(allchild(0),'Tag','series');
    215188RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
    216 WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
     189% WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
    217190end
    218191
     
    220193NbSlice_i=Param.IndexRange.NbSlice;
    221194if ~isequal(NbSlice_i,1)
    222     display(['multi-level splitting into ' num2str(NbSlice_i) ' slices']);
    223 end
    224 RootPath=Param.InputTable(:,1);
    225 RootFile=Param.InputTable(:,3);
    226 SubDir=Param.InputTable(:,2);
    227 NomType=Param.InputTable(:,4);
    228 FileExt=Param.InputTable(:,5);
    229 [filecell,i1_series,i2_series,j1_series]=get_file_series(Param);%series of file names organised as a single array
    230 
    231 %%%%%%%%%%%%
    232     % The cell array filecell is the list of input file names, while
    233     % filecell{iview,fileindex}:
    234     %        iview: line in the table corresponding to a given file series
    235     %        fileindex: file index within  the file series,
    236     % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
    237     % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    238 %%%%%%%%%%%%
    239 [FileInfo{1},MovieObject{1}]=get_file_info(filecell{1,1});
    240 FileType{1}=FileInfo{1}.FileType;
    241     if ~isempty(j1_series{1})
    242         frame_index{1}=j1_series{1};
    243     else
    244         frame_index{1}=i1_series{1};
    245     end
    246 
    247 
    248 %% output file naming
    249 FileExtOut='.png'; % write result as .png images for image inputsFileInfo.FileType='image'
    250 if strcmp(FileInfo{1}.FileType,'image')
    251     NomTypeOut=NomType{1};
    252 elseif isempty(j1_series{1})
    253     NomTypeOut='_1';
    254 else
    255     NomTypeOut='_1_1';% caseof purely numerical indexing
    256 end
    257 OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    258 OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
     195    disp(['multi-level splitting into ' num2str(NbSlice_i) ' slices']);
     196end
     197RootPath=Param.InputTable{1,1};
     198RootFile=Param.InputTable{1,3};
     199SubDir=Param.InputTable{1,2};
     200NomType=Param.InputTable{1,4};
     201FileExt=Param.InputTable{1,5};
     202%[filecell,i1_series,i2_series,j1_series]=get_file_series(Param);%series of file names organised as a single array
     203
    259204
    260205%% file index parameters
     
    267212% nbaver_ima: nbre of the images in the sliding sequence used for the background
    268213% nbaver=nbaver_ima/step: nbre of bursts corresponding to nbaver_ima images. It has been adjusted so that nbaver is an odd integer
    269 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    270 nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     214i_indices=Param.IndexRange.first_i:Param.IndexRange.incr_i:Param.IndexRange.last_i;
     215if isfield(Param.IndexRange,'first_j')
     216j_indices=Param.IndexRange.first_j:Param.IndexRange.incr_j:Param.IndexRange.last_j;
     217else
     218    j_indices=1;
     219end
     220nbfield_i=numel(i_indices); %nb of fields for the i index (bursts or volume slices)
     221NbField_j=numel(j_indices); %nb of fields for the j index
     222j_indices=j_indices'*ones(1,nbfield_i);
     223i_indices=ones(NbField_j,1)*i_indices;
    271224
    272225if Param.ActionInput.CheckVolume% case of volume scan: the background images must be determined for each index j
    273226    step=2;% we assume the burst contains only one image pair
    274     NbSlice_j=nbfield_j;
     227    NbSlice_j=NbField_j;
    275228    nbfield_series=nbfield_i;
    276229else
    277     step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     230    if Param.ActionInput.SlidingSequenceLength<NbField_j
     231        step=1;
     232    else
     233    step=NbField_j;%case of bursts: the sliding background is shifted by the length of one burst
     234    end
    278235    NbSlice_j=1;
    279     nbfield_series=nbfield_i*nbfield_j;
    280 end
    281 nbfield=nbfield_j*nbfield_i; %total number of fields
     236    nbfield_series=nbfield_i*NbField_j;
     237end
     238nbfield=NbField_j*nbfield_i; %total number of fields
    282239[nbaver_ima,nbaver,step]=adjust_slidinglength(Param.ActionInput.SlidingSequenceLength,step);
    283240if nbaver_ima > nbfield
    284     display('number of images in a slice smaller than the proposed number of images for the sliding average')
     241    disp('number of images in a slice smaller than the proposed number of images for the sliding average')
    285242    return
    286243end
    287244halfnbaver=floor(nbaver/2); % half width (in unit of bursts) of the sliding background
     245
     246
     247%% File relabeling documented by the xml file
     248CheckRelabel=isfield(Param,'FileSeries' );
     249
     250%% Input file info
     251if CheckRelabel
     252      [RootFileOut,FileIndexString]=index2filename(Param.FileSeries,Param.IndexRange.first_i,j_indices(1),NbField_j);
     253       FirstFileName=fullfile(RootPath,SubDir,[RootFileOut FileIndexString FileExt]);
     254else
     255FirstFileName=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,Param.IndexRange.first_i,[],j_indices(1));%get first file name
     256RootFileOut=RootFile;
     257end
     258[FileInfo,MovieObject]=get_file_info(FirstFileName);
     259FileType=FileInfo.FileType;
     260if isfield(FileInfo,'NumberOfFrames') && FileInfo.NumberOfFrames >1
     261    if isempty(regexp(NomType,'1$', 'once'))% no file indexing
     262        frame_index=i_indices;% the index i denotes the frame number in a movie, no index j
     263    else
     264        frame_index=j_indices;% the index j denotes the frame number in a movie
     265        MovieObject=[]; %not a single video object
     266    end
     267else
     268    frame_index=ones(1,nbfield);
     269end
     270
     271%% output file naming
     272FileExtOut='.png'; % write result as .png images for image inputsFileInfo.FileType='image'
     273if strcmp(FileInfo.FileType,'image')
     274    NomTypeOut=NomType;
     275elseif NbField_j==1
     276    NomTypeOut='_1';
     277else
     278    NomTypeOut='_1_1';% case of purely numerical indexing
     279end
     280OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     281OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
    288282
    289283%% calculate absolute brightness rank
     
    294288
    295289%% prealocate memory for the sliding background
    296 try
    297     Afirst=read_image(filecell{1,1},FileType{1},MovieObject{1},frame_index{1}(1));
    298     [npy,npx,nbcolor]=size(Afirst);% the argument nbcolor is important to get npx right for color images
    299     if strcmp(class(Afirst),'uint8') % case of 8bit images
    300         Ak=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory
    301         Asort=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory
    302     else
    303         Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
    304         Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
    305     end
    306 catch ME
    307     msgbox_uvmat('ERROR',['sub_background/read_image/' ME.message])
    308     return
    309 end
    310 
    311 %selection of frame indices
     290Ak=zeros(FileInfo.Height,FileInfo.Width,nbaver_ima,['uint' num2str(FileInfo.BitDepth)]); %prealocate memory   
     291
     292%% selection of frame indices
    312293if Param.ActionInput.CheckVolume
    313294    nbfield=floor(nbfield/NbSlice_j)*NbSlice_j;% truncate the total number of frames in case of incomplete series
     
    326307%%%%%%%  LOOP ON SLICES %%%%%%%
    327308for j_slice=1:NbSlice
    328     %% select the series of i indices to process
    329  %   indselect=j_slice:step*NbSlice_j:nbfield;% select file indices of the slice
    330 %     for ifield=1:step-1
    331 %         indselect=[indselect;indselect(end,:)+NbSlice];
    332 %     end
    333    
     309
    334310    %% read the first series of nbaver_ima images and sort by luminosity at each pixel
    335311    for ifield = 1:nbaver_ima
    336         ifile=indselect(jslice,ifield);
    337         filename=filecell{1,ifile};
    338         Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
     312        ifile=indselect(j_slice,ifield);
     313        %filename=filecell{1,ifile};
     314        if CheckRelabel
     315            [RootFile,FileIndexString,FrameIndex]=index2filename(Param.FileSeries,i_indices(ifile),j_indices(ifile),NbField_j);
     316            filename=fullfile(RootPath,SubDir,[RootFile FileIndexString FileExt]);
     317        else
     318            filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i_indices(ifile),[],j_indices(ifile));
     319            FrameIndex=frame_index(ifile);
     320        end
     321        Aread=read_image(filename,FileType,MovieObject,FrameIndex);
    339322        if ndims(Aread)==3%color images
    340323            Aread=sum(double(Aread),3);% take the sum of color components
     
    344327    Asort=sort(Ak,3);%sort the luminosity of images at each point
    345328    B=Asort(:,:,rank);%background image
    346    
     329
    347330    %% substract the first background image to the first images
    348     display( 'first background image will be substracted')
     331    disp( 'first background image will be substracted')
    349332    for ifield=1:step*(halfnbaver+1)% nbre of images treated by the first background image
    350333        Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
    351334        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    352         ifile=indselect(jslice,ifield);
    353         j1=1;
    354         if ~isempty(j1_series{1})
    355             j1=j1_series{1}(ifile);
    356         end
    357         newname=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    358        
     335        ifile=indselect(j_slice,ifield);
     336        newname=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,FileExtOut,NomTypeOut,i_indices(ifile),[],j_indices(ifile));
     337
    359338        %write result file
    360339        if ~isequal(Param.ActionInput.SaturationValue,0)
     
    362341            imwrite(C,newname,'BitDepth',16); % save the new image
    363342        else
    364             if ~isfield(FileInfo{1},'BitDepth')
    365                 FileInfo{1}.BitDepth=16;
    366             end
    367             if isequal(FileInfo{1}.BitDepth,16)
     343            if isequal(FileInfo.BitDepth,16)
    368344                C=uint16(Acor);
    369345                imwrite(C,newname,'BitDepth',16); % save the new image
     
    373349            end
    374350        end
    375         display([newname ' written'])
    376     end
    377    
     351        disp([newname ' written'])
     352    end
     353
    378354    %% repeat the operation on a sliding series of images
    379     display('sliding background image will be substracted')
     355    disp('sliding background image will be substracted')
    380356    if nbfield_series > nbaver_ima
    381357        for ifield = step*(halfnbaver+1):step:nbfield_series-step*(halfnbaver+1)% ifield +iburst=index of the current processed image
    382             update_waitbar(WaitbarHandle,ifield/nbfield_series)
     358            %             update_waitbar(WaitbarHandle,ifield/nbfield_series)
    383359            if  ~isempty(RUNHandle)&&~strcmp(get(RUNHandle,'BusyAction'),'queue')
    384360                disp('program stopped by user')
     
    386362            end
    387363            if nbaver_ima>step
    388             Ak(:,:,1:nbaver_ima-step)=Ak(:,:,1+step:nbaver_ima);% shift the current image series by one burst (step)
     364                Ak(:,:,1:nbaver_ima-step)=Ak(:,:,1+step:nbaver_ima);% shift the current image series by one burst (step)
    389365            end
    390366            %incorporate next burst in the current image series
    391367            for iburst=1:step
    392                 ifile=indselect(jslice,ifield+iburst+step*halfnbaver);
    393                 j1=1;
    394                 if ~isempty(j1_series{1})
    395                     j1=j1_series{1}(ifile);
     368                ifile=indselect(j_slice,ifield+iburst+step*halfnbaver);
     369                if CheckRelabel
     370                    [RootFile,FileIndexString,FrameIndex]=index2filename(Param.FileSeries,i_indices(ifile),j_indices(ifile),NbField_j);
     371                    filename=fullfile(RootPath,SubDir,[RootFile FileIndexString FileExt]);
     372                else
     373                    filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i_indices(ifile),[],j_indices(ifile));
     374                    FrameIndex=frame_index(ifile);
    396375                end
    397                
    398                 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
    399                 Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
     376                Aread=read_image(filename,FileType,MovieObject,FrameIndex);
    400377                if ndims(Aread)==3%case of color images
    401378                    Aread=sum(double(Aread),3);% take the sum of color components
     
    409386                Acor=double(Ak(:,:,step*halfnbaver+iburst))-double(B); %the current image has been already read ans stored as index step*halfnbaver+iburst in the current series
    410387                Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    411                 ifile=indselect(jslice,ifield+iburst);
    412                 if ~isempty(j1_series{1})
    413                     j1=j1_series{1}(ifile);
    414                 end
    415                 newname=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     388                ifile=indselect(j_slice,ifield+iburst);
     389                newname=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,FileExtOut,NomTypeOut,i_indices(ifile),[],j_indices(ifile));
    416390                %write result file
    417391                if ~isequal(Param.ActionInput.SaturationValue,0)
     
    419393                    imwrite(C,newname,'BitDepth',16); % save the new image
    420394                else
    421                     if isequal(FileInfo{1}.BitDepth,16)
     395                    if isequal(FileInfo.BitDepth,16)
    422396                        C=uint16(Acor);
    423397                        imwrite(C,newname,'BitDepth',16); % save the new image
     
    427401                    end
    428402                end
    429                 display([newname ' written'])
    430             end
    431         end
    432     end
    433    
     403                disp([newname ' written'])
     404            end
     405        end
     406    end
     407
    434408    %% substract the background from the last images
    435     display('last background image will be substracted')
     409    disp('last background image will be substracted')
    436410    for  ifield=nbfield_series-step*halfnbaver+1:nbfield_series
    437411        Acor=double(Ak(:,:,ifield-nbfield_series+step*(2*halfnbaver+1)))-double(B);
    438412        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    439         ifile=indselect(jslice,ifield);
    440         if ~isempty(j1_series{1})
    441             j1=j1_series{1}(ifile);
    442         end
    443         newname=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     413        ifile=indselect(j_slice,ifield);
     414        newname=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,FileExtOut,NomTypeOut,i_indices(ifile),[],j_indices(ifile));
    444415        %write result file
    445416        if ~isequal(Param.ActionInput.SaturationValue,0)
     
    447418            imwrite(C,newname,'BitDepth',16); % save the new image
    448419        else
    449             if isequal(FileInfo{1}.BitDepth,16)
     420            if isequal(FileInfo.BitDepth,16)
    450421                C=uint16(Acor);
    451422                imwrite(C,newname,'BitDepth',16); % save the new image
     
    455426            end
    456427        end
    457         display([newname ' written'])
     428        disp([newname ' written'])
    458429    end
    459430end
Note: See TracChangeset for help on using the changeset viewer.