source: trunk/src/transform_field/ima_remove_background.m @ 690

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

clean the transform fcts

File size: 1.5 KB
Line 
1% 'ima_remove_background': removes backgound from an image (using the local minimum)
2% requires the Matlab image processing toolbox
3
4%------------------------------------------------------------------------
5%%%%  Use the general syntax for transform fields with a single input %%%%
6% OUTPUT:
7% DataOut:   output field structure
8
9%INPUT:
10% DataIn:  first input field structure
11%------------------------------------------------------------------------
12function DataOut=remove_background(DataIn)
13%------------------------------------------------------------------------
14DataOut=[];  %default  output field
15if strcmp(DataIn,'*')
16    return
17end
18
19%parameters
20threshold=200
21nblock_x=30;%size of image subblocks for analysis
22nblock_y=30;
23%---------------------------------------------------------
24DataOut=DataIn;%default
25
26%BACKGROUND LEVEL
27Atype=class(DataIn.A);
28A=double(DataIn.A);
29Backg=zeros(size(A));
30Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
31Amin=A.*Aflagmin;%values of A at local minima
32% local background: find all the local minima in image subblocks
33sumblock= inline('sum(sum(x(:)))');
34Backg=blkproc(Amin,[nblock_y nblock_x],sumblock);% take the sum in  blocks
35Bmin=blkproc(Aflagmin,[nblock_y nblock_x],sumblock);% find the number of minima in blocks
36Backg=Backg./Bmin; % find the average of minima in blocks
37B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
38ImPart=(A-B);
39DataOut.A=ImPart.*(ImPart>threshold);
40DataOut.A=feval(Atype,DataOut.A);
Note: See TracBrowser for help on using the repository browser.