Ignore:
Timestamp:
Jun 12, 2016, 5:09:47 PM (5 years ago)
Author:
sommeria
Message:

bugs repaired

File:
1 edited

Legend:

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

    r950 r951  
    150150    end
    151151   
    152     prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
    153         'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
     152    prompt = {'volume scan mode (Yes/No)';...
     153        'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
     154        'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles';...
     155        'set to 0 image levels below median(Yes/No)';...
     156        'image rescaling coefficient(high values reduce the influence of bright particles), =0 for no rescaling' };
    154157    dlg_title = 'get (slice by slice) a sliding background and substract to each image';
    155     num_lines= 3;
    156     def     = { 'No';num2str(nbaver_init);'0.1'};
     158    num_lines= 5;
     159    def     = { 'No';num2str(nbaver_init);'0.1';'No';'2'};
    157160    answer = inputdlg(prompt,dlg_title,num_lines,def);
    158161    if isempty(answer)
     
    181184    ParamOut.ActionInput.SlidingSequenceLength=nbaver_ima;
    182185    ParamOut.ActionInput.BrightnessRankThreshold=str2double(answer{3});
    183    
     186    ParamOut.ActionInput.CheckSubmedian=strcmp(answer{4},'Yes');
     187    ParamOut.ActionInput.SaturationCoeff=str2double(answer{5});
    184188    % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
    185     answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
    186     ParamOut.ActionInput.CheckLevelTransform=strcmp(answer,'Yes');
     189%     answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
     190%     ParamOut.ActionInput.CheckLevelTransform=strcmp(answer,'Yes');
    187191    return
    188192end
     
    233237
    234238%% output file naming
    235 FileExtOut='.png'; % write result as .png images for image inputs
    236 if strcmp(lower(NomType{1}(end)),'a')
    237     NomTypeOut=NomType{1};%case of letter appendix
     239FileExtOut='.png'; % write result as .png images for image inputsFileInfo.FileType='image'
     240if strcmp(FileInfo{1}.FileType,'image')
     241    NomTypeOut=NomType{1};
     242% if strcmp(lower(NomType{1}(end)),'a')
     243%     NomTypeOut=NomType{1};%case of letter appendix
    238244elseif isempty(j1_series{1})
    239245    NomTypeOut='_1';
     
    338344       
    339345        %write result file
    340         if Param.ActionInput.CheckLevelTransform
    341             C=levels(Acor);
     346        if ~isequal(Param.ActionInput.SaturationCoeff,0)
     347            C=levels(Acor,Param.ActionInput.CheckSubmedian,Param.ActionInput.SaturationCoeff);
    342348            imwrite(C,newname,'BitDepth',16); % save the new image
    343349        else
     
    391397                newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    392398                %write result file
    393                 if Param.ActionInput.CheckLevelTransform
    394                     C=levels(Acor);
     399                if ~isequal(Param.ActionInput.SaturationCoeff,0)
     400                    C=levels(Acor,Param.ActionInput.CheckSubmedian,Param.ActionInput.SaturationCoeff);
    395401                    imwrite(C,newname,'BitDepth',16); % save the new image
    396402                else
     
    419425        newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    420426        %write result file
    421         if Param.ActionInput.CheckLevelTransform
    422             C=levels(Acor);
     427        if ~isequal(Param.ActionInput.SaturationCoeff,0)
     428            C=levels(Acor,Param.ActionInput.CheckSubmedian,Param.ActionInput.SaturationCoeff);
    423429            imwrite(C,newname,'BitDepth',16); % save the new image
    424430        else
     
    435441end
    436442
    437 function C=levels(A)
     443function C=levels(A,CheckSubmedian,Coeff)
    438444
    439445nblock_y=100;%2*Param.TransformInput.BlockSize;
     
    446452%Amin=A.*Aflagmin;%values of A at local minima
    447453% local background: find all the local minima in image subblocks
    448 fctblock= inline('median(x(:))');
    449 Backg=blkproc(A,[nblock_y nblock_x],fctblock);% take the median in  blocks
     454if CheckSubmedian
     455    fctblock= inline('median(x(:))');
     456    Backg=blkproc(A,[nblock_y nblock_x],fctblock);% take the median in  blocks
     457    %B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
     458    A=A-imresize(Backg,size(A),'bilinear');% substract background interpolated to the initial size image
     459end
    450460fctblock= inline('mean(x(:))');
    451 B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
    452 A=(A-B);%substract background
    453461AMean=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
    454462fctblock= inline('var(x(:))');
    455463AVar=blkproc(A,[nblock_y nblock_x],fctblock);% take the mean in  blocks
    456 Avalue=AVar./AMean% typical value of particle luminosity
     464Avalue=AVar./AMean;% typical value of particle luminosity
    457465Avalue=imresize(Avalue,size(A),'bilinear');% interpolate to the initial size image
    458 C=uint16(1000*tanh(A./(2*Avalue)));
    459 %Bmin=blkproc(Aflagmin,[nblock_y nblock_x],sumblock);% find the number of minima in blocks
    460 %Backg=Backg./Bmin; % find the average of minima in blocks
    461 % function C=levels(A)
    462 % %whos A;
    463 % B=double(A(:,:,1));
    464 % windowsize=round(min(size(B,1),size(B,2))/20);
    465 % windowsize=floor(windowsize/2)*2+1;
    466 % ix=1/2-windowsize/2:-1/2+windowsize/2;%
    467 % %del=np/3;
    468 % %fct=exp(-(ix/del).^2);
    469 % fct2=cos(ix/(windowsize-1)/2*pi/2);
    470 % %Mfiltre=(ones(5,5)/5^2);
    471 % %Mfiltre=fct2';
    472 % Mfiltre=fct2'*fct2;
    473 % Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
    474 %
    475 % C=filter2(Mfiltre,B);
    476 % C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
    477 % C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
    478 % C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
    479 % C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
    480 % C=tanh(B./(2*C));
    481 % [n,c]=hist(reshape(C,1,[]),100);
    482 % % figure;plot(c,n);
    483 %
    484 % [m,i]=max(n);
    485 % c_max=c(i);
    486 % [dummy,index]=sort(abs(c-c(i)));
    487 % n=n(index);
    488 % c=c(index);
    489 % i_select = find(cumsum(n)<0.95*sum(n));
    490 % if isempty(i_select)
    491 %     i_select = 1:length(c);
    492 % end
    493 % c_select=c(i_select);
    494 % n_select=n(i_select);
    495 % cmin=min(c_select);
    496 % cmax=max(c_select);
    497 % C=(C-cmin)/(cmax-cmin)*256;
    498 % C=uint8(C);
     466C=uint16(1000*tanh(A./(Coeff*Avalue)));
Note: See TracChangeset for help on using the changeset viewer.