Changeset 897 for trunk/src/series


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/series
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.