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

Last change on this file since 1162 was 1127, checked in by g7moreau, 11 months ago

Update Joel email

File size: 7.8 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-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
15%   http://www.legi.grenoble-inp.fr
16%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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');
89hfig=findobj(allchild(0),'Tag','set_threshold');
90hThreshold=findobj(hfig,'Tag','Threshold');
91Threshold=str2num(get(hThreshold,'String'));
92plot_mask(DataIn.A,Threshold)
93% Athreshold=Param.TransformInput.LumThreshold;
94% %
95% %     DataOut.A=zeros(size(DataIn.A,1),size(DataIn.A,2),3);
96% DataOut.A=(DataIn.A>Athreshold);%transform to the initial image format
97% %     DataOut.A(:,:,1)=DataIn.A;%transform to the initial image format, red
98% STATS = regionprops(DataOut.A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList');
99% Area=zeros(size(STATS));
100% for iobj=1:numel(STATS)
101%     Area(iobj)=STATS(iobj).FilledArea;
102% end
103% [Area, main_obj]=max(Area);
104% MajorAxisLength=STATS(main_obj).MajorAxisLength
105% MinorAxisLength=STATS(main_obj).MinorAxisLength
106% for iobj=1:numel(STATS)
107%     if iobj~=main_obj
108%         DataOut.A(STATS(iobj).PixelIdxList)=0;
109%     end
110% end
111%
112% DataOut.A=Amax*DataOut.A;
113
114
115%------------------------------------------------------------------------
116% function called by selecting CheckRefraction in the GUI set_slices
117function SetThreshold_Callback(hObject,eventdata)
118%------------------------------------------------------------------------
119hfig=get(hObject,'parent');
120hThreshold=findobj(hfig,'Tag','Threshold');
121Threshold=get(hObject,'Value');
122
123huvmat=findobj(allchild(0),'Tag','uvmat');
124hhuvmat=guidata(huvmat);
125UvData=get(huvmat,'UserData');
126Amax=max(max(UvData.Field.A));
127Amin=min(min(UvData.Field.A));
128Threshold=Amin+(Amax-Amin)*Threshold;
129set(hThreshold,'String',num2str(Threshold))
130
131plot_mask(UvData.Field.A,Threshold)
132
133UvData.XmlData{1}.TransformInput.LumThreshold=Threshold;
134set(huvmat,'UserData',UvData)
135
136
137
138
139
140
141% h_refraction(1)=findobj(hset_slice,'String','surface');
142% h_refraction(2)=findobj(hset_slice,'Tag','num_H');
143% h_refraction(3)=findobj(hset_slice,'String','index');
144% h_refraction(4)=findobj(hset_slice,'Tag','num_RefractionIndex');
145% if isequal(get(hObject,'Value'),1)
146%     set(h_refraction,'Visible','on')
147% else
148%     set(h_refraction,'Visible','off')
149% end
150
151function plot_mask(A,Threshold)
152   
153A=(A>Threshold) ;%& Amask>100;%transform to binary image format
154try
155    STATS = regionprops(A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList');
156    Area=zeros(size(STATS));
157    for iobj=1:numel(STATS)
158        Area(iobj)=STATS(iobj).FilledArea;
159    end
160    [Area, main_obj]=max(Area);
161    MajorAxisLength=STATS(main_obj).MajorAxisLength;
162    MinorAxisLength=STATS(main_obj).MinorAxisLength;
163    for iobj=1:numel(STATS)
164        if iobj~=main_obj
165            A(STATS(iobj).PixelIdxList)=0;
166        end
167    end
168catch ME
169    disp('image toolbox not available, skipped')
170end
171[npy,npx]=size(A);
172A=cat(3,A,zeros(npy,npx,2));% make a color image
173
174huvmat=findobj(allchild(0),'Tag','uvmat');
175hhuvmat=guidata(huvmat);
176hmask=findobj(hhuvmat.PlotAxes,'Tag','MaskFig')
177if isempty(hmask)
178    axes(hhuvmat.PlotAxes)
179    hold on
180    imagesc([0.5 npx],[npy-0.5 0.5],A,'AlphaData',0.2,'Tag','MaskFig')
181else
182    set(hmask,'CData',A)
183    set(hmask,'AlphaData',0.2)
184end
185
186
187function closefcn(hObject,eventdata)
188
189huvmat=findobj(allchild(0),'Tag','uvmat');
190hhuvmat=guidata(huvmat);
191hmask=findobj(hhuvmat.PlotAxes,'Tag','MaskFig')
192if ~isempty(hmask)
193   delete(hmask)
194end
Note: See TracBrowser for help on using the repository browser.