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

Last change on this file since 924 was 924, checked in by g7moreau, 8 years ago
  • Update Copyright Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
File size: 7.6 KB
Line 
1% 'ima_edge_detection': find edges
2
3%------------------------------------------------------------------------
4%%%%  Use the general syntax for transform fields with a single input and parameters %%%%
5% OUTPUT:
6% DataOut:   output field structure
7%
8%INPUT:
9% DataIn:  input field structure
10% Param: matlab structure whose field Param.TransformInput contains the filter parameters
11%-----------------------------------
12
13%=======================================================================
14% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
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
31function DataOut=ima_patch_detection(DataIn,Param)
32
33%% request input parameters
34if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
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   
44   
45   
46    %% create the GUI set_threshold
47    set(0,'Units','points')
48    ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
49    Width=350;% fig width in points (1/72 inch)
50    Height=min(0.8*ScreenSize(4),300);
51    Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40
52    Bottom=ScreenSize(4)-Height-40; %put fig at top right
53    hfig=findobj(allchild(0),'Tag','set_threshold');
54    if isempty(hfig)
55        hfig=figure('name','set_threshold','tag','set_threshold','MenuBar','none','NumberTitle','off','Units',...
56            'pixels','Position',[Left,Bottom,Width,Height],'DeleteFcn',@closefcn)%);
57    else
58        figure(hfig)
59    end
60    BackgroundColor=get(hfig,'Color');
61    hh=0.14; % box height (relative)
62    ii=0.01; % gap between uicontrols
63   
64    ww=(1-5*ii)/4; % box width (relative)
65    % first raw of the GUI
66    %Amask=imread('/fsnet/project/coriolis/2015/15MINI_MEDDY/0_REF_FILES/mask_patch.png');
67    uicontrol('Style','text','Units','normalized', 'Position', [ii 0.95-2*ii-0.75*hh ww hh/2],'BackgroundColor',BackgroundColor,...
68        'String','Threshold','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');%title
69    % uicontrol('Style','edit','Units','normalized', 'Position', [2*ii+ww 0.95-2*ii-hh ww hh],'tag','num_Z_1','BackgroundColor',[1 1 1],...
70    %     'String',num2str(SliceCoord(1,3)),'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''num_Z_1'': z position of first slice');%edit box
71    hThreshold=uicontrol('Style','edit','Units','normalized', 'Position', [3*ii+2*ww 0.95-2*ii-hh ww hh],'tag','Threshold','BackgroundColor',[1 1 1],...
72        'FontUnits','points','FontSize',12,'FontWeight','bold');%edit box
73    uicontrol('Style','slider','Units','normalized', 'Position', [0.1 0.1 0.8 0.1],'tag','SetThreshold','BackgroundColor',[1 1 1],...
74        'FontUnits','points','FontSize',12,'FontWeight','bold','Callback',@(hObject,eventdata)SetThreshold_Callback(hObject,eventdata));%edit box
75  %  uiwait(hfig);
76    %
77    %
78    %     DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
79    %     DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
80    DataOut.TransformInput.LumThreshold=str2num(get(hThreshold,'String')) %size of the filtering window
81   
82 
83   
84    return
85end
86
87DataOut=DataIn; %default
88%Amask=imread('/fsnet/project/coriolis/2015/15MINI_MEDDY/0_REF_FILES/mask_patch.png');
89plot_mask(DataIn.A,Param.TransformInput.LumThreshold)
90% Athreshold=Param.TransformInput.LumThreshold;
91% %
92% %     DataOut.A=zeros(size(DataIn.A,1),size(DataIn.A,2),3);
93% DataOut.A=(DataIn.A>Athreshold);%transform to the initial image format
94% %     DataOut.A(:,:,1)=DataIn.A;%transform to the initial image format, red
95% STATS = regionprops(DataOut.A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList');
96% Area=zeros(size(STATS));
97% for iobj=1:numel(STATS)
98%     Area(iobj)=STATS(iobj).FilledArea;
99% end
100% [Area, main_obj]=max(Area);
101% MajorAxisLength=STATS(main_obj).MajorAxisLength
102% MinorAxisLength=STATS(main_obj).MinorAxisLength
103% for iobj=1:numel(STATS)
104%     if iobj~=main_obj
105%         DataOut.A(STATS(iobj).PixelIdxList)=0;
106%     end
107% end
108%
109% DataOut.A=Amax*DataOut.A;
110
111
112%------------------------------------------------------------------------
113% function called by selecting CheckRefraction in the GUI set_slices
114function SetThreshold_Callback(hObject,eventdata)
115%------------------------------------------------------------------------
116hfig=get(hObject,'parent');
117hThreshold=findobj(hfig,'Tag','Threshold');
118Threshold=get(hObject,'Value');
119
120huvmat=findobj(allchild(0),'Tag','uvmat');
121hhuvmat=guidata(huvmat);
122UvData=get(huvmat,'UserData');
123Amax=max(max(UvData.Field.A));
124Amin=min(min(UvData.Field.A));
125Threshold=Amin+(Amax-Amin)*Threshold;
126set(hThreshold,'String',num2str(Threshold))
127
128plot_mask(UvData.Field.A,Threshold)
129
130UvData.XmlData{1}.TransformInput.LumThreshold=Threshold;
131set(huvmat,'UserData',UvData)
132
133
134
135
136
137
138% h_refraction(1)=findobj(hset_slice,'String','surface');
139% h_refraction(2)=findobj(hset_slice,'Tag','num_H');
140% h_refraction(3)=findobj(hset_slice,'String','index');
141% h_refraction(4)=findobj(hset_slice,'Tag','num_RefractionIndex');
142% if isequal(get(hObject,'Value'),1)
143%     set(h_refraction,'Visible','on')
144% else
145%     set(h_refraction,'Visible','off')
146% end
147
148function plot_mask(A,Threshold)
149   
150A=(A>Threshold) ;%& Amask>100;%transform to binary image format
151try
152    STATS = regionprops(A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList');
153    Area=zeros(size(STATS));
154    for iobj=1:numel(STATS)
155        Area(iobj)=STATS(iobj).FilledArea;
156    end
157    [Area, main_obj]=max(Area);
158    MajorAxisLength=STATS(main_obj).MajorAxisLength;
159    MinorAxisLength=STATS(main_obj).MinorAxisLength;
160    for iobj=1:numel(STATS)
161        if iobj~=main_obj
162            A(STATS(iobj).PixelIdxList)=0;
163        end
164    end
165catch ME
166    disp('image toolbox not available, skipped')
167end
168[npy,npx]=size(A);
169A=cat(3,A,zeros(npy,npx,2));% make a color image
170
171huvmat=findobj(allchild(0),'Tag','uvmat');
172hhuvmat=guidata(huvmat);
173hmask=findobj(hhuvmat.PlotAxes,'Tag','MaskFig')
174if isempty(hmask)
175    axes(hhuvmat.PlotAxes)
176    hold on
177    imagesc([0.5 npx],[npy-0.5 0.5],A,'AlphaData',0.2,'Tag','MaskFig')
178else
179    set(hmask,'CData',A)
180    set(hmask,'AlphaData',0.2)
181end
182
183
184function closefcn(hObject,eventdata)
185
186huvmat=findobj(allchild(0),'Tag','uvmat');
187hhuvmat=guidata(huvmat);
188hmask=findobj(hhuvmat.PlotAxes,'Tag','MaskFig')
189if ~isempty(hmask)
190   delete(hmask)
191end
Note: See TracBrowser for help on using the repository browser.