Ignore:
Timestamp:
Jun 13, 2012, 5:04:14 PM (12 years ago)
Author:
sommeria
Message:

aver_stat, ima_levels , sub_background now adapted to the new settings
merge_proj, time_series still need to be modified

File:
1 edited

Legend:

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

    r451 r454  
    99    % luminosity, but it can be polluted by noise.
    1010% Organization of image indices:
    11     % The program is working on a series of images, labelled by two indices i and j, given
    12     % by the input matlab vectors num_i1 and num_j1 respectively. In the list, j is the fastest increasing index.
    13     % The processing can be done in slices (number nbslice), with bursts of
    14     % nbfield2 successive images for a given slice (mode 'multilevel')
    15     % In the mode 'volume', nbfield2=1 (1 image at each level)
    16    
    17 % function GUI_input=sub_background(Param)
     11    % The program is working on a series of images,
     12    % The processing can be done over groups of nbfield2 consecutive files in slices (parameter NbSlice)
     13    % In the mode 'volume', nbfield2=1 (1 image at each level)and NbSlice (=nbfield_j)
     14    % Else nbfield2=nbfield_j =nbre of images in a burst (j index)
     15   
     16% function GUI_series_config=sub_background(Param)
    1817%
    1918%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    2019%OUTPUT
    21 % GUI_input=list of options in the GUI series.fig needed for the function
     20% GUI_series_config=list of options in the GUI series.fig needed for the function
    2221%
    2322%INPUT:
     
    2524% In batch mode, Param is the name of the corresponding xml file containing the same information
    2625% In the absence of input (as activated when the current Action is selected
    27 % in series), the function ouput GUI_input set the activation of the needed GUI elements
     26% in series), the function ouput GUI_series_config set the activation of the needed GUI elements
    2827%
    2928% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     
    4746
    4847   
    49 function GUI_input=sub_background (Param)
     48function GUI_config=sub_background (Param,get_param)
    5049
    5150%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5251if ~exist('Param','var') % case with no input parameter
    53     GUI_input={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
     52    GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
    5453        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    5554        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    5958        'ProjObject';'off';...%can use projection object(option 'off'/'on',
    6059        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
    61         'OutputDirExt';'.sbk';...%set the output dir extension
     60        'OutputDirExt';'.sback';...%set the output dir extension
    6261               ''};
    6362        return
     
    6766%% get input parameters, file names and indices
    6867% BATCH  case: read the xml file for batch case
    69 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
    70     Param=xml2struct(Param);
    71     checkrun=0;
    72 % RUN case: parameters introduced as the input structure Param 
    73 else
     68if exist('get_param','var') && isequal(get_param,0)
     69    checkrun=-1; %the function is just used to define to complement the input parameters
     70elseif ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) %batch mode
     71        Param=xml2struct(Param);
     72        checkrun=0;
     73    % RUN case: parameters introduced as the input structure Param
     74else
    7475    hseries=guidata(Param.hseries);%handles of the GUI series
    7576    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     
    8586% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    8687% set of frame indices used for movie or multimage input
    87 if ~isempty(j1_series)
    88     frame_index=j1_series;
    89 else
    90     frame_index=i1_series;
    91 end
     88
    9289
    9390%% root input file(s) and type
     
    103100    NbSlice=Param.IndexRange.NbSlice;
    104101end
    105 nbview=size(i1_series,1);%number of input file series (lines in InputTable)
    106 nbfield_j=size(i1_series,2); %nb of consecutive fields at each level(burst
    107 nbfield=nbfield_j*size(i1_series,3); %total number of files or frames
    108 nbfield_i=floor(nbfield/NbSlice);%total number of i indexes (adjusted to an integer number of slices)
    109 nbfield=nbfield_i*nbfield_j; %total number of fields after adjustement
     102nbview=numel(i1_series);%number of input file series (lines in InputTable)
     103nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     104nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     105nbfield=nbfield_j*nbfield_i; %total number of fields
     106nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     107nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    110108
    111109%determine the file type on each line from the first input file
    112 ImageTypeOptions={'image','multimage','mmreader','video'};
    113 NcTypeOptions={'netcdf','civx','civdata'};
    114    
    115 % % for iview=1:nbview
    116 %     if ~exist(filecell{iview,1}','file')
    117 %         msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
    118 %         return
    119 %     end
    120 %     [FileType{iview},FileInfo{iview},Object{iview}]=get_file_type(filecell{iview,1});
    121 %     CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
    122 %     CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
    123 % end
    124 
    125 [FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1});
    126 CheckImage=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     110ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     111
     112[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     113CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     114if ~isempty(j1_series{1})
     115    frame_index{1}=j1_series{1};
     116else
     117    frame_index{1}=i1_series{1};
     118end
    127119
    128120%% calibration data and timing: read the ImaDoc files
     
    139131
    140132 %% check the validity of  input file types
    141 if CheckImage
     133if CheckImage{1}
    142134    FileExtOut='.png'; % write result as .png images for image inputs
    143     NomTypeOut='_1_1';
     135    if strcmp(lower(NomType{1}(end)),'a')
     136        NomTypeOut=NomType{1};%case of letter appendix
     137    else
     138        NomTypeOut='_1_1';% caseof purely numerical indexing
     139    end
    144140else
    145141    msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image'])
    146142    return
    147143end
    148 %
    149 % NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
    150 % if NbSlice~=nbfield_j
    151 %     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
    152 %     if ~strcmp(answer,'Yes')
    153 %         return
    154 %     end
    155 % end
    156144
    157145%% Set field names and velocity types
    158146%not relevant here
    159 
    160147
    161148%% Initiate output fields
     
    164151%%% SPECIFIC PART BEGINS HERE
    165152NbSlice=Param.IndexRange.NbSlice; %number of slices
    166 siz=size(i1_series);
     153%siz=size(i1_series);
    167154nbaver_init=23;%approximate number of images used for the sliding background: to be adjusted later to include an integer number of bursts
    168155j1=[];%default
    169156
    170 %% apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
    171 answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
    172 test_level=isequal(answer,'Yes');
    173 
    174157%% adjust the proposed number of images in the sliding average to include an integer number of bursts
    175 if siz(3)~=1
    176     nbaver=floor(nbaver_init/siz(2)); % number of bursts used for the sliding background,
     158if nbfield_i~=1
     159    nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
    177160    if isequal(floor(nbaver/2),nbaver)
    178161        nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
    179162    end
    180     nbaver_init=nbaver*siz(2);%propose by default an integer number of bursts
     163    nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts
    181164end
    182165
    183166%% set processing parameters
    184 prompt = {'Number of images for the sliding background (MUST FIT IN COMPUETER MEMORY)';'The number of positions (laser slices)';'volume scan mode (Yes/No)';...
    185     'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
    186 dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' Param.OutputDir];
    187 num_lines= 3;
    188 def     = { num2str(nbaver_init);num2str(NbSlice);'No';'0.1'};
    189 answer = inputdlg(prompt,dlg_title,num_lines,def);
    190 set(hseries.ParamVal,'String',answer([1 [3:4]]))
    191 set(hseries.ParamVal,'Visible','on')
    192 
    193 nbaver_ima=str2num(answer{1});%number of images for the sliding background
    194 nbaver=ceil(nbaver_ima/siz(2));%number of bursts for the sliding background
    195 if isequal(floor(nbaver/2),nbaver)
    196     nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
    197 end
    198 step=siz(2);%case of bursts: the sliding background is shifted by one burst
    199 vol_test=answer{3};
    200 if isequal(vol_test,'Yes')
    201     nbfield2=1;%case of volume: no consecutive series at a given level
    202     NbSlice=siz(2);%number of slices
     167if checkrun ==-1
     168    prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
     169        'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
     170    dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' Param.OutputDir];
     171    num_lines= 3;
     172    def     = { 'No';num2str(nbaver_init);'0.1'};
     173    answer = inputdlg(prompt,dlg_title,num_lines,def);
     174   
     175    %check input consistency
     176    if strcmp(answer{1},'No') && ~isequal(NbSlice,1)
     177        check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice) ' slices']);
     178        if ~strcmp(check,'Yes')
     179            return
     180        end
     181    end
     182    if strcmp(answer{1},'Yes')
     183        step=1;
     184    else
     185        step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     186    end
     187    nbaver_ima=str2num(answer{2});%number of images for the sliding background
     188    nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
     189    if isequal(floor(nbaver/2),nbaver)
     190        nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     191    end
     192    nbaver_ima=nbaver*step;
     193    if nbaver_ima > nbfield
     194        msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
     195        return
     196    end
     197    GUI_config.CheckVolume=strcmp(answer{1},'Yes');
     198    GUI_config.SlidingSequenceSize=nbaver_ima;
     199    GUI_config.BrightnessRankThreshold=str2num(answer{3});
     200   
     201    % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
     202    answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
     203    GUI_config.CheckLevelTransform=strcmp(answer,'Yes');
     204   
     205    % return to BATCH mode
     206    if checkrun==-1
     207        return %transfer to BATCH mode
     208    end
    203209else
    204     nbfield2=siz(2); %nb of consecutive images at each level(burst)
    205     if siz(3)>1
    206         % NbSlice=str2num(answer{2})/(num_i1(1,2)-num_i1(1,1));% number of slices
    207         NbSlice=str2num(answer{2})/(i1_series(1,1,2)-i1_series(1,1,1));% number of slices
     210    GUI_config=Param.Specific;
     211    if isequal(GUI_config.CheckVolume,1)
     212        step=1;
    208213    else
    209         NbSlice=1;
    210     end
    211     if ~isequal(floor(NbSlice),NbSlice)
    212         msgbox_uvmat('ERROR','the number of slices must be a multiple of the i increment')
     214        step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     215    end
     216    nbaver_ima=GUI_config.SlidingSequenceSize;%number of images for the sliding background
     217    nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
     218    if isequal(floor(nbaver/2),nbaver)
     219        nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     220    end
     221    nbaver_ima=nbaver*step;
     222    if nbaver_ima > nbfield
     223        msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
    213224        return
    214225    end
    215226end
    216 rank=floor(str2num(answer{4})*nbaver_ima);
     227
     228% calculate absolute brightness rank
     229rank=floor(GUI_config.BrightnessRankThreshold*nbaver_ima);
    217230if rank==0
    218231    rank=1;%rank selected in the sorted image series
    219232end
    220 lengthtot=siz(2)*siz(3);
    221 nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
    222 nbfield_slice=nbfield*nbfield2;% number of fields per slice
    223 if nbaver_ima > nbfield*nbfield2
    224     msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
    225     return
    226 end
    227 nbfirst=(ceil(nbaver/2))*step;
    228 if nbfirst>nbaver_ima
    229     nbfirst=ceil(nbaver_ima/2);
    230     step=1;
    231     nbaver=nbaver_ima;
    232 end
    233233
    234234%% prealocate memory for the sliding background
    235 Afirst=read_image(filecell{1,1},FileType{1},MovieObject,i1_series(1,1));
    236 [npy,npx]=size(Afirst);
    237235try
    238     Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
    239     Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
     236    Afirst=read_image(filecell{1,1},FileType{1},MovieObject{1},frame_index{1}(1));
     237    [npy,npx]=size(Afirst);
     238    if strcmp(class(Afirst),'uint8') % case of 8bit images
     239        Ak=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory
     240        Asort=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory
     241    else
     242        Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
     243        Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
     244    end
    240245catch ME
    241246    msgbox_uvmat('ERROR',ME.message)
     
    244249
    245250%% update the xml file
    246 SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.'
    247 filexml=fullfile(RootPath{1},[SubDirBase '.xml']);
    248 if ~exist(filexml,'file') && exist([filebase '.xml'],'file')% xml inside the image directory
    249     copyfile([filebase '.xml'],filexml);% copy the .xml file
    250 end
    251 if exist(filexml,'file')
    252     t=xmltree(filexml); 
    253     %update information on the first image name in the series
    254     uid_Heading=find(t,'ImaDoc/Heading');
    255     if isempty(uid_Heading)
    256         [t,uid_Heading]=add(t,1,'element','Heading');
    257     end
    258     uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
    259     if ~isempty(j1_series{1})
    260         j1=j1_series{1}(1);
    261     end
    262     ImageName=fullfile_uvmat([dir_images term],'',RootFile{1},'.png',NomType,i1_series(1,1),[],j1);
    263     [pth,ImageName]=fileparts(ImageName);
    264     ImageName=[ImageName '.png'];
    265     if isempty(uid_ImageName)
    266         [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
    267     end
    268     uid_value=children(t,uid_ImageName);
    269     if isempty(uid_value)
    270         t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
    271     else
    272         t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
    273     end
    274    
    275     %add information about image transform
    276     [t,new_uid]=add(t,1,'element','ImageTransform');
    277     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
    278     [t]=add(t,NameFunction_uid,'chardata','sub_background');
    279     if test_level
    280         [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
    281         [t]=add(t,NameFunction_uid,'chardata','levels');
    282     end
    283     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
    284     [t]=add(t,new_uid,'chardata',num2str(NbSlice));
    285     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
    286     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
    287     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
    288     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
    289     save(t,filexml)
    290 end
     251% SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.'
     252% filexml=fullfile(RootPath{1},[SubDirBase '.xml']);
     253% if ~exist(filexml,'file') && exist([fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml'],'file')% xml inside the image directory
     254%     copyfile([filebase '.xml'],filexml);% copy the .xml file
     255% end
     256% if exist(filexml,'file')
     257%     t=xmltree(filexml); 
     258%     %update information on the first image name in the series
     259%     uid_Heading=find(t,'ImaDoc/Heading');
     260%     if isempty(uid_Heading)
     261%         [t,uid_Heading]=add(t,1,'element','Heading');
     262%     end
     263%     uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
     264%     if ~isempty(j1_series{1})
     265%         j1=j1_series{1}(1);
     266%     end
     267%     ImageName=fullfile_uvmat([dir_images term],'',RootFile{1},'.png',NomType,i1_series(1,1),[],j1);
     268%     [pth,ImageName]=fileparts(ImageName);
     269%     ImageName=[ImageName '.png'];
     270%     if isempty(uid_ImageName)
     271%         [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
     272%     end
     273%     uid_value=children(t,uid_ImageName);
     274%     if isempty(uid_value)
     275%         t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
     276%     else
     277%         t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
     278%     end
     279%    
     280%     %add information about image transform
     281%     [t,new_uid]=add(t,1,'element','ImageTransform');
     282%     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
     283%     [t]=add(t,NameFunction_uid,'chardata','sub_background');
     284%     if GUI_config.CheckLevel
     285%         [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
     286%         [t]=add(t,NameFunction_uid,'chardata','levels');
     287%     end
     288%     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
     289%     [t]=add(t,new_uid,'chardata',num2str(NbSlice));
     290%     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
     291%     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
     292%     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
     293%     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
     294%     save(t,filexml)
     295% end
    291296%copy the mask
    292297% if exist([filebase '_1mask_1'],'file')
     
    297302for islice=1:NbSlice
    298303    %% select the series of image indices at the level islice
    299     for ifield=1:nbfield
    300         for iburst=1:nbfield2
    301             indselect(iburst,ifield)=((ifield-1)*NbSlice+(islice-1))*nbfield2+iburst;
    302         end
     304    indselect=islice:NbSlice*step:nbfield;% select file indices of the slice
     305    for ifield=1:step-1
     306        indselect=[indselect;indselect(end,:)+1];
    303307    end
    304308   
     
    307311        ifile=indselect(ifield);
    308312        filename=filecell{1,ifile};
    309         Aread=read_image(filename,FileType,MovieObject,i1_series{1}(ifile));
     313        Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
     314        if ndims(Aread)==3;%color images
     315            Aread=sum(double(Aread),3);% take the sum of color components
     316        end
    310317        Ak(:,:,ifield)=Aread;
    311318    end
     
    313320    B=Asort(:,:,rank);%background image
    314321    display( 'first background image will be substracted')
     322    nbfirst=(ceil(nbaver/2))*step;
    315323    for ifield=1:nbfirst
    316324        Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
    317325        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    318         C=uint16(Acor);% set to integer 16 bits
    319326        ifile=indselect(ifield);
    320         %             newname=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType)% makes the new file name
    321327        if ~isempty(j1_series{1})
    322328            j1=j1_series{1}(ifile);
    323329        end
    324         newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,ifile),[],i_slice,[]);
    325 %         newname=fullfile_uvmat(RootPath{1},SubdirResult,RootFile{1},'.png',NomType,i1_series{1}(ifile),[],j1);
    326         %newname=name_generator(filebase_b,i1_series{1}(ifile),j1_series{1}(ifile),'.png',NomType);% makes the new file name
    327         if test_level
    328             C=levels(C);
     330        newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     331       
     332        %write result file
     333        if GUI_config.CheckLevelTransform
     334            C=levels(Acor);
    329335            imwrite(C,newname,'BitDepth',8); % save the new image
    330336        else
    331             imwrite(C,newname,'BitDepth',16); % save the new image
    332         end
    333     end
    334    
    335     %% repeat the operation on a sliding series of nbaver*nbfield2 images
     337            if isequal(FileInfo{1}.BitDepth,16)
     338                C=uint16(Acor);
     339                imwrite(C,newname,'BitDepth',16); % save the new image
     340            else
     341                C=uint8(Acor);
     342                imwrite(C,newname,'BitDepth',8); % save the new image
     343            end
     344        end
     345        display([newname ' written'])
     346    end
     347   
     348    %% repeat the operation on a sliding series of images
    336349    display('sliding background image will be substracted')
    337     if nbfield_slice > nbaver_ima
    338         for ifield = step*ceil(nbaver/2)+1:step:nbfield_slice-step*floor(nbaver/2)
     350    if nbfield_i > nbaver_ima
     351        for ifield = step*ceil(nbaver/2)+1:step:nbfield_i-step*floor(nbaver/2)
    339352            if checkrun
    340353                stopstate=get(hseries.RUN,'BusyAction');
    341                 update_waitbar(hseries.waitbar_frame,WaitbarPos,(ifield+(islice-1)*nbfield_slice)/(nbfield_slice*NbSlice))
     354                update_waitbar(hseries.waitbar_frame,WaitbarPos,(ifield+(islice-1)*nbfield_i)/(nbfield_i*NbSlice))
    342355            else
    343356                stopstate='queue';
     
    348361                for iburst=1:step
    349362                    ifile=indselect(ifield+step*floor(nbaver/2)+iburst-1);
    350                     filename=fullfile_uvmat(RootPath{1},SubDir,RootFile{1},FileExt,NomType,i1_series(1,ifile),[],j1_series(1,ifile));
    351                     %filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),FileExt,NomType);
    352                     Aread=read_image(filename,FileType,MovieObject,i1_series(1,ifile));
     363                    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1_series{1}(ifile));
     364                    Aread=read_image(filename,FileType{1},MovieObject{1},i1_series{1}(ifile));
     365                    if ndims(Aread)==3;%color images
     366                        Aread=sum(double(Aread),3);% take the sum of color components
     367                    end
    353368                    Ak(:,:,nbaver_ima-step+iburst)=Aread;
    354369                end
     
    359374                    Acor=double(Ak(:,:,index))-double(B);
    360375                    Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    361                     C=uint16(Acor);
    362376                    ifile=indselect(ifield+iburst-1);
    363377                    if ~isempty(j1_series{1})
    364378                        j1=j1_series{1}(ifile);
    365379                    end
    366                     newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,1),[],i_slice,[]);
    367                    % newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    368                     %[newname]=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType) % makes the new file name
    369                     if test_level
    370                         C=levels(C);
     380                    newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     381                    %write result file
     382                    if GUI_config.CheckLevelTransform
     383                        C=levels(Acor);
    371384                        imwrite(C,newname,'BitDepth',8); % save the new image
    372385                    else
    373                         imwrite(C,newname,'BitDepth',16); % save the new image
     386                        if isequal(FileInfo{1}.BitDepth,16)
     387                            C=uint16(Acor);
     388                            imwrite(C,newname,'BitDepth',16); % save the new image
     389                        else
     390                            C=uint8(Acor);
     391                            imwrite(C,newname,'BitDepth',8); % save the new image
     392                        end
    374393                    end
     394                    display([newname ' written'])
     395                   
    375396                end
    376397            else
     
    382403    %% substract the background from the last images
    383404    display('last background image will be substracted')
    384     ifield=nbfield_slice-(step*ceil(nbaver/2))+1:nbfield_slice;
    385     for ifield=nbfield_slice-(step*floor(nbaver/2))+1:nbfield_slice
    386         index=ifield-nbfield_slice+step*(2*floor(nbaver/2)+1);
     405    ifield=nbfield_i-(step*ceil(nbaver/2))+1:nbfield_i;
     406    for ifield=nbfield_i-(step*floor(nbaver/2))+1:nbfield_i
     407        index=ifield-nbfield_i+step*(2*floor(nbaver/2)+1);
    387408        Acor=double(Ak(:,:,index))-double(B);
    388409        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    389         C=uint16(Acor);
    390410        ifile=indselect(ifield);
    391411        if ~isempty(j1_series{1})
    392412            j1=j1_series{1}(ifile);
    393413        end
    394         newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,ifile),[],j1);
    395 %         newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    396         if test_level
    397             C=levels(C);
     414        newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     415       
     416        %write result file
     417        if GUI_config.CheckLevelTransform
     418            C=levels(Acor);
    398419            imwrite(C,newname,'BitDepth',8); % save the new image
    399420        else
    400             imwrite(C,newname,'BitDepth',16); % save the new image
    401         end
     421            if isequal(FileInfo{1}.BitDepth,16)
     422                C=uint16(Acor);
     423                imwrite(C,newname,'BitDepth',16); % save the new image
     424            else
     425                C=uint8(Acor);
     426                imwrite(C,newname,'BitDepth',8); % save the new image
     427            end
     428        end
     429        display([newname ' written'])
    402430    end
    403431end
     
    406434if checkrun
    407435    update_waitbar(hseries.waitbar,WaitbarPos,1)
    408 end
    409 
    410 %------------------------------------------------------------------------
    411 %--read images and convert them to the uint16 format used for PIV
    412 function A=read_image(FileName,FileType,VideoObject,num)
    413 %------------------------------------------------------------------------
    414 %num is the view number needed for an avi movie
    415 switch FileType
    416     case {'video','mmreader'}
    417         A=read(VideoObject,num);
    418     case 'multimage'
    419         A=imread(FileName,num);
    420     case 'image'   
    421         A=imread(FileName);
    422 end
    423 siz=size(A);
    424 if length(siz)==3;%color images
    425     A=sum(double(A),3);% take the sum of color components
    426436end
    427437   
Note: See TracChangeset for help on using the changeset viewer.