Home > SuperSegger > trainingConstants > makeTrainingData.m

makeTrainingData

PURPOSE ^

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

SYNOPSIS ^

function [data,touch_list] = makeTrainingData (data,FLAGS)

DESCRIPTION ^

 makeTrainingData : 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] = makeTrainingData (data,FLAGS)
0002 % makeTrainingData : 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 
0032 if ~exist('FLAGS','var') ||  ~isfield(FLAGS,'im_flag')
0033     FLAGS.im_flag  = 1;
0034     FLAGS.S_flag  = 0;
0035     FLAGS.t_flag  = 0;
0036 end
0037 
0038 im_flag = FLAGS.im_flag ;
0039 touch_list = []
0040 ss = size(data.phase);
0041 selectMode = true;
0042 
0043 
0044 while selectMode
0045     figure(2)
0046     imshow(data.phase);
0047     figure(1);
0048     showSegRule( data, FLAGS ,1)
0049     
0050     disp ('Click on segment/region to modify. To exit press enter while image is selected.');
0051     x = floor(ginput(1));
0052     disp(x);
0053     
0054     if ~isempty(x)
0055         % creates an image of 51 x 51 of gaussian like point
0056         tmp = zeros([51,51]);
0057         tmp(26,26) = 1;
0058         tmp = 8000-double(bwdist(tmp));
0059         
0060         rmin = max([1,x(2)-25]);
0061         rmax = min([ss(1),x(2)+25]);
0062         
0063         cmin = max([1,x(1)-25]);
0064         cmax = min([ss(2),x(1)+25]);
0065         
0066         rrind = rmin:rmax;
0067         ccind = cmin:cmax;
0068         
0069         pointSize = [numel(rrind),numel(ccind)];
0070         
0071         
0072         if im_flag == 1
0073             
0074             segs = data.segs.segs_good(rrind,ccind) + ...
0075                 data.segs.segs_bad(rrind,ccind);
0076             segs = segs>0;
0077             tmp = tmp(26-x(2)+rrind,26-x(1)+ccind).*segs ;
0078             
0079             [~,ind] = max( tmp(:) );
0080             
0081             % indices in point image for max / closest segment
0082             [sub1, sub2] = ind2sub( pointSize, ind );
0083             
0084             % closest segments id
0085             ii = data.segs.segs_label(rmin+sub1-1,cmin+sub2-1);
0086             
0087             if ii ~=0
0088                 
0089                 hold on;
0090                 plot( sub2-1+cmin, sub1-1+rmin, 'w.','MarkerSize', 30)
0091                 
0092                 % xx and yy are the segments coordinates
0093                 [xx,yy] = getBB( data.segs.props(ii).BoundingBox );
0094                 
0095                 if data.segs.score(ii) % score is 1
0096                     data.segs.score(ii) = 0; % set to 0
0097                     data.segs.segs_good(yy,xx) ...
0098                         = double(~~(data.segs.segs_good(yy,xx)...
0099                         - double(data.segs.segs_label(yy,xx)==ii)));
0100                     data.segs.segs_bad(yy,xx) = ...
0101                         double(~~(data.segs.segs_bad(yy,xx)...
0102                         +double(data.segs.segs_label(yy,xx)==ii)));
0103                 else
0104                     data.segs.score(ii) = 1;
0105                     data.segs.segs_good(yy,xx) = ...
0106                         double(~~(data.segs.segs_good(yy,xx)+...
0107                         double(data.segs.segs_label(yy,xx)==ii)));
0108                     data.segs.segs_bad(yy,xx) = ...
0109                         double(~~(data.segs.segs_bad(yy,xx)-...
0110                         double(data.segs.segs_label(yy,xx)==ii)));
0111                     
0112                 end
0113                 
0114                 % updates cell mask
0115                 data.mask_cell   = double((data.mask_bg - data.segs.segs_good - data.segs.segs_3n)>0);
0116                 touch_list = [touch_list, ii];
0117             end
0118         elseif im_flag == 2
0119             tmp = tmp(26-x(2)+rrind,26-x(1)+ccind).*data.mask_cell(rrind,ccind);
0120             try
0121                 [~,ind] = max( tmp(:) );
0122             catch ME
0123                 printError(ME);
0124             end
0125             
0126             [sub1, sub2] = ind2sub( pointSize, ind );
0127             ii = data.regs.regs_label(sub1-1+rmin,sub2-1+cmin);
0128             plot( sub2-1+cmin, sub1-1+rmin, 'g.' );
0129             
0130             if ii
0131                 data.regs.score(ii) = ~data.regs.score(ii);
0132             end
0133         end
0134     else
0135         selectMode = 0;
0136     end
0137 end
0138 
0139 end

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