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

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