Home > SuperSegger > frameLink > splitAreaErrors.m

splitAreaErrors

PURPOSE ^

splitAreaErrors : splits cells with large area error.

SYNOPSIS ^

function [madeChanges, data_c, data_r] = splitAreaErrors (data_c, data_r, CONST, time, verbose)

DESCRIPTION ^

 splitAreaErrors : splits cells with large area error.

 INPUT :
   data_c : current time frame data (seg/err) file.
   data_r : reverse time frame data (seg/err) file.
   CONST : segmentation parameters.
   time : frame number

 OUTPUT :
   data_c : updated current time frame data (seg/err) file.
   data_r : updated reverse time frame data (seg/err) file.
   madeChanges : boolean for whether cells were split


 Copyright (C) 2016 Wiggins Lab
 Written by Connor Brennan
 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 [madeChanges, data_c, data_r] =  splitAreaErrors (data_c, data_r, CONST, time, verbose)
0002 % splitAreaErrors : splits cells with large area error.
0003 %
0004 % INPUT :
0005 %   data_c : current time frame data (seg/err) file.
0006 %   data_r : reverse time frame data (seg/err) file.
0007 %   CONST : segmentation parameters.
0008 %   time : frame number
0009 %
0010 % OUTPUT :
0011 %   data_c : updated current time frame data (seg/err) file.
0012 %   data_r : updated reverse time frame data (seg/err) file.
0013 %   madeChanges : boolean for whether cells were split
0014 %
0015 %
0016 % Copyright (C) 2016 Wiggins Lab
0017 % Written by Connor Brennan
0018 % University of Washington, 2016
0019 % This file is part of SuperSegger.
0020 %
0021 % SuperSegger is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % SuperSegger is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 DEBUG_FLAG = 1;
0035 
0036 DA_MIN = CONST.trackOpti.DA_MIN;
0037 DA_MAX =  CONST.trackOpti.DA_MAX;
0038 
0039 madeChanges = 0;
0040 
0041 splitRegions = [];
0042 
0043 for regNum =  1 : data_c.regs.num_regs;
0044     rCellsFromC = data_c.regs.map.r{regNum}; % where regNum maps in reverse
0045     rCells = unique(data_r.regs.revmap.f{regNum});
0046     
0047     if ~isempty(rCellsFromC)
0048         cCellsFromR = unique([data_r.regs.map.f{rCellsFromC}]);
0049     else
0050         cCellsFromR = [];
0051     end
0052     
0053     rCells = unique([rCellsFromC, rCells]);
0054     cCells = unique([regNum, cCellsFromR]);
0055     
0056     data_r.regs.dA.f(rCells);
0057     data_c.regs.dA.r(cCells);
0058     
0059     if numel(rCells) > 0 && numel(cCells) > 0
0060         fromArray = repmat(rCells, [1, numel(cCells)]);
0061         toArray = repmat(cCells, [1, numel(rCells)]);
0062 
0063         deltaSize = ([data_c.regs.props(toArray).Area] - [data_r.regs.props(fromArray).Area]) ./ [data_r.regs.props(fromArray).Area];
0064         
0065         for i = find(deltaSize > DA_MAX)
0066             if ~ismember(toArray(i), splitRegions)
0067                 if (DEBUG_FLAG)
0068                     toMask = (data_c.regs.regs_label == toArray(i));
0069                     fromMask = (data_r.regs.regs_label == fromArray(i));
0070 
0071                     figure(4);
0072 
0073                     [fromX, fromY] = getBBpad(data_c.regs.props(toArray(i)).BoundingBox, size(data_c.mask_cell), 20);
0074                     [toX, toY] = getBBpad(data_r.regs.props(fromArray(i)).BoundingBox, size(data_r.mask_cell), 20);
0075 
0076                     xMax = max([toX, fromX]);
0077                     xMin = min([toX, fromX]);
0078                     yMax = max([toY, fromY]);
0079                     yMin = min([toY, fromY]);
0080 
0081                     x = xMin : xMax;
0082                     y = yMin : yMax;
0083                     
0084                     toMask = toMask(y, x) .* data_c.mask_cell(y, x);
0085                     fromMask = fromMask(y, x) .* data_r.mask_cell(y, x);
0086 
0087                     background = zeros(size(y, 2), size(x, 2));
0088                     imshow(cat(3, background + 0.5 * data_c.mask_cell(y, x) + 0.5 * toMask, background + 0.5 * toMask+ 0.5 * fromMask, background + 0.5 * data_r.mask_cell(y, x) + fromMask), []);
0089                 
0090                     figure(5);
0091                     imshow(cat(3, ag(data_c.phase(y, x)), background, ag(data_c.segs.segs_bad(y, x))), []);
0092                     %imshow(data_c.segs.segs_3n(y, x) + data_c.segs.segs_good(y, x) + data_c.segs.segs_bad(y, x))
0093                 end
0094                 
0095                 [data_c, success] = splitAtBestSeg(data_c, toArray(i), CONST);
0096                 
0097                 if success
0098                     madeChanges = 1;
0099 
0100                     disp (['Frame ', num2str(time), ' : split region ', num2str(toArray(i)), ' due to abnormal growth speed.']);
0101                 else
0102                     if verbose
0103                         disp (['Frame ', num2str(time), ' : could not find segment to split region ', num2str(toArray(i)), '.']);
0104                     end
0105                 end
0106                 
0107                 splitRegions = [splitRegions, toArray(i)];
0108             end
0109         end
0110     end
0111 end
0112

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