Changeset 1124
 Timestamp:
 Sep 28, 2023, 6:22:45 PM (12 months ago)
 Location:
 trunk/src/series
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/series/sub_background.m
r1107 r1124 142 142 CheckVolume='No'; 143 143 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 145 146 nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background, 146 147 if isequal(mod(nbaver,2),0)% if nbaver is even … … 150 151 end 151 152 BrightnessRankThreshold=0.1; 152 CheckSubmedian='No';153 SaturationCoeff=0;153 % CheckSubmedian='No'; 154 % SaturationCoeff=0; 154 155 if isfield(Param,'ActionInput') 155 156 if isfield(Param.ActionInput,'CheckVolume') && Param.ActionInput.CheckVolume … … 162 163 BrightnessRankThreshold=Param.ActionInput.BrightnessRankThreshold; 163 164 end 164 if isfield(Param.ActionInput,'CheckSubmedian') && Param.ActionInput.CheckSubmedian165 CheckSubmedian='Yes';166 end167 if isfield(Param.ActionInput,'Saturation Coeff')168 Saturation Coeff=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; 169 170 end 170 171 end … … 172 173 'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';... 173 174 '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' }; 176 176 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)}; 179 179 answer = inputdlg(prompt,dlg_title,num_lines,def); 180 180 if isempty(answer) … … 189 189 end 190 190 if strcmp(answer{1},'Yes') 191 step=2;%the sliding background is shifted by the length of one burst, assumed =2 for volume ;ode191 step=2;%the sliding background is shifted by the length of one burst, assumed =2 for volume 192 192 ParamOut.NbSlice=1; %nbre of slices displayed 193 193 else 194 194 step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst 195 195 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); 202 197 ParamOut.ActionInput.CheckVolume=strcmp(answer{1},'Yes'); 203 ParamOut.ActionInput.SlidingSequenceLength=nbaver_ima;204 198 ParamOut.ActionInput.BrightnessRankThreshold=str2double(answer{3}); 205 ParamOut.ActionInput.CheckSubmedian=strcmp(answer{4},'Yes');206 ParamOut.ActionInput.Saturation Coeff=str2double(answer{5});199 % ParamOut.ActionInput.CheckSubmedian=strcmp(answer{4},'Yes'); 200 ParamOut.ActionInput.SaturationValue=str2double(answer{4}); 207 201 % apply the image rescaling function 'level' (avoid the blinking effects of bright particles) 208 202 % answer=msgbox_uvmat('INPUT_YN','apply image rescaling function levels.m after sub_background'); … … 259 253 if strcmp(FileInfo{1}.FileType,'image') 260 254 NomTypeOut=NomType{1}; 261 % if strcmp(lower(NomType{1}(end)),'a')262 % NomTypeOut=NomType{1};%case of letter appendix263 255 elseif isempty(j1_series{1}) 264 256 NomTypeOut='_1'; … … 267 259 end 268 260 OutputDir=[Param.OutputSubDir Param.OutputDirExt]; 261 OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device); 269 262 270 263 %% file index parameters 271 % NbSlice_i: nbre of slices for i index : different of of 1 for multilevel,264 % NbSlice_i: nbre of slices for i index in multilevel mode: equal to 1 for a single level 272 265 % the function sub_background is then relaunched by the GUI series for each 273 266 % slice, incrementing the first index i by 1 … … 280 273 nbfield_i=size(i1_series{1},2); %nb of fields for the i index 281 274 282 if Param.ActionInput.CheckVolume 275 if Param.ActionInput.CheckVolume% case of volume scan: the background images must be determined for each index j 283 276 step=2;% we assume the burst contains only one image pair 284 277 NbSlice_j=nbfield_j; 285 NbSlice=nbfield_j;286 278 nbfield_series=nbfield_i; 287 279 else 288 280 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; 291 282 %nbfield_i=floor(nbfield_i/NbSlice_i);%total number of indexes in a slice (adjusted to an integer number of slices) 292 283 %nbfield=nbfield_i*NbSlice_i; %total number of fields after adjustement … … 294 285 end 295 286 nbfield=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); 302 288 if nbaver_ima > nbfield 303 289 display('number of images in a slice smaller than the proposed number of images for the sliding average') … … 342 328 filename=filecell{1,ifile}; 343 329 Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile)); 344 if ndims(Aread)==3 ;%color images330 if ndims(Aread)==3%color images 345 331 Aread=sum(double(Aread),3);% take the sum of color components 346 332 end … … 352 338 %% substract the first background image to the first images 353 339 display( 'first background image will be substracted') 354 for ifield=1:step*(halfnbaver+1) ;% nbre of images treated by the first background image340 for ifield=1:step*(halfnbaver+1)% nbre of images treated by the first background image 355 341 Acor=double(Ak(:,:,ifield))double(B);%substract background to the current image 356 342 Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor … … 360 346 j1=j1_series{1}(ifile); 361 347 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); 363 349 364 350 %write result file 365 if ~isequal(Param.ActionInput.Saturation Coeff,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); 367 353 imwrite(C,newname,'BitDepth',16); % save the new image 368 354 else … … 400 386 j1=j1_series{1}(ifile); 401 387 end 388 402 389 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1); 403 390 Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile)); 404 if ndims(Aread)==3 ;%color images391 if ndims(Aread)==3%case of color images 405 392 Aread=sum(double(Aread),3);% take the sum of color components 406 393 end … … 417 404 j1=j1_series{1}(ifile); 418 405 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); 420 407 %write result file 421 if ~isequal(Param.ActionInput.Saturation Coeff,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); 423 410 imwrite(C,newname,'BitDepth',16); % save the new image 424 411 else … … 445 432 j1=j1_series{1}(ifile); 446 433 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); 448 435 %write result file 449 if ~isequal(Param.ActionInput.Saturation Coeff,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); 451 438 imwrite(C,newname,'BitDepth',16); % save the new image 452 439 else … … 463 450 end 464 451 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=Aimresize(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))); 452 function 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=Aimresize(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))); 476 C=uint16(Coeff*tanh(A./Coeff)); 477 % 478 % adjust the number of images used for the sliding average 479 function [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 481 nbaver=ceil(nb_aver_in/step);%number of bursts for the sliding background 482 if 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) 484 end 485 step_out=step; 486 if nbaver>1 487 nbaver_ima=nbaver*step;% correct the nbre of images corresponding to nbaver 488 else 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; 494 end 
trunk/src/series/sub_background_special.m
r1107 r1124 106 106 Bfilter=ones(1,20)/20; 107 107 %% root input file names and nomenclature type (cell arrays with one element) 108 OutputDir=[Param.OutputSubDir Param.OutputDirExt]; 4108 OutputDir=[Param.OutputSubDir Param.OutputDirExt]; 109 109 nbj=numel(Param.IndexRange.first_i:Param.IndexRange.last_i); 110 110 for i_ind=Param.IndexRange.first_i:Param.IndexRange.last_i
Note: See TracChangeset
for help on using the changeset viewer.