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

Last change on this file since 924 was 924, checked in by g7moreau, 5 years ago
  • Update Copyright Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
File size: 2.7 KB
Line 
1% 'ima_remove_particles': removes particles from an image (keeping the local minimum)
2% requires the Matlab image processing toolbox
3%------------------------------------------------------------------------
4%%%%  Use the general syntax for transform fields with a single input %%%%
5% OUTPUT:
6% DataOut:   output field structure
7%
8%INPUT:
9% DataIn:  first input field structure
10
11%=======================================================================
12% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
13%   http://www.legi.grenoble-inp.fr
14%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
15%
16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
19%     it under the terms of the GNU General Public License as published
20%     by the Free Software Foundation; either version 2 of the license,
21%     or (at your option) any later version.
22%
23%     UVMAT is distributed in the hope that it will be useful,
24%     but WITHOUT ANY WARRANTY; without even the implied warranty of
25%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
29function DataOut=ima_remove_particles(DataIn,Param)
30%------------------------------------------------------------------------
31%% request input parameters
32if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
33    prompt = {'radius'};
34    dlg_title = 'get the disk radius (pixels) used to calculate the regional minimum';
35    num_lines= 1;
36    def     = { '4'};
37    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'DiskRadius')
38        def={num2str(Param.TransformInput.DiskRadius)};
39    end
40    answer = inputdlg(prompt,dlg_title,num_lines,def);
41    DataOut.TransformInput.DiskRadius=str2num(answer{1});
42    return
43end
44if ~isfield(DataIn,'A')
45    DataOut.Txt='remove_particles only valid for input images';
46    return
47end
48if ~exist('imerode','file');
49        DataOut.Txt='the function imerode from the image processing toolbox is needed';
50    return
51end
52
53SE=strel('disk',Param.TransformInput.DiskRadius);
54%---------------------------------------------------------
55DataOut=DataIn;%default
56
57[npy,npx]=size(DataIn.A);
58[X,Y]=meshgrid(1:npx,1:npy);
59%BACKGROUND LEVEL
60Atype=class(DataIn.A);
61%SE=ones(4);
62Aerode=imerode(DataIn.A,SE);
63Aflagmin=find(DataIn.A==Aerode);
64% Backg=zeros(size(A));
65%Aflagmin=imregionalmin(DataIn.A);%Amin=1 for local image minima
66Xmin=X(Aflagmin);
67Ymin=Y(Aflagmin);
68Amin=double(DataIn.A(Aflagmin));
69F = TriScatteredInterp([Xmin Ymin], Amin);
70DataOut.A=F(X,Y);
71DataOut.A=feval(Atype,DataOut.A);
72
Note: See TracBrowser for help on using the repository browser.