Home > SuperSegger > trainingConstants > updateTrainingImage.m

updateTrainingImage

PURPOSE ^

updateTrainingImage : user can click on segments or regions to change score

SYNOPSIS ^

function [data,touch_list] = updateTrainingImage (data, FLAGS, x)

DESCRIPTION ^

 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/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data,touch_list] = updateTrainingImage (data, FLAGS, x)
0002 % updateTrainingImage : user can click on segments or regions to change score
0003 % from 0 to 1 or vice versa. It updates scores, cell mask, good and bad
0004 % segs.
0005 %
0006 % INPUT :
0007 %       data : data file with segments to be modified
0008 %       FLAGS : im_flag = 1 for segments, 2 for regions.
0009 % INPUT :
0010 %       data : data file with modified segments
0011 %       touch_list : list with modified segments/regions
0012 %
0013 % Copyright (C) 2016 Wiggins Lab
0014 % Written by Paul Wiggins, Stella Stylianidou.
0015 % University of Washington, 2016
0016 % This file is part of SuperSegger.
0017 %
0018 % SuperSegger is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % SuperSegger is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 im_flag = FLAGS.im_flag ;
0032 touch_list = [];
0033 ss = size(data.phase);
0034 
0035 x = round(x);
0036 
0037 if ~isempty(x)
0038     % creates an image of 51 x 51 of gaussian like point
0039     tmp = zeros([51,51]);
0040     tmp(26,26) = 1;
0041     tmp = 8000-double(bwdist(tmp));
0042 
0043     rmin = max([1,x(2)-25]);
0044     rmax = min([ss(1),x(2)+25]);
0045 
0046     cmin = max([1,x(1)-25]);
0047     cmax = min([ss(2),x(1)+25]);
0048 
0049     rrind = rmin:rmax;
0050     ccind = cmin:cmax;
0051 
0052     pointSize = [numel(rrind),numel(ccind)];
0053 
0054 
0055     if im_flag == 1
0056 
0057         segs = data.segs.segs_good(rrind,ccind) + ...
0058             data.segs.segs_bad(rrind,ccind);
0059         segs = segs>0;
0060         tmp = tmp(26-x(2)+rrind,26-x(1)+ccind).*segs ;
0061 
0062         [~,ind] = max( tmp(:) );
0063 
0064         % indices in point image for max / closest segment
0065         [sub1, sub2] = ind2sub( pointSize, ind );
0066 
0067         % closest segments id
0068         ii = data.segs.segs_label(rmin+sub1-1,cmin+sub2-1);
0069 
0070         if ii ~=0
0071 
0072             % xx and yy are the segments coordinates
0073             [xx,yy] = getBB( data.segs.props(ii).BoundingBox );
0074 
0075             if data.segs.score(ii) % score is 1
0076                 data.segs.score(ii) = 0; % set to 0
0077                 data.segs.segs_good(yy,xx) ...
0078                     = double(~~(data.segs.segs_good(yy,xx)...
0079                     - double(data.segs.segs_label(yy,xx)==ii)));
0080                 data.segs.segs_bad(yy,xx) = ...
0081                     double(~~(data.segs.segs_bad(yy,xx)...
0082                     +double(data.segs.segs_label(yy,xx)==ii)));
0083             else
0084                 data.segs.score(ii) = 1;
0085                 data.segs.segs_good(yy,xx) = ...
0086                     double(~~(data.segs.segs_good(yy,xx)+...
0087                     double(data.segs.segs_label(yy,xx)==ii)));
0088                 data.segs.segs_bad(yy,xx) = ...
0089                     double(~~(data.segs.segs_bad(yy,xx)-...
0090                     double(data.segs.segs_label(yy,xx)==ii)));
0091             end
0092 
0093             % updates cell mask
0094             data.mask_cell = double((data.mask_bg - data.segs.segs_good - data.segs.segs_3n)>0);
0095             data.regs.regs_label = bwlabel(data.mask_cell);
0096             touch_list = [touch_list, ii];
0097         end
0098     elseif im_flag == 2
0099         tmp = tmp(26-x(2)+rrind,26-x(1)+ccind).*data.mask_cell(rrind,ccind);
0100         try
0101             [~,ind] = max( tmp(:) );
0102         catch ME
0103             printError(ME);
0104         end
0105 
0106         [sub1, sub2] = ind2sub( pointSize, ind );
0107         ii = data.regs.regs_label(sub1-1+rmin,sub2-1+cmin);
0108         plot( sub2-1+cmin, sub1-1+rmin, 'g.' );
0109 
0110         if ii
0111             data.regs.score(ii) = ~data.regs.score(ii);
0112         end
0113     end
0114 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005