Skip to content

Commit

Permalink
Fixed problem introduced when segmented editing was updated. Added up…
Browse files Browse the repository at this point in the history
…dateTrainingImageTrain... new version of updateTrainingImage.
  • Loading branch information
Paul Wiggins committed Aug 8, 2018
1 parent 9e36803 commit 1dcc875
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 4 deletions.
9 changes: 5 additions & 4 deletions trainingConstants/trainingGui.m
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ function updateUI(handles)
FLAGS.t_flag = 0;
showSegRuleGUI(settings_train.currentData, FLAGS, handles.viewport_train);
if numel(handles.viewport_train.Children) > 0
set(handles.viewport_train.Children(1),'ButtonDownFcn',@imageButtonDownFcn);
set(handles.viewport_train.Children(1),'ButtonDownFcn',{@imageButtonDownFcn,handles});
end

elseif settings_train.axisFlag == 4
Expand All @@ -420,7 +420,7 @@ function updateUI(handles)
% deleting regions
maskFigure()
if numel(handles.viewport_train.Children) > 0
set(handles.viewport_train.Children(1),'ButtonDownFcn',@imageButtonDownFcn);
set(handles.viewport_train.Children(1),'ButtonDownFcn',{@imageButtonDownFcn,handles});
end

if numel(settings_train.firstPosition) > 0
Expand All @@ -436,7 +436,7 @@ function updateUI(handles)
if settings_train.cropTime
% deleting areas in square
if numel(handles.viewport_train.Children) > 0
set(handles.viewport_train.Children(1),'ButtonDownFcn',@imageButtonDownFcn);
set(handles.viewport_train.Children(1),'ButtonDownFcn',{@imageButtonDownFcn,handles});
end

if numel(settings_train.firstPosition) > 0
Expand Down Expand Up @@ -726,9 +726,10 @@ function imageButtonDownFcn(hObject, eventdata, handles)
FLAGS.im_flag = settings_train.axisFlag;
FLAGS.S_flag = 0;
FLAGS.t_flag = 0;


addUndo();
[settings_train.currentData, list] = updateTrainingImage(settings_train.currentData, FLAGS, eventdata.IntersectionPoint(1:2));
[settings_train.currentData, list] = updateTrainingImageTrain(settings_train.currentData, FLAGS, eventdata.IntersectionPoint(1:2));
if settings_train.axisFlag == 1 && numel(list) > 0
settings_train.currentData = intMakeRegs( settings_train.currentData, settings_train.CONST, [], [] );
end
Expand Down
114 changes: 114 additions & 0 deletions trainingConstants/updateTrainingImageTrain.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
function [data,touch_list] = updateTrainingImage (data, FLAGS, x)
% updateTrainingImage : user can click on segments or regions to change score
% from 0 to 1 or vice versa. It updates scores, cell mask, good and bad
% segs.
%
% INPUT :
% data : data file with segments to be modified
% FLAGS : im_flag = 1 for segments, 2 for regions.
% INPUT :
% data : data file with modified segments
% touch_list : list with modified segments/regions
%
% Copyright (C) 2016 Wiggins Lab
% Written by Paul Wiggins, Stella Stylianidou.
% University of Washington, 2016
% This file is part of SuperSegger.
%
% SuperSegger 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 3 of the License, or
% (at your option) any later version.
%
% SuperSegger 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 for more details.
%
% You should have received a copy of the GNU General Public License
% along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.

im_flag = FLAGS.im_flag ;
touch_list = [];
ss = size(data.phase);

x = round(x);

if ~isempty(x)
% creates an image of 51 x 51 of gaussian like point
tmp = zeros([51,51]);
tmp(26,26) = 1;
tmp = 8000-double(bwdist(tmp));

rmin = max([1,x(2)-25]);
rmax = min([ss(1),x(2)+25]);

cmin = max([1,x(1)-25]);
cmax = min([ss(2),x(1)+25]);

rrind = rmin:rmax;
ccind = cmin:cmax;

pointSize = [numel(rrind),numel(ccind)];


if im_flag == 1

segs = data.segs.segs_good(rrind,ccind) + ...
data.segs.segs_bad(rrind,ccind);
segs = segs>0;
tmp = tmp(26-x(2)+rrind,26-x(1)+ccind).*segs ;

[~,ind] = max( tmp(:) );

% indices in point image for max / closest segment
[sub1, sub2] = ind2sub( pointSize, ind );

% closest segments id
ii = data.segs.segs_label(rmin+sub1-1,cmin+sub2-1);

if ii ~=0

% xx and yy are the segments coordinates
[xx,yy] = getBB( data.segs.props(ii).BoundingBox );

if data.segs.score(ii) % score is 1
data.segs.score(ii) = 0; % set to 0
data.segs.segs_good(yy,xx) ...
= double(~~(data.segs.segs_good(yy,xx)...
- double(data.segs.segs_label(yy,xx)==ii)));
data.segs.segs_bad(yy,xx) = ...
double(~~(data.segs.segs_bad(yy,xx)...
+double(data.segs.segs_label(yy,xx)==ii)));
else
data.segs.score(ii) = 1;
data.segs.segs_good(yy,xx) = ...
double(~~(data.segs.segs_good(yy,xx)+...
double(data.segs.segs_label(yy,xx)==ii)));
data.segs.segs_bad(yy,xx) = ...
double(~~(data.segs.segs_bad(yy,xx)-...
double(data.segs.segs_label(yy,xx)==ii)));
end

% updates cell mask
data.mask_cell = double((data.mask_bg - data.segs.segs_good - data.segs.segs_3n)>0);
data.regs.regs_label = bwlabel(data.mask_cell);
touch_list = [touch_list, ii];
end
elseif im_flag == 2
tmp = tmp(26-x(2)+rrind,26-x(1)+ccind).*data.mask_cell(rrind,ccind);
try
[~,ind] = max( tmp(:) );
catch ME
printError(ME);
end

[sub1, sub2] = ind2sub( pointSize, ind );
ii = data.regs.regs_label(sub1-1+rmin,sub2-1+cmin);
plot( sub2-1+cmin, sub1-1+rmin, 'g.' );

if ii
data.regs.score(ii) = ~data.regs.score(ii);
end
end
end

0 comments on commit 1dcc875

Please sign in to comment.