Ignore:
Timestamp:
Mar 25, 2013, 6:34:00 PM (11 years ago)
Author:
sommeria
Message:

commit the series fcts with the new form

File:
1 edited

Legend:

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

    r573 r592  
    5555function ParamOut=sub_background (Param)
    5656
    57 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    58 if ~exist('Param','var') % case with no input parameter
    59     ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    60         'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    61         'NbSlice';'on'; ...%nbre of slices ('off' by default)
    62         'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
    63         'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    64         'FieldTransform'; 'off';...%can use a transform function
    65         'ProjObject';'off';...%can use projection object(option 'off'/'on',
    66         'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
    67         'OutputDirExt';'.sback';...%set the output dir extension
    68                ''};
     57%% input preparation mode (no RUN)
     58if isstruct(Param) && isequal(Param.Action.RUN,0)
     59    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
     60    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
     61    ParamOut.NbSlice='on'; ...%nbre of slices ('off' by default)
     62    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     63    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     64    ParamOut.FieldTransform = 'off';...%can use a transform function
     65    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
     66    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
     67    ParamOut.OutputDirExt='.sback';%set the output dir extension
     68   
     69    %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     70   
     71    %% root input file(s) and type
     72%     RootPath=Param.InputTable(:,1);
     73%     RootFile=Param.InputTable(:,3);
     74%     SubDir=Param.InputTable(:,2);
     75%     NomType=Param.InputTable(:,4);
     76%     FileExt=Param.InputTable(:,5);
     77    [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     78    %%%%%%%%%%%%
     79    % The cell array filecell is the list of input file names, while
     80    % filecell{iview,fileindex}:
     81    %        iview: line in the table corresponding to a given file series
     82    %        fileindex: file index within  the file series,
     83    % 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
     84    % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     85    %%%%%%%%%%%%
     86    NbSlice=1;%default
     87    if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     88        NbSlice=Param.IndexRange.NbSlice;
     89    end
     90    nbview=numel(i1_series);%number of input file series (lines in InputTable)
     91    nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     92    nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     93    nbfield=nbfield_j*nbfield_i; %total number of fields
     94    nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     95    nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     96   
     97    %determine the file type on each line from the first input file
     98
     99   
     100    %% calibration data and timing: read the ImaDoc files
     101    %not relevant here
     102   
     103    %% check coincidence in time for several input file series
     104    %not relevant here
     105   
     106    %% coordinate transform or other user defined transform
     107    %not relevant here
     108   
     109    %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     110    % EDIT FROM HERE
     111   
     112    %% check the validity of  input file types
     113    ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     114    FileType=get_file_type(filecell{1,1});
     115    CheckImage=~isempty(find(strcmp(FileType,ImageTypeOptions), 1));% =1 for images
     116    if ~CheckImage
     117        msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image'])
    69118        return
    70 end
    71 
    72 %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
    73 %% select different modes,  RUN, parameter input, BATCH
    74 % BATCH  case: read the xml file for batch case
     119    end
     120   
     121    %% Set field names and velocity types
     122    %not relevant here
     123   
     124    %% Initiate output fields
     125    %not relevant here
     126   
     127    %%% SPECIFIC PART BEGINS HERE
     128    NbSlice=1;
     129    if isfield(Param.IndexRange,'NbSlice')
     130        NbSlice=Param.IndexRange.NbSlice; %number of slices
     131    end
     132    %siz=size(i1_series);
     133    nbaver_init=23;%approximate number of images used for the sliding background: to be adjusted later to include an integer number of bursts
     134    j1=[];%default
     135   
     136    %% adjust the proposed number of images in the sliding average to include an integer number of bursts
     137    if nbfield_i~=1
     138        nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
     139        if isequal(floor(nbaver/2),nbaver)
     140            nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
     141        end
     142        nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts
     143    end
     144   
     145    %% input of specific parameters
     146    %if checkrun %get specific parameters interactively
     147    if isequal(Param.Action.RUN,0)
     148        prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
     149            'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
     150        dlg_title = 'get (slice by slice) a sliding background and substract to each image';
     151        num_lines= 3;
     152        def     = { 'No';num2str(nbaver_init);'0.1'};
     153        answer = inputdlg(prompt,dlg_title,num_lines,def);
     154       
     155        %check input consistency
     156        if strcmp(answer{1},'No') && ~isequal(NbSlice,1)
     157            check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice) ' slices']);
     158            if ~strcmp(check,'Yes')
     159                return
     160            end
     161        end
     162        if strcmp(answer{1},'Yes')
     163            step=1;
     164        else
     165            step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     166        end
     167        nbaver_ima=str2num(answer{2});%number of images for the sliding background
     168        nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
     169        if isequal(floor(nbaver/2),nbaver)
     170            nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     171        end
     172        nbaver_ima=nbaver*step;
     173    end
     174    ParamOut.InputGUI.CheckVolume=strcmp(answer{1},'Yes');
     175    ParamOut.InputGUI.SlidingSequenceLength=nbaver_ima;
     176    ParamOut.InputGUI.BrightnessRankThreshold=str2num(answer{3});
     177   
     178    % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
     179    answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
     180    ParamOut.InputGUI.CheckLevelTransform=strcmp(answer,'Yes');
     181    return
     182end
     183%%%%%%%%%%%%%%%%%%%%%%  STOP HERE FOR PAMETER INPUT MODE  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     184
     185%% read input parameters from an xml file if input is a file name (batch mode)
     186checkrun=1;
    75187if ischar(Param)
    76         Param=xml2struct(Param);
    77         checkrun=0;
    78 % RUN case: parameters introduced as the input structure Param
    79 else
    80     hseries=guidata(Param.hseries);%handles of the GUI series
    81     if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
    82         checkrun=1;% will search input parameters (preparation of BATCH mode)
    83     else
    84         checkrun=2; % indicate the RUN option is used
    85     end
    86 end
    87 ParamOut=Param; %default output
    88 OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    89 
    90 %% root input file(s) and type
     188    Param=xml2struct(Param);% read Param as input file (batch case)
     189    checkrun=0;
     190end
     191
     192%% Input preparation
     193nbaver_ima=Param.InputGUI.SlidingSequenceLength;
     194NbSlice=Param.IndexRange.NbSlice;
     195if ~isequal(NbSlice,1)
     196    display(['multi-level splitting into ' num2str(NbSlice) ' slices']);
     197end
    91198RootPath=Param.InputTable(:,1);
    92199RootFile=Param.InputTable(:,3);
     
    95202FileExt=Param.InputTable(:,5);
    96203[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    97 %%%%%%%%%%%%
    98 % The cell array filecell is the list of input file names, while
    99 % filecell{iview,fileindex}:
    100 %        iview: line in the table corresponding to a given file series
    101 %        fileindex: file index within  the file series,
    102 % 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
    103 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    104 %%%%%%%%%%%%
    105 NbSlice=1;%default
    106 if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    107     NbSlice=Param.IndexRange.NbSlice;
    108 end
    109 nbview=numel(i1_series);%number of input file series (lines in InputTable)
     204[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     205    if ~isempty(j1_series{1})
     206        frame_index{1}=j1_series{1};
     207    else
     208        frame_index{1}=i1_series{1};
     209    end
    110210nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    111211nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    112212nbfield=nbfield_j*nbfield_i; %total number of fields
    113 nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
     213nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    114214nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    115215
    116 %determine the file type on each line from the first input file
    117 ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
    118 
    119 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
    120 CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
    121 if ~isempty(j1_series{1})
    122     frame_index{1}=j1_series{1};
     216%% Output
     217FileExtOut='.png'; % write result as .png images for image inputs
     218if strcmp(lower(NomType{1}(end)),'a')
     219    NomTypeOut=NomType{1};%case of letter appendix
     220elseif isempty(j1_series)
     221    NomTypeOut='_1';
    123222else
    124     frame_index{1}=i1_series{1};
    125 end
    126 
    127 %% calibration data and timing: read the ImaDoc files
    128 %not relevant here
    129 
    130 %% check coincidence in time for several input file series
    131 %not relevant here
    132 
    133 %% coordinate transform or other user defined transform
    134 %not relevant here
    135 
    136 %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    137  % EDIT FROM HERE
    138 
    139  %% check the validity of  input file types
    140 if CheckImage{1}
    141     FileExtOut='.png'; % write result as .png images for image inputs
    142     if strcmp(lower(NomType{1}(end)),'a')
    143         NomTypeOut=NomType{1};%case of letter appendix
    144     elseif isempty(j1_series)
    145         NomTypeOut='_1';
    146     else
    147         NomTypeOut='_1_1';% caseof purely numerical indexing
    148     end
    149 else
    150     msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image'])
     223    NomTypeOut='_1_1';% caseof purely numerical indexing
     224end
     225
     226OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     227
     228if isequal(Param.InputGUI.CheckVolume,1)
     229    step=1;
     230else
     231    step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     232end
     233nbaver_ima=Param.InputGUI.SlidingSequenceLength;%number of images for the sliding background
     234nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
     235if isequal(floor(nbaver/2),nbaver)
     236    nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     237end
     238nbaver_ima=nbaver*step;
     239if nbaver_ima > nbfield
     240    display('number of images in a slice smaller than the proposed number of images for the sliding average')
    151241    return
    152242end
    153243
    154 %% Set field names and velocity types
    155 %not relevant here
    156 
    157 %% Initiate output fields
    158 %not relevant here
    159  
    160 %%% SPECIFIC PART BEGINS HERE
    161 NbSlice=Param.IndexRange.NbSlice; %number of slices
    162 %siz=size(i1_series);
    163 nbaver_init=23;%approximate number of images used for the sliding background: to be adjusted later to include an integer number of bursts
    164 j1=[];%default
    165 
    166 %% adjust the proposed number of images in the sliding average to include an integer number of bursts
    167 if nbfield_i~=1
    168     nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
    169     if isequal(floor(nbaver/2),nbaver)
    170         nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
    171     end
    172     nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts
    173 end
    174 
    175 %% input of specific parameters
    176 if checkrun %get specific parameters interactively
    177     prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
    178         'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
    179     dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' OutputDir];
    180     num_lines= 3;
    181     def     = { 'No';num2str(nbaver_init);'0.1'};
    182     answer = inputdlg(prompt,dlg_title,num_lines,def);
    183    
    184     %check input consistency
    185     if strcmp(answer{1},'No') && ~isequal(NbSlice,1)
    186         check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice) ' slices']);
    187         if ~strcmp(check,'Yes')
    188             return
    189         end
    190     end
    191     if strcmp(answer{1},'Yes')
    192         step=1;
    193     else
    194         step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
    195     end
    196     nbaver_ima=str2num(answer{2});%number of images for the sliding background
    197     nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
    198     if isequal(floor(nbaver/2),nbaver)
    199         nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
    200     end
    201     nbaver_ima=nbaver*step;
    202     if nbaver_ima > nbfield
    203         msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
    204         return
    205     end
    206     ParamOut.Specific.CheckVolume=strcmp(answer{1},'Yes');
    207     ParamOut.Specific.SlidingSequenceSize=nbaver_ima;
    208     ParamOut.Specific.BrightnessRankThreshold=str2num(answer{3});
    209    
    210     % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
    211     answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
    212     ParamOut.Specific.CheckLevelTransform=strcmp(answer,'Yes');
    213     if checkrun==1
    214          return
    215     end
    216     %%%%%%%%%%%%%%%%%%%%%%  STOP HERE FOR PAMETER INPUT MODE  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    217 else
    218     if isequal(Param.Specific.CheckVolume,1)
    219         step=1;
    220     else
    221         step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
    222     end
    223     nbaver_ima=Param.Specific.SlidingSequenceSize;%number of images for the sliding background
    224     nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
    225     if isequal(floor(nbaver/2),nbaver)
    226         nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
    227     end
    228     nbaver_ima=nbaver*step;
    229     if nbaver_ima > nbfield
    230         msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
    231         return
    232     end
    233 end
    234 
    235244% calculate absolute brightness rank
    236 rank=floor(ParamOut.Specific.BrightnessRankThreshold*nbaver_ima);
     245rank=floor(Param.InputGUI.BrightnessRankThreshold*nbaver_ima);
    237246if rank==0
    238247    rank=1;%rank selected in the sorted image series
     
    251260    end
    252261catch ME
    253     msgbox_uvmat('ERROR',ME.message)
     262    msgbox_uvmat('ERROR',['sub_background/read_image/' ME.message])
    254263    return
    255264end
     
    338347       
    339348        %write result file
    340         if ParamOut.Specific.CheckLevelTransform
     349        if Param.InputGUI.CheckLevelTransform
    341350            C=levels(Acor);
    342351            imwrite(C,newname,'BitDepth',8); % save the new image
     
    358367        for ifield = step*ceil(nbaver/2)+1:step:nbfield_i-step*floor(nbaver/2)
    359368            if checkrun
    360                 stopstate=get(hseries.RUN,'BusyAction');
    361                 update_waitbar(hseries.Waitbar,(ifield+(islice-1)*nbfield_i)/(nbfield_i*NbSlice))
     369                stopstate=get(Param.RUNHandle,'BusyAction');
     370                update_waitbar(Param.WaitbarHandle,(ifield+(islice-1)*nbfield_i)/(nbfield_i*NbSlice))
    362371            else
    363372                stopstate='queue';
     
    387396                    newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    388397                    %write result file
    389                     if ParamOut.Specific.CheckLevelTransform
     398                    if Param.InputGUI.CheckLevelTransform
    390399                        C=levels(Acor);
    391400                        imwrite(C,newname,'BitDepth',8); % save the new image
     
    422431       
    423432        %write result file
    424         if ParamOut.Specific.CheckLevelTransform
     433        if Param.InputGUI.CheckLevelTransform
    425434            C=levels(Acor);
    426435            imwrite(C,newname,'BitDepth',8); % save the new image
Note: See TracChangeset for help on using the changeset viewer.