source: trunk/src/transform_field/ima_edge_detection.m @ 1179

Last change on this file since 1179 was 1179, checked in by sommeria, 4 weeks ago

a few bug repairs and cleaning

File size: 4.0 KB
Line 
1% 'ima_edge_detection': find edges
2% requires MATLAB Image Processing toolbox
3
4%------------------------------------------------------------------------
5%%%%  Use the general syntax for transform fields with a single input and parameters %%%%
6% OUTPUT:
7% Data:   output field structure
8%
9%INPUT:
10% DataIn:  input field structure
11% Param: matlab structure whose field Param.TransformInput contains the filter parameters
12%-----------------------------------
13
14%=======================================================================
15% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
16%   http://www.legi.grenoble-inp.fr
17%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
18%
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published
23%     by the Free Software Foundation; either version 2 of the license,
24%     or (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (see LICENSE.txt) for more details.
30%=======================================================================
31
32function Data=ima_edge_detection(Data,Param,Data_1)
33
34%% request input parameters
35if isfield(Data,'Action') && isfield(Data.Action,'RUN') && isequal(Data.Action.RUN,0)
36    prompt = {'npx';'npy';'threshold'};
37    dlg_title = 'get the filter size in x and y';
38    num_lines= 3;
39    def     = { '50';'50';'0.3'};
40    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
41            isfield(Param.TransformInput,'FilterBoxSize_y')&&isfield(Param.TransformInput,'LumThreshold')
42        def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y);num2str(Param.TransformInput.LumThreshold)};
43    end
44    answer = inputdlg(prompt,dlg_title,num_lines,def);
45    Data.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
46    Data.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
47    Data.TransformInput.LumThreshold=str2num(answer{3}); %size of the filtering window
48    return
49end
50
51
52%definition of the cos shape matrix filter
53ix=[1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2];%
54iy=[1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2];%
55%del=np/3;
56%fct=exp(-(ix/del).^2);
57fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
58fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
59%Mfiltre=(ones(5,5)/5^2);
60Mfiltre=fct2_y'*fct2_x;
61Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
62
63Afilt=filter2(Mfiltre,Data.A);% smooth the image, excluding the edges (spurious reflexions)
64
65    %Afilt=filter2(Mfiltre,Data.A(100:end-100,100:end-100));% smooth the image, excluding the edges (spurious reflexions)
66  %Data.A= double(Data.A)-Afilt;
67
68
69   
70   
71%     
72    Amax=max(max(Afilt));
73    Amin=min(min(Afilt));
74%     Data.A( Data_1.A(100:end-100,100:end-100)==100)=(Amin+Amax)/2;
75
76 
77 
78    Athreshold=(Amin+Amax)*Param.TransformInput.LumThreshold;
79%     
80%     Data.A=zeros(size(Data.A,1),size(Data.A,2),3);
81    Data.A=(Data.A>Athreshold);%transform to the initial image format
82%     Data.A(:,:,1)=Data.A;%transform to the initial image format, red
83STATS = regionprops(Data.A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList');
84Area=zeros(size(STATS));
85for iobj=1:numel(STATS)
86    Area(iobj)=STATS(iobj).FilledArea;
87end
88[Area, main_obj]=max(Area)
89    MajorAxisLength=STATS(main_obj).MajorAxisLength;
90    MinorAxisLength=STATS(main_obj).MinorAxisLength;
91for iobj=1:numel(STATS)
92    if iobj~=main_obj
93    Data.A(STATS(iobj).PixelIdxList)=0;
94    end
95end
96
97Data.A=Amax*Data.A;
98 
Note: See TracBrowser for help on using the repository browser.