Changeset 1124 for trunk/src/series


Ignore:
Timestamp:
Sep 28, 2023, 6:22:45 PM (10 months ago)
Author:
sommeria
Message:

series/sub_background corrected for long series of j index

Location:
trunk/src/series
Files:
2 edited

Legend:

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

    r1107 r1124  
    142142    CheckVolume='No';
    143143    nbaver_init=23; %default number of images used for the sliding background: to be adjusted later to include an integer number of bursts
    144      if nbfield_i~=1
     144    SaturationValue=0;
     145     if nbfield_i~=1 && nbfield_j<=nbaver_init
    145146        nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
    146147        if isequal(mod(nbaver,2),0)% if nbaver is even
     
    150151    end
    151152    BrightnessRankThreshold=0.1;
    152     CheckSubmedian='No';
    153     SaturationCoeff=0;
     153   % CheckSubmedian='No';
     154%     SaturationCoeff=0;
    154155    if isfield(Param,'ActionInput')
    155156        if isfield(Param.ActionInput,'CheckVolume') && Param.ActionInput.CheckVolume
     
    162163          BrightnessRankThreshold=Param.ActionInput.BrightnessRankThreshold;
    163164        end
    164         if isfield(Param.ActionInput,'CheckSubmedian') && Param.ActionInput.CheckSubmedian
    165         CheckSubmedian='Yes';
    166         end
    167         if isfield(Param.ActionInput,'SaturationCoeff')
    168             SaturationCoeff=Param.ActionInput.SaturationCoeff;
     165%         if isfield(Param.ActionInput,'CheckSubmedian') && Param.ActionInput.CheckSubmedian
     166%         CheckSubmedian='Yes';
     167%         end
     168        if isfield(Param.ActionInput,'SaturationValue')
     169            SaturationValue=Param.ActionInput.SaturationValue;
    169170        end
    170171    end   
     
    172173        'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
    173174        'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles';...
    174         'set to 0 image levels below median(Yes/No)';...
    175         'image rescaling coefficient(=2 to reduce the influence of bright particles), =0 for no rescaling' };
     175        'image saturation level for rescaling( reduce the influence of particles brighter than this value), =0 for no rescaling' };
    176176    dlg_title = 'get (slice by slice) a sliding background and substract to each image';
    177     num_lines= 5;
    178     def     = { CheckVolume;num2str(nbaver_init);num2str(BrightnessRankThreshold);CheckSubmedian;num2str(SaturationCoeff)};
     177    num_lines= 4;
     178    def     = { CheckVolume;num2str(nbaver_init);num2str(BrightnessRankThreshold);num2str(SaturationValue)};
    179179    answer = inputdlg(prompt,dlg_title,num_lines,def);
    180180    if isempty(answer)
     
    189189    end
    190190    if strcmp(answer{1},'Yes')
    191         step=2;%the sliding background is shifted by the length of one burst, assumed =2 for volume ;ode
     191        step=2;%the sliding background is shifted by the length of one burst, assumed =2 for volume
    192192        ParamOut.NbSlice=1; %nbre of slices displayed
    193193    else
    194194        step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
    195195    end
    196     nbaver_ima=str2double(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(mod(nbaver,2),0)% if nbaver is even
    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;% correct the nbre of images corresponding to nbaver
     196    ParamOut.ActionInput.SlidingSequenceLength=adjust_slidinglength(str2num(answer{2}),step);
    202197    ParamOut.ActionInput.CheckVolume=strcmp(answer{1},'Yes');
    203     ParamOut.ActionInput.SlidingSequenceLength=nbaver_ima;
    204198    ParamOut.ActionInput.BrightnessRankThreshold=str2double(answer{3});
    205     ParamOut.ActionInput.CheckSubmedian=strcmp(answer{4},'Yes');
    206     ParamOut.ActionInput.SaturationCoeff=str2double(answer{5});
     199%     ParamOut.ActionInput.CheckSubmedian=strcmp(answer{4},'Yes');
     200    ParamOut.ActionInput.SaturationValue=str2double(answer{4});
    207201    % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
    208202%     answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
     
    259253if strcmp(FileInfo{1}.FileType,'image')
    260254    NomTypeOut=NomType{1};
    261 % if strcmp(lower(NomType{1}(end)),'a')
    262 %     NomTypeOut=NomType{1};%case of letter appendix
    263255elseif isempty(j1_series{1})
    264256    NomTypeOut='_1';
     
    267259end
    268260OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     261OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
    269262
    270263%% file index parameters
    271 % NbSlice_i: nbre of slices for i index: different of of 1 for multi-level,
     264% NbSlice_i: nbre of slices for i index in multi-level mode: equal to 1 for a single level
    272265% the function sub_background is then relaunched by the GUI series for each
    273266%      slice, incrementing the first index i by 1
     
    280273nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    281274
    282 if Param.ActionInput.CheckVolume
     275if Param.ActionInput.CheckVolume% case of volume scan: the background images must be determined for each index j
    283276    step=2;% we assume the burst contains only one image pair
    284277    NbSlice_j=nbfield_j;
    285     NbSlice=nbfield_j;
    286278    nbfield_series=nbfield_i;
    287279else
    288280    step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
    289         NbSlice_j=1;
    290         NbSlice=NbSlice_i;
     281    NbSlice_j=1;
    291282    %nbfield_i=floor(nbfield_i/NbSlice_i);%total number of  indexes in a slice (adjusted to an integer number of slices)
    292283    %nbfield=nbfield_i*NbSlice_i; %total number of fields after adjustement
     
    294285end
    295286nbfield=nbfield_j*nbfield_i; %total number of fields
    296 nbaver_ima=Param.ActionInput.SlidingSequenceLength;%number of images for the sliding background
    297 nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
    298 if isequal(mod(nbaver,2),0)
    299     nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
    300 end
    301 nbaver_ima=nbaver*step;
     287[nbaver_ima,nbaver,step]=adjust_slidinglength(Param.ActionInput.SlidingSequenceLength,step);
    302288if nbaver_ima > nbfield
    303289    display('number of images in a slice smaller than the proposed number of images for the sliding average')
     
    342328        filename=filecell{1,ifile};
    343329        Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
    344         if ndims(Aread)==3;%color images
     330        if ndims(Aread)==3%color images
    345331            Aread=sum(double(Aread),3);% take the sum of color components
    346332        end
     
    352338    %% substract the first background image to the first images
    353339    display( 'first background image will be substracted')
    354     for ifield=1:step*(halfnbaver+1);% nbre of images treated by the first background image
     340    for ifield=1:step*(halfnbaver+1)% nbre of images treated by the first background image
    355341        Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
    356342        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
     
    360346            j1=j1_series{1}(ifile);
    361347        end
    362         newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     348        newname=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    363349       
    364350        %write result file
    365         if ~isequal(Param.ActionInput.SaturationCoeff,0)
    366             C=levels(Acor,Param.ActionInput.CheckSubmedian,Param.ActionInput.SaturationCoeff);
     351        if ~isequal(Param.ActionInput.SaturationValue,0)
     352            C=levels(Acor,Param.ActionInput.SaturationValue);
    367353            imwrite(C,newname,'BitDepth',16); % save the new image
    368354        else
     
    400386                    j1=j1_series{1}(ifile);
    401387                end
     388               
    402389                filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
    403390                Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
    404                 if ndims(Aread)==3;%color images
     391                if ndims(Aread)==3%case of color images
    405392                    Aread=sum(double(Aread),3);% take the sum of color components
    406393                end
     
    417404                    j1=j1_series{1}(ifile);
    418405                end
    419                 newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     406                newname=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    420407                %write result file
    421                 if ~isequal(Param.ActionInput.SaturationCoeff,0)
    422                     C=levels(Acor,Param.ActionInput.CheckSubmedian,Param.ActionInput.SaturationCoeff);
     408                if ~isequal(Param.ActionInput.SaturationValue,0)
     409                    C=levels(Acor,Param.ActionInput.SaturationValue);
    423410                    imwrite(C,newname,'BitDepth',16); % save the new image
    424411                else
     
    445432            j1=j1_series{1}(ifile);
    446433        end
    447         newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     434        newname=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    448435        %write result file
    449         if ~isequal(Param.ActionInput.SaturationCoeff,0)
    450             C=levels(Acor,Param.ActionInput.CheckSubmedian,Param.ActionInput.SaturationCoeff);
     436        if ~isequal(Param.ActionInput.SaturationValue,0)
     437            C=levels(Acor,Param.ActionInput.SaturationValue);
    451438            imwrite(C,newname,'BitDepth',16); % save the new image
    452439        else
     
    463450end
    464451
    465 function C=levels(A,CheckSubmedian,Coeff)
    466 
    467 nblock_y=100;%2*Param.TransformInput.BlockSize;
    468 nblock_x=100;%2*Param.TransformInput.BlockSize;
    469 [npy,npx]=size(A);
    470 [X,Y]=meshgrid(1:npx,1:npy);
    471 
    472 %Backg=zeros(size(A));
    473 %Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
    474 %Amin=A.*Aflagmin;%values of A at local minima
    475 % local background: find all the local minima in image subblocks
    476 if CheckSubmedian
    477     fctblock= inline('median(x(:))');
    478     Backg=blkproc(A,[nblock_y nblock_x],fctblock);% take the median in  blocks
    479     %B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
    480     A=A-imresize(Backg,size(A),'bilinear');% substract background interpolated to the initial size image
    481 end
    482 fctblock= inline('mean(x(:))');
    483 AMean=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
    484 fctblock= inline('var(x(:))');
    485 AVar=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
    486 Avalue=AVar./AMean;% typical value of particle luminosity
    487 Avalue=imresize(Avalue,size(A),'bilinear');% interpolate to the initial size image
    488 C=uint16(1000*tanh(A./(Coeff*Avalue)));
     452function C=levels(A,Coeff)
     453
     454% nblock_y=100;%2*Param.TransformInput.BlockSize;
     455% nblock_x=100;%2*Param.TransformInput.BlockSize;
     456% [npy,npx]=size(A);
     457% [X,Y]=meshgrid(1:npx,1:npy);
     458%
     459% %Backg=zeros(size(A));
     460% %Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
     461% %Amin=A.*Aflagmin;%values of A at local minima
     462% % local background: find all the local minima in image subblocks
     463% if CheckSubmedian
     464%     fctblock= inline('median(x(:))');
     465%     Backg=blkproc(A,[nblock_y nblock_x],fctblock);% take the median in  blocks
     466%     %B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
     467%     A=A-imresize(Backg,size(A),'bilinear');% substract background interpolated to the initial size image
     468% end
     469% fctblock= inline('mean(x(:))');
     470% AMean=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
     471% fctblock= inline('var(x(:))');
     472% AVar=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
     473% Avalue=AVar./AMean;% typical value of particle luminosity
     474% Avalue=imresize(Avalue,size(A),'bilinear');% interpolate to the initial size image
     475%C=uint16(1000*tanh(A./(Coeff*Avalue)));
     476C=uint16(Coeff*tanh(A./Coeff));
     477%------------------------------------------
     478% adjust the number of images used for the sliding average
     479function [nbaver_ima,nbaver,step_out]=adjust_slidinglength(nb_aver_in,step)
     480%nbaver_ima=str2double(nb_aver_in);%number of images for the sliding background
     481nbaver=ceil(nb_aver_in/step);%number of bursts for the sliding background
     482if isequal(mod(nbaver,2),0)% if nbaver is even
     483    nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     484end
     485step_out=step;
     486if nbaver>1
     487    nbaver_ima=nbaver*step;% correct the nbre of images corresponding to nbaver
     488else
     489    nbaver_ima=nb_aver_in;
     490    if isequal(mod(nbaver_ima,2),0)% if nbaver_ima is even
     491        nbaver_ima=nbaver_ima+1;%set the number of bursts to an odd number (so the middle burst is defined)
     492    end
     493    step_out=1;
     494end
  • trunk/src/series/sub_background_special.m

    r1107 r1124  
    106106Bfilter=ones(1,20)/20;
    107107%% root input file names and nomenclature type (cell arrays with one element)
    108 OutputDir=[Param.OutputSubDir Param.OutputDirExt];4
     108OutputDir=[Param.OutputSubDir Param.OutputDirExt];
    109109nbj=numel(Param.IndexRange.first_i:Param.IndexRange.last_i);
    110110for i_ind=Param.IndexRange.first_i:Param.IndexRange.last_i
Note: See TracChangeset for help on using the changeset viewer.