Home > SuperSegger > trainingConstants > killRegionsGUI.m

killRegionsGUI

PURPOSE ^

killRegionsGUI : used to remove regions from an image.

SYNOPSIS ^

function data = killRegionsGUI (data, CONST, position1, position2)

DESCRIPTION ^

 killRegionsGUI : used to remove regions from an image.

 INPUT :
       data : data file with regions (seg/err file)
       CONST : segmentation constants
 OUTPUT : 
       data : data file without the selected region

 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 = killRegionsGUI (data, CONST, position1, position2)
0002 % killRegionsGUI : used to remove regions from an image.
0003 %
0004 % INPUT :
0005 %       data : data file with regions (seg/err file)
0006 %       CONST : segmentation constants
0007 % OUTPUT :
0008 %       data : data file without the selected region
0009 %
0010 % Copyright (C) 2016 Wiggins Lab
0011 % Written by Paul Wiggins, Stella Stylianidou.
0012 % University of Washington, 2016
0013 % This file is part of SuperSegger.
0014 %
0015 % SuperSegger is free software: you can redistribute it and/or modify
0016 % it under the terms of the GNU General Public License as published by
0017 % the Free Software Foundation, either version 3 of the License, or
0018 % (at your option) any later version.
0019 %
0020 % SuperSegger is distributed in the hope that it will be useful,
0021 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0022 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0023 % GNU General Public License for more details.
0024 %
0025 % You should have received a copy of the GNU General Public License
0026 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0027 
0028 
0029 
0030 if ~isempty(position1) && isempty(position2)
0031     % get closer region
0032     ss = size(data.phase);
0033     x = round(position1);
0034     tmp_cell_mask = zeros([51,51]);
0035     tmp_cell_mask(26,26) = 1;
0036     tmp_cell_mask = 8000-double(bwdist(tmp_cell_mask));
0037 
0038     rmin = max([1,x(2)-25]);
0039     rmax = min([ss(1),x(2)+25]);
0040 
0041     cmin = max([1,x(1)-25]);
0042     cmax = min([ss(2),x(1)+25]);
0043 
0044     rrind = rmin:rmax;
0045     ccind = cmin:cmax;
0046 
0047     pointSize = [numel(rrind),numel(ccind)];
0048     tmp_cell_mask = tmp_cell_mask(26-x(2)+rrind,26-x(1)+ccind).*data.mask_cell(rrind,ccind);
0049     try
0050         [~,ind] = max( tmp_cell_mask(:) );
0051     catch ME
0052         printError(ME);
0053     end
0054 
0055     [sub1, sub2] = ind2sub( pointSize, ind );
0056     ii = data.regs.regs_label(sub1-1+rmin,sub2-1+cmin);
0057     if ii ~=0
0058         [xx,yy] = getBB( data.regs.props(ii).BoundingBox);
0059         tmp_cell_mask = (data.regs.regs_label == ii);
0060         
0061         tmp_cell_mask = imdilate(tmp_cell_mask,strel('square',2));
0062         data.segs.segs_good(tmp_cell_mask) = 0;
0063         data.segs.segs_bad(tmp_cell_mask) = 0;
0064         data.segs.segs_3n(tmp_cell_mask) = 0;
0065         data.segs.segs_label(tmp_cell_mask) = 0;
0066         data.mask_bg(tmp_cell_mask)= 0;
0067         data.mask_cell(tmp_cell_mask) = 0;
0068         
0069         data = intMakeRegs( data, CONST);
0070     end
0071     
0072 elseif ~isempty(position1) && ~isempty(position2)
0073     xy = [position1(1:2); position2(1:2)];
0074     xy = floor(xy);
0075     xmin = min(xy(:,1));
0076     xmin = max(xmin,1);
0077     xmax = max(xy(:,1));
0078     xmax = min(xmax,size(data.phase,2));
0079     ymin = min(xy(:,2));
0080     ymin = max(ymin,1);
0081     ymax = max(xy(:,2));
0082     ymax = min(ymax,size(data.phase,1));
0083     xx = xmin:xmax;
0084     yy = ymin:ymax;
0085     hold on
0086     plot( [xmin,xmax],[ymin,ymax] ,'r.');
0087     ind_segs = unique( data.segs.segs_label(yy,xx));
0088     ind_segs = ind_segs(logical(ind_segs));
0089     ind_segs = reshape(ind_segs,1,numel(ind_segs));
0090 
0091 %     if isfield( data, 'regs' );
0092 %         ind_regs = unique( data.regs.regs_label(yy,xx));
0093 %         ind_regs = ind_regs(logical(ind_regs));
0094 %         ind_regs = reshape(ind_regs,1,numel(ind_regs));
0095 %         data = rmfield(data,'regs');
0096 %     end
0097 
0098     mask = false(size(data.phase));
0099 
0100     for ii = ind_segs
0101         data.segs.info(ii,:)   = NaN;
0102         data.segs.score(ii)    = NaN;
0103         data.segs.scoreRaw(ii) = NaN;
0104         mask = logical(mask + (data.segs.segs_label==ii));
0105     end
0106     
0107     data.segs.segs_good(yy,xx)  = 0;
0108     data.segs.segs_bad(yy,xx)   = 0;
0109     data.segs.segs_3n(yy,xx)    = 0;
0110     data.segs.segs_label(yy,xx) = 0;
0111     data.mask_cell(yy,xx)       = 0;
0112     data.mask_bg(yy,xx)         = 0;
0113 
0114     data.segs.segs_good(mask)  = 0;
0115     data.segs.segs_bad(mask)   = 0;
0116     data.segs.segs_3n(mask)    = 0;
0117     data.segs.segs_label(mask) = 0;
0118     data.mask_cell(mask)       = 0;
0119     data.mask_bg(mask)         = 0;
0120     data = intMakeRegs( data, CONST);
0121 end

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