source: trunk/src/transform_field/remove_background.m @ 557

Last change on this file since 557 was 557, checked in by sommeria, 12 years ago

functions updated to fit with new conventions

File size: 1.1 KB
Line 
1function DataOut=remove_background(DataIn)
2%-----------------------------------------------
3%% set GUI config: no action defined
4DataOut=[];  %default  output field
5if strcmp(DataIn,'*')
6    return
7end
8
9%parameters
10threshold=200
11nblock_x=30;%size of image subblocks for analysis
12nblock_y=30;
13%---------------------------------------------------------
14DataOut=DataIn;%default
15
16%BACKGROUND LEVEL
17Atype=class(DataIn.A);
18A=double(DataIn.A);
19Backg=zeros(size(A));
20Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
21Amin=A.*Aflagmin;%values of A at local minima
22% local background: find all the local minima in image subblocks
23sumblock= inline('sum(sum(x(:)))');
24Backg=blkproc(Amin,[nblock_y nblock_x],sumblock);% take the sum in  blocks
25Bmin=blkproc(Aflagmin,[nblock_y nblock_x],sumblock);% find the number of minima in blocks
26Backg=Backg./Bmin; % find the average of minima in blocks
27B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
28ImPart=(A-B);
29DataOut.A=ImPart.*(ImPart>threshold);
30DataOut.A=feval(Atype,DataOut.A);
Note: See TracBrowser for help on using the repository browser.