source: trunk/src/transform_field/ima_remove_particles.m @ 742

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

clean the transform fcts

File size: 1.6 KB
Line 
1% 'ima_remove_particles': removes particles from an image (keeping 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=ima_remove_particles(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
26if ~isfield(DataIn,'A')
27    DataOut.Txt='remove_particles only valid for input images';
28    return
29end
30
31%BACKGROUND LEVEL
32Atype=class(DataIn.A);
33A=double(DataIn.A);
34Backg=zeros(size(A));
35Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
36Amin=A.*Aflagmin;%values of A at local minima
37% local background: find all the local minima in image subblocks
38sumblock= inline('sum(sum(x(:)))');
39Backg=blkproc(Amin,[nblock_y nblock_x],sumblock);% take the sum in  blocks
40Bmin=blkproc(Aflagmin,[nblock_y nblock_x],sumblock);% find the number of minima in blocks
41Backg=Backg./Bmin; % find the average of minima in blocks
42B=imresize(Backg,size(A),'bilinear');% interpolate to the initial size image
43ImPart=(A-B);
44ImPart=ImPart.*(ImPart>threshold);
45DataOut.A=A-ImPart;%
46DataOut.A=feval(Atype,DataOut.A);
47
Note: See TracBrowser for help on using the repository browser.