Index: trunk/src/transform_field/ima_edge_detection.m
===================================================================
--- trunk/src/transform_field/ima_edge_detection.m	(revision 917)
+++ trunk/src/transform_field/ima_edge_detection.m	(revision 917)
@@ -0,0 +1,89 @@
+% 'ima_edge_detection': find edges 
+
+%------------------------------------------------------------------------
+%%%%  Use the general syntax for transform fields with a single input and parameters %%%%
+% OUTPUT: 
+% DataOut:   output field structure 
+%
+%INPUT:
+% DataIn:  input field structure
+% Param: matlab structure whose field Param.TransformInput contains the filter parameters
+%-----------------------------------
+
+%=======================================================================
+% Copyright 2008-2015, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
+%   http://www.legi.grenoble-inp.fr
+%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
+%
+%     This file is part of the toolbox UVMAT.
+%
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published
+%     by the Free Software Foundation; either version 2 of the license,
+%     or (at your option) any later version.
+%
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (see LICENSE.txt) for more details.
+%=======================================================================
+
+function DataOut=ima_edge_detection(DataIn,Param)
+
+%% request input parameters
+if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
+    prompt = {'npx';'npy';'threshold'};
+    dlg_title = 'get the filter size in x and y';
+    num_lines= 3;
+    def     = { '50';'50';'0.3'};
+    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
+            isfield(Param.TransformInput,'FilterBoxSize_y')&&isfield(Param.TransformInput,'LumThreshold')
+        def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y);num2str(Param.TransformInput.LumThreshold)};
+    end
+    answer = inputdlg(prompt,dlg_title,num_lines,def);
+    DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
+    DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
+    DataOut.TransformInput.LumThreshold=str2num(answer{3}); %size of the filtering window
+    return
+end
+
+DataOut=DataIn; %default
+%DataOut.A=255*edge(DataIn.A);
+
+%definition of the cos shape matrix filter
+ix=[1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2];%
+iy=[1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2];%
+%del=np/3;
+%fct=exp(-(ix/del).^2);
+fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
+fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
+%Mfiltre=(ones(5,5)/5^2);
+Mfiltre=fct2_y'*fct2_x;
+Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
+
+
+
+    Afilt=filter2(Mfiltre,DataIn.A(100:end-100,100:end-100));% smooth the image, excluding the edges (spurious reflexions)
+    Amax=max(max(Afilt));
+    Amin=min(min(Afilt));
+    Athreshold=(Amin+Amax)*Param.TransformInput.LumThreshold;
+%     
+%     DataOut.A=zeros(size(DataIn.A,1),size(DataIn.A,2),3);
+    DataOut.A=(DataIn.A>Athreshold);%transform to the initial image format
+%     DataOut.A(:,:,1)=DataIn.A;%transform to the initial image format, red
+STATS = regionprops(DataOut.A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList');
+Area=zeros(size(STATS));
+for iobj=1:numel(STATS)
+    Area(iobj)=STATS(iobj).FilledArea;
+end
+[Area, main_obj]=max(Area);
+    MajorAxisLength=STATS(main_obj).MajorAxisLength
+    MinorAxisLength=STATS(main_obj).MinorAxisLength
+for iobj=1:numel(STATS)
+    if iobj~=main_obj
+    DataOut.A(STATS(iobj).PixelIdxList)=0;
+    end
+end
+
+DataOut.A=Amax*DataOut.A;
+ 
