systematic: Finds the minimum energy configuration by trying all segment combinations. INPUT : segs_list : list of ids of segments to be turned on and off data : seg data file cell_mask : mask of regions of cells to be optimized xx : xx from bounding box of cell_mask yy : yy from bounding box of cell_mask CONST : segmentation constants OUTPUT : minVect : vector of segments to be on for minimum energy found. regEmin : energy of every region for the minimum state Copyright (C) 2016 Wiggins Lab Written by Stella Stylianidou, 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/>.
0001 function [minVect,regEmin] = systematic( segs_list, data, cell_mask, xx, yy, CONST) 0002 % systematic: Finds the minimum energy configuration by trying all segment 0003 % combinations. 0004 % 0005 % INPUT : 0006 % segs_list : list of ids of segments to be turned on and off 0007 % data : seg data file 0008 % cell_mask : mask of regions of cells to be optimized 0009 % xx : xx from bounding box of cell_mask 0010 % yy : yy from bounding box of cell_mask 0011 % CONST : segmentation constants 0012 % 0013 % OUTPUT : 0014 % minVect : vector of segments to be on for minimum energy found. 0015 % regEmin : energy of every region for the minimum state 0016 % 0017 % 0018 % Copyright (C) 2016 Wiggins Lab 0019 % Written by Stella Stylianidou, Paul Wiggins. 0020 % University of Washington, 2016 0021 % This file is part of SuperSegger. 0022 % 0023 % SuperSegger is free software: you can redistribute it and/or modify 0024 % it under the terms of the GNU General Public License as published by 0025 % the Free Software Foundation, either version 3 of the License, or 0026 % (at your option) any later version. 0027 % 0028 % SuperSegger is distributed in the hope that it will be useful, 0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0031 % GNU General Public License for more details. 0032 % 0033 % You should have received a copy of the GNU General Public License 0034 % along with SuperSegger. If not, see <http://www.gnu.org/licenses/>. 0035 0036 debug_flag = 0; 0037 0038 num_segs = numel(segs_list); 0039 num_comb = 2^num_segs; 0040 state = cell( 1, num_comb ); 0041 regionScore = zeros( 1, num_comb ); 0042 0043 for jj = 1:num_comb; 0044 0045 % goes through all combinations and turns on segments 0046 vect = makeVector(jj-1,num_segs)'; 0047 0048 % calculates state energy 0049 [regionScore(jj),state{jj}] = calculateStateEnergy(cell_mask,vect,segs_list,data,xx,yy,CONST); 0050 0051 end 0052 0053 % get the minimum score 0054 [Emin, jj_min] = min(regionScore); 0055 minVect = makeVector(jj_min-1,num_segs)'; 0056 minState = state{jj_min}; 0057 regEmin = minState.reg_E; 0058 0059 if debug_flag 0060 % shows the minimum score found from systematic 0061 cell_mask_mod = cell_mask; 0062 for kk = 1:num_segs 0063 cell_mask_mod = cell_mask_mod - minVect(kk)*(segs_list(kk)==data.segs.segs_label(yy,xx)); 0064 end 0065 figure(1); 0066 clf; 0067 imshow( cat(3,ag(cell_mask),... 0068 ag(cell_mask_mod),... 0069 0*ag(cell_mask)),'InitialMagnification','fit'); 0070 disp(['Total Region Score : ',num2str(Emin)]); 0071 end 0072 0073 end 0074 0075 function vect = makeVector( nn, n ) 0076 vect = zeros(1,n); 0077 for i=n-1:-1:0; 0078 vect(i+1) = floor(nn/2^i); 0079 nn = nn - vect(i+1)*2^i; 0080 end 0081 end