Changeset 897 for trunk/src


Ignore:
Timestamp:
May 25, 2015, 8:48:58 PM (10 years ago)
Author:
sommeria
Message:

sub_background corrected for volume and multilevel cases

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series.m

    r896 r897  
    15561556end
    15571557
    1558 %% set nbre of cluster cores and processes
     1558%% set nbre of cluster cores and processes:
     1559% NbCore is the number of computer processors used
     1560% NbProcess is the number of independent processes in which the required calculation is split
    15591561switch RunMode
    15601562    case {'local','background'}
     
    15981600end
    15991601if isempty(Param.IndexRange.NbSlice)
    1600     NbProcess=NbCore;% choose one process per core
     1602    NbProcess=NbCore;% choose one process per core if NbSlice is not imposed
    16011603else
    1602     NbProcess=Param.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
    1603     NbCore=min(NbCore,NbProcess);% at least one process per core
     1604    NbProcess=Param.IndexRange.NbSlice;% the parameter NbSlice sets the nbre of run processes
     1605    NbCore=min(NbCore,NbProcess);% reduces the number of cores if it exceeds the number of processes
    16041606end
    16051607
     
    16621664OutputNomType=nomtype2pair(Param.InputTable{1,4});% nomenclature for output files
    16631665
    1664 %% get the set of reference field indices
    1665 first_i=1;
    1666 last_i=1;
    1667 incr_i=1;
    1668 first_j=1;
    1669 last_j=1;
    1670 incr_j=1;
     1666%% get the set of reference input field indices
     1667first_i=1;% first i index to process
     1668last_i=1;% last i index to process
     1669incr_i=1;% increment step in i index
     1670first_j=1;% first j index to process
     1671last_j=1;% last j index to process
     1672incr_j=1;% increment step in j index
    16711673if isfield(Param.IndexRange,'first_i')
    16721674    first_i=Param.IndexRange.first_i;
     
    16881690    set(handles.num_incr_i,'String','1')
    16891691end
     1692% case of no increment i defined: processing is done on the available files found in i1_series
    16901693if isempty(incr_i)
    16911694    if isempty(incr_j)
     
    17011704        ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
    17021705    end
     1706% increment i is defined: processing is done on first_i:incr_i:last_i;
    17031707else
    17041708    ref_i=first_i:incr_i:last_i;
     
    17111715    end
    17121716end
    1713 BlockLength=ceil(numel(ref_i)/NbProcess);
    1714 nbfield_j=numel(ref_j);
     1717BlockLength=ceil(numel(ref_i)/NbProcess);% nbre of input fields in each process
     1718nbfield_j=numel(ref_j); % number of j indices
    17151719
    17161720%% record nbre of output files and starting time for computation for status
     
    17291733set(handles.status,'UserData',StatusData)
    17301734
    1731 
     1735%% case of a function in Python
    17321736if strcmp(ActionExt, '.py (in dev.)')
    17331737    fprintf([
     
    17591763            %Param.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i);
    17601764        else %multislices (then incr_i is not empty)
    1761              Param.IndexRange.first_i= first_i+incr_i*(iprocess-1);
    1762              Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
     1765            Param.IndexRange.first_i= first_i+incr_i*(iprocess-1);
     1766            Param.IndexRange.incr_i=incr_i*Param.IndexRange.NbSlice;
    17631767        end
    17641768        if isfield(Param,'OutputSubDir')
    1765         t=struct2xml(Param);
    1766         t=set(t,1,'name','Series');
    1767         filexml=fullfile_uvmat(DirXml,'',Param.InputTable{1,3},'.xml',OutputNomType,...
    1768             Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
    1769         save(t,filexml);
     1769            t=struct2xml(Param);
     1770            t=set(t,1,'name','Series');
     1771            filexml=fullfile_uvmat(DirXml,'',Param.InputTable{1,3},'.xml',OutputNomType,...
     1772                Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
     1773            save(t,filexml);
    17701774        end
    17711775        switch ActionExt
     
    18951899        for iprocess=1:NbProcess
    18961900            system([batch_file_list{iprocess} ' &'])% directly execute the command file for each process
    1897             msgbox_uvmat('CONFIRMATION',[ActionName ' launched in background: press STATUS to see results'])
    1898         end
     1901        end
     1902        msgbox_uvmat('CONFIRMATION',[ActionName ' launched in background: press STATUS to see results'])
    18991903    case 'cluster_oar' % option 'oar-parexec' used
    19001904        %create subdirectory for oar command and log files
     
    20412045drawnow
    20422046
    2043 %% check whether the input file(s) need to be refreshed
    2044 % SeriesData=get(handles.series,'UserData');%hidden parameters
    2045 % if ~isfield(SeriesData,'i1_series')
    2046 %     msgbox_uvmat('ERROR','The input field series needs to be refreshed: press REFRESH');
    2047 %     return
    2048 % end
    2049 
    20502047%% get Action name and path
    20512048NbBuiltinAction=get(handles.Action,'UserData'); %nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series)
     
    21062103       set(handles.ActionName,'UserData',ActionPathList);
    21072104    set(handles.ActionExt,'Value',ActionExtIndex)
    2108 %     ActionPathList{ActionIndex,ActionExtIndex}=PathName;
    21092105       
    21102106    %record the user defined menu additions in personal file profil_perso
     
    21342130
    21352131%% create the function handle for Action
    2136 path_series=which('series');
    2137 if ~isequal(ActionPath,path_series)
    2138     eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
    2139     if ~exist(ActionPath,'dir')
    2140         errormsg=['The prescribed function path ' ActionPath ' does not exist'];
    2141         return
    2142     end
    2143     if ~isequal(spath,ActionPath)
    2144         addpath(ActionPath)% add the prescribed path if not the current one
    2145     end
    2146 end
    2147 eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
    2148 if ~isequal(ActionPath,path_series)
    2149         rmpath(ActionPath)% add the prescribed path if not the current one   
    2150 end
     2132if ~exist(ActionPath,'dir')
     2133    msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']);
     2134    return
     2135end
     2136current_dir=pwd;%current working dir
     2137cd(ActionPath)
     2138h_fun=str2func(ActionName);
     2139cd(current_dir)
     2140
     2141%
     2142% checkaddpath=0;
     2143% path_series=which('series');
     2144% %eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
     2145% spath=fileparts(which(ActionName)); %spath = current path of the selected function ACTION
     2146% if ~exist(ActionPath,'dir')
     2147%     msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']);
     2148%     return
     2149% end
     2150% if ~strcmp(spath,ActionPath)
     2151%     if strcmp(pwd,spath)
     2152%         msgbox_uvmat('ERROR',[ 'a function called ' ActionName ' on your working space oversets the selected one']);
     2153%         return
     2154%     else
     2155%         addpath(ActionPath)% add the prescribed path if not the current one
     2156%         checkaddpath=1;
     2157%     end
     2158% end
     2159% eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
     2160% if checkaddpath && ~isequal(ActionPath,path_series)
     2161%     rmpath(ActionPath)% add the prescribed path if not the current one
     2162% end
    21512163
    21522164%% Activate the Action fct to adapt the configuration of the GUI series and bring specific parameters in SeriesData
     
    21852197FieldList_1=get(handles.FieldName_1,'String');% previous list as default
    21862198if ~iscell(FieldList_1),FieldList_1={FieldList_1};end
    2187 CheckList=0;% indicate whether FieldName has been updated
     2199%CheckList=0;% indicate whether FieldName has been updated
    21882200CheckList_1=1;% indicate whether FieldName_1 has been updated
    21892201handles_coord=[handles.Coord_x handles.Coord_y handles.Coord_z handles.Coord_x_title handles.Coord_y_title handles.Coord_z_title];
     
    21952207    set(handles.VelType_title,'Visible','on')
    21962208    FieldList=[set_field_list('U','V');{'C'};{'get_field...'}];%standard menu for civx data
    2197     CheckList=1;
     2209    %CheckList=1;
    21982210    set(handles.FieldName,'Value',1); %velocity vector choice by default
    21992211    if  VelTypeRequest_1 && numel(iview_civ)>=2
     
    23472359
    23482360%% NbSlice visibility
    2349 NbSliceVisible='off';%default
    2350 if isfield(ParamOut,'NbSlice') && isequal(ParamOut.NbSlice,'on')
    2351     NbSliceVisible='on';
    2352     set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices
     2361%NbSliceVisible='off';%default
     2362if isfield(ParamOut,'NbSlice') && (strcmp(ParamOut.NbSlice,'on')||isnumeric(ParamOut.NbSlice))
     2363    set(handles.num_NbSlice,'Visible','on')
     2364    set(handles.NbSlice_title,'Visible','on')
    23532365else
    2354     set(handles.num_NbProcess,'String','')% free nbre of processes
    2355 end
    2356 set(handles.num_NbSlice,'Visible',NbSliceVisible)
    2357 set(handles.NbSlice_title,'Visible',NbSliceVisible)
     2366    set(handles.num_NbSlice,'Visible','off')
     2367    set(handles.NbSlice_title,'Visible','off')
     2368    %     set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices
     2369    % else
     2370    %     set(handles.num_NbProcess,'String','')% free nbre of processes
     2371end
     2372if isnumeric(ParamOut.NbSlice)
     2373    set(handles.num_NbSlice,'String',num2str(ParamOut.NbSlice))
     2374    set(handles.num_NbSlice,'Enable','off'); % NbSlice set by the activation of the Action function
     2375else
     2376    set(handles.num_NbSlice,'Enable','on'); % NbSlice can be modified on the GUI series
     2377end
     2378% set(handles.num_NbSlice,'Visible',NbSliceVisible)
     2379% set(handles.NbSlice_title,'Visible',NbSliceVisible)
    23582380
    23592381
     
    30033025%% create the function handle of the selected fct
    30043026if ~isempty(TransformName)
     3027    if ~exist(TransformPathList{TransformIndex},'dir')
     3028        msgbox_uvmat('ERROR',['The prescribed transform function path ' TransformPathList{TransformIndex} ' does not exist']);
     3029        return
     3030    end
    30053031    current_dir=pwd;%current working dir
    30063032    cd(TransformPathList{TransformIndex})
     
    32943320end
    32953321
    3296 function num_NbProcess_Callback(hObject, eventdata, handles)
     3322%function num_NbProcess_Callback(hObject, eventdata, handles)
    32973323
    32983324
    32993325function num_NbSlice_Callback(hObject, eventdata, handles)
    33003326NbSlice=str2num(get(handles.num_NbSlice,'String'));
    3301 set(handles.num_NbProcess,'String',num2str(NbSlice))
     3327%set(handles.num_NbProcess,'String',num2str(NbSlice))
    33023328
    33033329%------------------------------------------------------------------------
  • trunk/src/series/civ_input.m

    r885 r897  
    17931793     end
    17941794     Param.ActionInput.Civ1.CorrSmooth=0;% launch Civ1 with no data point (to get the image names for A and B)
     1795     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
     1796     Param.IndexRange.last_i=str2num(get(handles.ref_i,'String'));
     1797     if strcmp(get(handles.ref_j,'Visible'),'on')
     1798         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
     1799         Param.IndexRange.last_j=Param.IndexRange.first_j;
     1800     else
     1801         Param.IndexRange.first_j=1;
     1802         Param.IndexRange.last_j=1;
     1803     end
    17951804     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
    17961805     if ~isempty(errormsg), return, end % rmq: error msg displayed in civ_series
  • trunk/src/series/civ_series.m

    r896 r897  
    355355    % if Civ1 computation is requested
    356356    if isfield (Param.ActionInput,'Civ1')
     357        if CheckInputFile
    357358        disp('civ1 started')
     359        end
    358360        par_civ1=Param.ActionInput.Civ1;
    359361        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
  • trunk/src/series/sub_background.m

    r854 r897  
    7575    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
    7676    ParamOut.WholeIndexRange='on';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    77     ParamOut.NbSlice='on'; %nbre of slices ('off' by default)
     77    ParamOut.NbSlice='on'; % edit box nbre of slices made active
    7878    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
    7979    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     
    117117   
    118118    %% numbers of fields
    119     NbSlice=1;%default
     119    NbSlice_i=1;%default
    120120    if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    121         NbSlice=Param.IndexRange.NbSlice;
     121        NbSlice_i=Param.IndexRange.NbSlice;
    122122    end
    123123    incr_j=1;%default
     
    130130        nbfield_j=numel(first_j:incr_j:last_j);%nb of fields for the j index (bursts or volume slices)
    131131    end
    132     incr_i=1;%default
    133     first_i=1;last_i=1;incr_i;%default
     132    first_i=1;last_i=1;incr_i=1;%default
    134133    if isfield(Param.IndexRange,'first_i'); last_i=Param.IndexRange.first_i; end   
    135134    if isfield(Param.IndexRange,'last_i'); last_i=Param.IndexRange.last_i; end
     
    139138    nbfield_i=numel(first_i:incr_i:last_i);%nb of fields for the i index (bursts or volume slices)
    140139    nbfield=nbfield_j*nbfield_i; %total number of fields
    141     nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     140    nbfield_i=floor(nbfield/NbSlice_i);%total number of  indexes in a slice (adjusted to an integer number of slices)
    142141   
    143142    %% setting of  parameters specific to sub_background
     
    159158   
    160159    %check input consistency
    161     if strcmp(answer{1},'No') && ~isequal(NbSlice,1)
    162         check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice) ' slices']);
     160    if strcmp(answer{1},'No') && ~isequal(NbSlice_i,1)
     161        check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice_i) ' slices']);
    163162        if ~strcmp(check,'Yes')
    164163            return
     
    166165    end
    167166    if strcmp(answer{1},'Yes')
    168         step=1;
     167        step=2;%the sliding background is shifted by the length of one burst, assumed =2 for volume ;ode
     168        ParamOut.NbSlice=1; %nbre of slices displayed
    169169    else
    170170        step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     
    198198
    199199%% input preparation
    200 NbSlice=Param.IndexRange.NbSlice;
    201 if ~isequal(NbSlice,1)
    202     display(['multi-level splitting into ' num2str(NbSlice) ' slices']);
     200NbSlice_i=Param.IndexRange.NbSlice;
     201if ~isequal(NbSlice_i,1)
     202    display(['multi-level splitting into ' num2str(NbSlice_i) ' slices']);
    203203end
    204204RootPath=Param.InputTable(:,1);
     
    207207NomType=Param.InputTable(:,4);
    208208FileExt=Param.InputTable(:,5);
    209 hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
    210 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    211 if ~isempty(hdisp),delete(hdisp),end;
     209%hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
     210[filecell,i1_series,i2_series,j1_series]=get_file_series(Param);
     211% if ~isempty(hdisp),delete(hdisp),end;
    212212%%%%%%%%%%%%
    213213    % The cell array filecell is the list of input file names, while
     
    225225        frame_index{1}=i1_series{1};
    226226    end
    227 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    228 nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    229 nbfield=nbfield_j*nbfield_i; %total number of fields
    230 nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    231 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    232 
    233 %% output
     227
     228
     229%% output file naming
    234230FileExtOut='.png'; % write result as .png images for image inputs
    235231if strcmp(lower(NomType{1}(end)),'a')
     
    240236    NomTypeOut='_1_1';% caseof purely numerical indexing
    241237end
    242 
    243238OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    244239
    245 if isequal(Param.ActionInput.CheckVolume,1)
    246     step=1;
    247 else
     240%% file index parameters
     241% NbSlice_i: nbre of slices for i index: different of of 1 for multi-level,
     242% the function sub_background is then relaunched by the GUI series for each
     243%      slice, incrementing the first index i by 1
     244% NbSlice_j: nbre of slices in volume mode
     245% nbfield : total number of images treated per slice
     246% step: shift of image index at each step of the sliding background (corresponding to the nbre of images in a burst)
     247% nbaver_ima: nbre of the images in the sliding sequence used for the background
     248% nbaver=nbaver_ima/step: nbre of bursts corresponding to nbaver_ima images. It has been adjusted so that nbaver is an odd integer
     249nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     250nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     251nbfield=nbfield_j*nbfield_i; %total number of fields
     252if Param.ActionInput.CheckVolume
     253    step=2;% we assume the burst contains only one image pair
     254    NbSlice_j=nbfield_j;
     255    NbSlice=nbfield_j;
     256    nbfield_series=nbfield_i;
     257else
    248258    step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     259        NbSlice_j=1;
     260        NbSlice=NbSlice_i;
     261    nbfield_i=floor(nbfield/NbSlice_i);%total number of  indexes in a slice (adjusted to an integer number of slices)
     262    nbfield=nbfield_i*NbSlice_i; %total number of fields after adjustement
     263    nbfield_series=nbfield;
    249264end
    250265nbaver_ima=Param.ActionInput.SlidingSequenceLength;%number of images for the sliding background
     
    258273    return
    259274end
    260 
    261 % calculate absolute brightness rank
     275halfnbaver=floor(nbaver/2); % half width (in unit of bursts) of the sliding background
     276
     277%% calculate absolute brightness rank
    262278rank=floor(Param.ActionInput.BrightnessRankThreshold*nbaver_ima);
    263279if rank==0
     
    281297end
    282298
    283 %% summary of the parameters:
    284 % nbfield : total number of images treated (in case of multislices the function sub_background is repeated for each slice)
    285 % step: shift at each step of the sliding background (corresponding to the nbre of images in a burst)
    286 % nbaver_ima: length of the sequence used for the sliding background
    287 
    288 % nbaver=nbaver_ima/step: nbaver_ima has been adjusted so that nbaver is an odd integer
    289 halfnbaver=floor(nbaver/2); % half width (in unit of bursts) of the sliding background
    290 
    291 %% select the series of image indices to process
    292 indselect=1:step:nbfield;% select file indices of the slice
    293 for ifield=1:step-1
    294     indselect=[indselect;indselect(end,:)+1];
    295 end
    296 
    297 %% read the first series of nbaver_ima images and sort by luminosity at each pixel
    298 for ifield = 1:nbaver_ima
    299     ifile=indselect(ifield);
    300     filename=filecell{1,ifile};
    301     Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
    302     if ndims(Aread)==3;%color images
    303         Aread=sum(double(Aread),3);% take the sum of color components
    304     end
    305     Ak(:,:,ifield)=Aread;
    306 end
    307 Asort=sort(Ak,3);%sort the luminosity of images at each point
    308 B=Asort(:,:,rank);%background image
    309 
    310 %% substract the first background image to the first images
    311 display( 'first background image will be substracted')
    312 for ifield=1:step*(halfnbaver+1);% nbre of images treated by the first background image
    313     Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
    314     Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    315     ifile=indselect(ifield);
    316     j1=1;
    317     if ~isempty(j1_series{1})
    318         j1=j1_series{1}(ifile);
    319     end
    320     newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    321    
    322     %write result file
    323     if Param.ActionInput.CheckLevelTransform
    324         C=levels(Acor);
    325         imwrite(C,newname,'BitDepth',8); % save the new image
    326     else
    327         if isequal(FileInfo{1}.BitDepth,16)
    328             C=uint16(Acor);
    329             imwrite(C,newname,'BitDepth',16); % save the new image
     299
     300%%%%%%%  LOOP ON SLICES FOR VOLUME SCAN %%%%%%%
     301for j_slice=1:NbSlice_j
     302    %% select the series of i indices to process
     303    indselect=j_slice:step*NbSlice_j:nbfield;% select file indices of the slice
     304    for ifield=1:step-1
     305        indselect=[indselect;indselect(end,:)+NbSlice_j];
     306    end
     307   
     308    %% read the first series of nbaver_ima images and sort by luminosity at each pixel
     309    for ifield = 1:nbaver_ima
     310        ifile=indselect(ifield);
     311        filename=filecell{1,ifile};
     312        Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
     313        if ndims(Aread)==3;%color images
     314            Aread=sum(double(Aread),3);% take the sum of color components
     315        end
     316        Ak(:,:,ifield)=Aread;
     317    end
     318    Asort=sort(Ak,3);%sort the luminosity of images at each point
     319    B=Asort(:,:,rank);%background image
     320   
     321    %% substract the first background image to the first images
     322    display( 'first background image will be substracted')
     323    for ifield=1:step*(halfnbaver+1);% nbre of images treated by the first background image
     324        Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
     325        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
     326        ifile=indselect(ifield);
     327        j1=1;
     328        if ~isempty(j1_series{1})
     329            j1=j1_series{1}(ifile);
     330        end
     331        newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     332       
     333        %write result file
     334        if Param.ActionInput.CheckLevelTransform
     335            C=levels(Acor);
     336            imwrite(C,newname,'BitDepth',8); % save the new image
    330337        else
    331             C=uint8(Acor);
     338            if isequal(FileInfo{1}.BitDepth,16)
     339                C=uint16(Acor);
     340                imwrite(C,newname,'BitDepth',16); % save the new image
     341            else
     342                C=uint8(Acor);
     343                imwrite(C,newname,'BitDepth',8); % save the new image
     344            end
     345        end
     346        display([newname ' written'])
     347    end
     348   
     349    %% repeat the operation on a sliding series of images
     350    display('sliding background image will be substracted')
     351    if nbfield_series > nbaver_ima
     352        for ifield = step*(halfnbaver+1):step:nbfield_series-step*(halfnbaver+1)% ifield +iburst=index of the current processed image
     353            update_waitbar(WaitbarHandle,ifield/nbfield_series)
     354            if  ~strcmp(get(RUNHandle,'BusyAction'),'queue')
     355                disp('program stopped by user')
     356                return
     357            end
     358            if nbaver_ima>step
     359            Ak(:,:,1:nbaver_ima-step)=Ak(:,:,1+step:nbaver_ima);% shift the current image series by one burst (step)
     360            end
     361            %incorporate next burst in the current image series
     362            for iburst=1:step
     363                ifile=indselect(ifield+iburst+step*halfnbaver);
     364                j1=1;
     365                if ~isempty(j1_series{1})
     366                    j1=j1_series{1}(ifile);
     367                end
     368                filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
     369                Aread=read_image(filename,FileType{1},MovieObject{1},i1_series{1}(ifile));
     370                if ndims(Aread)==3;%color images
     371                    Aread=sum(double(Aread),3);% take the sum of color components
     372                end
     373                Ak(:,:,nbaver_ima-step+iburst)=Aread;% fill the last burst of the current image series by the new image
     374            end
     375            Asort=sort(Ak,3);%sort the new current image series by luminosity
     376            B=Asort(:,:,rank);%current background image
     377            %substract the background for the current burst
     378            for iburst=1:step
     379                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
     380                Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
     381                ifile=indselect(ifield+iburst);
     382                if ~isempty(j1_series{1})
     383                    j1=j1_series{1}(ifile);
     384                end
     385                newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     386                %write result file
     387                if Param.ActionInput.CheckLevelTransform
     388                    C=levels(Acor);
     389                    imwrite(C,newname,'BitDepth',8); % save the new image
     390                else
     391                    if isequal(FileInfo{1}.BitDepth,16)
     392                        C=uint16(Acor);
     393                        imwrite(C,newname,'BitDepth',16); % save the new image
     394                    else
     395                        C=uint8(Acor);
     396                        imwrite(C,newname,'BitDepth',8); % save the new image
     397                    end
     398                end
     399                display([newname ' written'])
     400            end
     401        end
     402    end
     403   
     404    %% substract the background from the last images
     405    display('last background image will be substracted')
     406    for  ifield=nbfield_series-step*halfnbaver+1:nbfield_series
     407        Acor=double(Ak(:,:,ifield-nbfield_series+step*(2*halfnbaver+1)))-double(B);
     408        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
     409        ifile=indselect(ifield);
     410        if ~isempty(j1_series{1})
     411            j1=j1_series{1}(ifile);
     412        end
     413        newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     414        %write result file
     415        if Param.ActionInput.CheckLevelTransform
     416            C=levels(Acor);
    332417            imwrite(C,newname,'BitDepth',8); % save the new image
    333         end
    334     end
    335     display([newname ' written'])
    336 end
    337 
    338 %% repeat the operation on a sliding series of images
    339 display('sliding background image will be substracted')
    340 if nbfield_i > nbaver_ima
    341     for ifield = step*(halfnbaver+1):step:nbfield_i-step*(halfnbaver+1)% ifield +iburst=index of the current processed image
    342         update_waitbar(WaitbarHandle,ifield/nbfield_i)
    343         if ~isempty(RUNHandle) &&ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
    344             disp('program stopped by user')
    345             return
    346         end
    347         Ak(:,:,1:nbaver_ima-step)=Ak(:,:,1+step:nbaver_ima);% shift the current image series by one burst (step)
    348         %incorporate next burst in the current image series
    349         for iburst=1:step
    350             ifile=indselect(ifield+iburst+step*halfnbaver);
    351             j1=1;
    352     if ~isempty(j1_series{1})
    353         j1=j1_series{1}(ifile);
    354     end
    355             filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
    356             Aread=read_image(filename,FileType{1},MovieObject{1},i1_series{1}(ifile));
    357             if ndims(Aread)==3;%color images
    358                 Aread=sum(double(Aread),3);% take the sum of color components
    359             end
    360             Ak(:,:,nbaver_ima-step+iburst)=Aread;% fill the last burst of the current image series by the new image
    361         end
    362         Asort=sort(Ak,3);%sort the new current image series by luminosity
    363         B=Asort(:,:,rank);%current background image
    364         %substract the background for the current burst
    365         for iburst=1:step
    366             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
    367             Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    368             ifile=indselect(ifield+iburst);
    369             if ~isempty(j1_series{1})
    370                 j1=j1_series{1}(ifile);
    371             end
    372             newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    373             %write result file
    374             if Param.ActionInput.CheckLevelTransform
    375                 C=levels(Acor);
     418        else
     419            if isequal(FileInfo{1}.BitDepth,16)
     420                C=uint16(Acor);
     421                imwrite(C,newname,'BitDepth',16); % save the new image
     422            else
     423                C=uint8(Acor);
    376424                imwrite(C,newname,'BitDepth',8); % save the new image
    377             else
    378                 if isequal(FileInfo{1}.BitDepth,16)
    379                     C=uint16(Acor);
    380                     imwrite(C,newname,'BitDepth',16); % save the new image
    381                 else
    382                     C=uint8(Acor);
    383                     imwrite(C,newname,'BitDepth',8); % save the new image
    384                 end
    385             end
    386             display([newname ' written'])       
    387         end
    388     end
    389 end
    390 
    391 %% substract the background from the last images
    392 display('last background image will be substracted')
    393 for  ifield=nbfield_i-step*halfnbaver+1:nbfield_i
    394     Acor=double(Ak(:,:,ifield-nbfield_i+step*(2*halfnbaver+1)))-double(B);
    395     Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    396     ifile=indselect(ifield);
    397     if ~isempty(j1_series{1})
    398         j1=j1_series{1}(ifile);
    399     end
    400     newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1); 
    401     %write result file
    402     if Param.ActionInput.CheckLevelTransform
    403         C=levels(Acor);
    404         imwrite(C,newname,'BitDepth',8); % save the new image
    405     else
    406         if isequal(FileInfo{1}.BitDepth,16)
    407             C=uint16(Acor);
    408             imwrite(C,newname,'BitDepth',16); % save the new image
    409         else
    410             C=uint8(Acor);
    411             imwrite(C,newname,'BitDepth',8); % save the new image
    412         end
    413     end
    414     display([newname ' written'])
    415 end
    416 
     425            end
     426        end
     427        display([newname ' written'])
     428    end
     429end
    417430
    418431
  • trunk/src/transform_field/ima_remove_background.m

    r810 r897  
    5454B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
    5555ImPart=(A-B);
    56 DataOut.A=ImPart.*(ImPart>threshold);
     56DataOut.A=ImPart;
     57%DataOut.A=ImPart.*(ImPart>threshold);
    5758DataOut.A=feval(Atype,DataOut.A);
  • trunk/src/transform_field/ima_remove_particles.m

    r810 r897  
    3232if strcmp(DataIn,'*')
    3333    return
     34   
    3435end
    3536
    3637%parameters
    3738threshold=200;
    38 nblock_x=30;%size of image subblocks for analysis
    39 nblock_y=30;
     39nblock_x=10;%size of image subblocks for analysis
     40nblock_y=10;
    4041%---------------------------------------------------------
    4142DataOut=DataIn;%default
     
    4950Atype=class(DataIn.A);
    5051A=double(DataIn.A);
    51 Backg=zeros(size(A));
     52% Backg=zeros(size(A));
    5253Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
    5354Amin=A.*Aflagmin;%values of A at local minima
     
    5859Backg=Backg./Bmin; % find the average of minima in blocks
    5960B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
    60 ImPart=(A-B);
    61 ImPart=ImPart.*(ImPart>threshold);
    62 DataOut.A=A-ImPart;%
     61DataOut.A=B;
     62% ImPart=(A-B);
     63% ImPart=ImPart.*(ImPart>threshold);
     64% DataOut.A=A-ImPart;%
    6365DataOut.A=feval(Atype,DataOut.A);
    6466
Note: See TracChangeset for help on using the changeset viewer.