


getInfoScores : gathers properties and predicted values to be used for
model training.
INPUT:
dirname : directory with seg files
xChoice : 'segs' or 'regs' for segments or regions
CONST : segmentation constants
OUPUT :
X : properties (info) for segments or regions
Y : boolean array with two fields for bad or good segment/region
Copyright (C) 2016 Wiggins Lab
Written by 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/>.


0001 function [X,Y] = getInfoScores (dirname, xChoice, recalcInfo, CONST) 0002 % getInfoScores : gathers properties and predicted values to be used for 0003 % model training. 0004 % 0005 % INPUT: 0006 % dirname : directory with seg files 0007 % xChoice : 'segs' or 'regs' for segments or regions 0008 % CONST : segmentation constants 0009 % OUPUT : 0010 % X : properties (info) for segments or regions 0011 % Y : boolean array with two fields for bad or good segment/region 0012 % 0013 % Copyright (C) 2016 Wiggins Lab 0014 % Written by 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 dirname = fixDir(dirname); 0033 if ~strcmp (xChoice,'segs') && ~strcmp (xChoice,'regs') 0034 disp('no x chosen, optimizing segments'); 0035 xChoice = 'segs'; 0036 end 0037 if strcmp (xChoice,'segs') 0038 contents = dir([dirname,'*_seg.mat']); 0039 else 0040 contents = dir([dirname,'*_seg*.mat']); 0041 end 0042 0043 0044 Y = []; 0045 X = []; 0046 0047 for i = 1 : numel(contents) 0048 data = load([dirname,contents(i).name]); 0049 disp(contents(i).name); 0050 if recalcInfo && exist('CONST','var') && ~isempty(CONST) 0051 disp ('recalculating'); 0052 data = calculateInfo (data,CONST,xChoice); 0053 save ([dirname,contents(i).name],'-struct','data'); 0054 end 0055 0056 if strcmp (xChoice,'segs') 0057 X = [X;data.segs.info]; 0058 Y = [Y;data.segs.score]; 0059 0060 else 0061 X = [X;data.regs.info]; 0062 Y = [Y;data.regs.score]; 0063 end 0064 0065 0066 0067 end 0068 0069 [indices] = find(~isnan(Y)); 0070 X = X(indices,:); 0071 Y = Y(indices); 0072 0073 [indices] = find(isfinite(sum(X,2))); 0074 X = X(indices,:); 0075 Y = Y(indices); 0076 0077 0078 function [data] = calculateInfo (data,CONST,xChoice) 0079 if strcmp (xChoice,'regs') 0080 oldInfo = data.regs.info; 0081 ss = size(data.mask_cell); 0082 data.regs.regs_label = bwlabel(data.mask_cell); 0083 data.regs.props = regionprops( data.regs.regs_label,'BoundingBox','Orientation','Centroid','Area'); 0084 data.regs.num_regs = max(data.regs.regs_label(:)); 0085 data.regs.info = []; 0086 0087 for ii = 1:data.regs.num_regs 0088 [xx,yy] = getBBpad( data.regs.props(ii).BoundingBox, ss, 1); 0089 mask = data.regs.regs_label(yy,xx)==ii; 0090 data.regs.info(ii,:) = CONST.regionScoreFun.props( mask, data.regs.props(ii) ); 0091 end 0092 0093 0094 0095 newInfo = data.regs.info; 0096 if isempty(newInfo) || all(size (oldInfo)~=size(newInfo)) 0097 error('size') 0098 elseif all (oldInfo~=newInfo) 0099 error('hi') 0100 end 0101 0102 elseif strcmp (xChoice,'segs') 0103 0104 data = superSeggerOpti( data, [], 0, CONST ); 0105 % disp('hack'); 0106 %ss = size(data.segs.info,1); 0107 %data.segs.info (1:ss,20:25) = 0; 0108 0109 0110 0111 end 0112 end 0113 0114 end 0115 0116