Home > SuperSegger > segmentation > segsTLEdit.m

segsTLEdit

PURPOSE ^

segsTLEdit : used to visually modify segments in a frame.

SYNOPSIS ^

function [saved_touch_list] = segsTLEdit( dirname, frame_num, CONST )

DESCRIPTION ^

 segsTLEdit : used to visually modify segments in a frame.
 red are segments that are on, bad are the segments that are off and green
 the permanent segments. 
 Possible choices : q to quit
                    press the enter button to select a segment to modify
                    s to save the modified segments
                    g#: go to frame #
                    1, 2, 3, & 4 are different image modes
                    c  clear figure

 INPUT :
       dirname : xy/seg directory
       frame_num : initial frame number to be loaded

 OUTPUT :
       final_touch_list : frames that were modified
       

 Copyright (C) 2016 Wiggins Lab 
 Written by Paul Wiggins.
 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [saved_touch_list] = segsTLEdit( dirname, frame_num, CONST )
0002 % segsTLEdit : used to visually modify segments in a frame.
0003 % red are segments that are on, bad are the segments that are off and green
0004 % the permanent segments.
0005 % Possible choices : q to quit
0006 %                    press the enter button to select a segment to modify
0007 %                    s to save the modified segments
0008 %                    g#: go to frame #
0009 %                    1, 2, 3, & 4 are different image modes
0010 %                    c  clear figure
0011 %
0012 % INPUT :
0013 %       dirname : xy/seg directory
0014 %       frame_num : initial frame number to be loaded
0015 %
0016 % OUTPUT :
0017 %       final_touch_list : frames that were modified
0018 %
0019 %
0020 % Copyright (C) 2016 Wiggins Lab
0021 % Written by Paul Wiggins.
0022 % University of Washington, 2016
0023 % This file is part of SuperSegger.
0024 %
0025 % SuperSegger is free software: you can redistribute it and/or modify
0026 % it under the terms of the GNU General Public License as published by
0027 % the Free Software Foundation, either version 3 of the License, or
0028 % (at your option) any later version.
0029 %
0030 % SuperSegger is distributed in the hope that it will be useful,
0031 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0032 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0033 % GNU General Public License for more details.
0034 %
0035 % You should have received a copy of the GNU General Public License
0036 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0037 
0038 
0039 
0040 if ~exist('disp_flag');
0041     disp_flag = 0;
0042 end
0043 
0044 touch_list = [];
0045 saved_touch_list = [];
0046 if(nargin<1 || isempty(dirname))
0047     dirname=pwd;
0048 end
0049 dirname = fixDir(dirname);
0050 
0051 contents=dir([dirname '*_seg.mat']);
0052 num_im = length(contents);
0053 im_flag = 1;
0054 runFlag = 1;
0055 
0056 if nargin < 2
0057     i = 1;
0058 else
0059     i = frame_num;
0060 end
0061 
0062 
0063 data = loaderInternal([dirname,contents(i).name]);
0064 ss = size( data.segs.phaseMagic );
0065 
0066 while runFlag
0067     
0068     data.mask_cell   = double((data.mask_bg - data.segs.segs_good - ...
0069         data.segs.segs_3n)>0);
0070     
0071     showSegData( data,im_flag);
0072     figure(1);
0073     hold on;
0074     disp('--- Segment Editing ---');
0075     disp('q       : quit');
0076     disp('[enter] : modify');
0077     disp('s       : save' );
0078     disp('g#      : go to frame #');
0079     disp('1,2,3,4 : different image modes');
0080     disp('c       : clear the figure');
0081     disp(['Frame #: ', num2str(i)] );
0082     
0083     c = input(':','s')
0084     
0085     if isempty(c)
0086         x = floor(ginput(1));
0087         tmp = zeros(ss);
0088         if isempty(x)
0089             continue;
0090         end
0091         
0092         tmp(x(2),x(1)) = 1;
0093         tmp = 8000-double(bwdist(tmp));
0094         
0095         %imshow( tmp, [] );
0096         
0097         tmp = tmp.*(data.segs.segs_good+data.segs.segs_bad);
0098         [~,ind] = max( tmp(:) );
0099         [sub1, sub2] = ind2sub( ss, ind );
0100         ii = data.segs.segs_label(sub1,sub2);
0101         plot( sub2, sub1, 'r.' );
0102         
0103         yymin = floor(data.segs.props(ii).BoundingBox(2));
0104         yymax = yymin + floor(data.segs.props(ii).BoundingBox(4));
0105         xxmin = floor(data.segs.props(ii).BoundingBox(1));
0106         xxmax = xxmin + floor(data.segs.props(ii).BoundingBox(3));
0107         
0108         if data.segs.score(ii)
0109             data.segs.score(ii) = 0;
0110             data.segs.segs_good(yymin:yymax, xxmin:xxmax) ...
0111                 = double(~~(data.segs.segs_good(yymin:yymax, xxmin:xxmax)...
0112                 - double(data.segs.segs_label(yymin:yymax, xxmin:xxmax)==ii)));
0113             data.segs.segs_bad(yymin:yymax, xxmin:xxmax) = ...
0114                 double(~~(data.segs.segs_bad(yymin:yymax, xxmin:xxmax)...
0115                 +double(data.segs.segs_label(yymin:yymax, xxmin:xxmax)==ii)));
0116             
0117         else
0118             data.segs.score(ii) = 1;
0119             data.segs.segs_good(yymin:yymax, xxmin:xxmax) = ...
0120                 double(~~(data.segs.segs_good(yymin:yymax, xxmin:xxmax)+...
0121                 double(data.segs.segs_label(yymin:yymax, xxmin:xxmax)==ii)));
0122             data.segs.segs_bad(yymin:yymax, xxmin:xxmax) = ...
0123                 double(~~(data.segs.segs_bad(yymin:yymax, xxmin:xxmax)-...
0124                 double(data.segs.segs_label(yymin:yymax, xxmin:xxmax)==ii)));
0125         end
0126         
0127         % recalculate regions and cell mask
0128         data.mask_cell = double((data.mask_bg - data.segs.segs_good - data.segs.segs_3n)>0);
0129         data = intMakeRegs(data, CONST, [], [])
0130         touch_list = [touch_list, i];
0131         
0132     elseif c(1) == 'q' % quit
0133         
0134         runFlag = 0  ;
0135         
0136     elseif c(1) == 'g' % go to frame c(2:end)
0137         
0138         i = str2num(c(2:end));
0139         if i<1
0140             i = 1;
0141         elseif i> num_im
0142             i = num_im;
0143         end
0144         
0145         data = loaderInternal([dirname,contents(i).name]);
0146         data.mask_cell = double((data.mask_bg - data.segs.segs_good - data.segs.segs_3n)>0);
0147         
0148     elseif c == 's' % save
0149         if any(touch_list==i)
0150             saved_touch_list = unique([saved_touch_list,i]);
0151         end
0152         dataname=[dirname,contents(i).name];
0153         save(dataname,'-STRUCT','data');
0154         
0155     elseif c == '1' % image mode 1
0156         im_flag = 1;
0157         
0158     elseif c == '2'
0159         im_flag = 2;
0160         
0161     elseif c == '3'        
0162         im_flag = 3;
0163         
0164     elseif c == '4'
0165         im_flag = 4;
0166         
0167     elseif c == 'c' % clear figure
0168         clf;
0169     end
0170     
0171     
0172 end
0173 
0174 touch_list = unique(touch_list);
0175 
0176 end
0177 
0178 function data = loaderInternal( filename )
0179 
0180 data = load(filename);
0181 data.segs.segs_good = double(data.segs.segs_label>0).*double(~data.mask_cell);
0182 data.segs.segs_bad = double(data.segs.segs_label>0).*data.mask_cell;
0183 
0184 end

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