Home > SuperSegger > segmentation > calculateStateEnergy.m

calculateStateEnergy

PURPOSE ^

calculateStateEnergy : calculates the state energy for modifying segments

SYNOPSIS ^

function [regionScore,state] = calculateStateEnergy(cell_mask,vect,segs_list,data,xx,yy,CONST)

DESCRIPTION ^

 calculateStateEnergy : calculates the state energy for modifying segments
 in a mask of a region.

 INPUT :
       cell_mask : mask of regions of cells to be optimized
       vect : logical for segments that are on or off
       segs_list : list of ids of segments to be turned on and off
       data : seg data file
       xx : xx from bounding box of cell_mask
       yy : yy from bounding box of cell_mask
       CONST : segmentation constants

 OUTPUT :
       regionScore : total score for modified mask
       state : state information


 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/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [regionScore,state] = calculateStateEnergy(cell_mask,vect,segs_list,data,xx,yy,CONST)
0002 % calculateStateEnergy : calculates the state energy for modifying segments
0003 % in a mask of a region.
0004 %
0005 % INPUT :
0006 %       cell_mask : mask of regions of cells to be optimized
0007 %       vect : logical for segments that are on or off
0008 %       segs_list : list of ids of segments to be turned on and off
0009 %       data : seg data file
0010 %       xx : xx from bounding box of cell_mask
0011 %       yy : yy from bounding box of cell_mask
0012 %       CONST : segmentation constants
0013 %
0014 % OUTPUT :
0015 %       regionScore : total score for modified mask
0016 %       state : state information
0017 %
0018 %
0019 % Copyright (C) 2016 Wiggins Lab
0020 % Written by Stella Stylianidou.
0021 % University of Washington, 2016
0022 % This file is part of SuperSegger.
0023 %
0024 % SuperSegger is free software: you can redistribute it and/or modify
0025 % it under the terms of the GNU General Public License as published by
0026 % the Free Software Foundation, either version 3 of the License, or
0027 % (at your option) any later version.
0028 %
0029 % SuperSegger is distributed in the hope that it will be useful,
0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0032 % GNU General Public License for more details.
0033 %
0034 % You should have received a copy of the GNU General Public License
0035 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0036 
0037 
0038 state =  caclulateState(cell_mask,vect,segs_list,data,xx,yy,CONST);
0039 sigma = 1-2*double(state.seg_vect0);
0040 allGoodScore = double(all(state.reg_E> 0));
0041 allWidth = double(all(CONST.superSeggerOpti.MAX_WIDTH < state.short_axis_mean));
0042 regionScore = mean(-state.reg_E)+ mean(sigma.*state.seg_E) - allGoodScore * 50 - allWidth * 10;
0043 
0044 end
0045 
0046 function [state] =  caclulateState(cell_mask,vect,segs_list,data,xx,yy,CONST)
0047 % caclulateState : calculates the region scores for the modified cell mask
0048 % using the vect for the segments that will be on or off.
0049 state.seg_E = data.segs.scoreRaw(segs_list)*CONST.regionOpti.DE_norm;
0050 state.seg_vect0 = logical(vect);
0051 state.mask = cell_mask;
0052 num_segs = numel(vect);
0053 
0054 for kk = 1:num_segs
0055     state.mask = state.mask - vect(kk)*(segs_list(kk)==data.segs.segs_label(yy,xx));
0056 end
0057 
0058 state.mask = state.mask>0;
0059 
0060 regs_label_mod = (bwlabel(state.mask, 4));
0061 regs_props_mod = regionprops( regs_label_mod,'BoundingBox','Orientation','Centroid','Area');
0062 num_regs_mod = max(regs_label_mod(:));
0063 info = zeros(num_regs_mod, CONST.regionScoreFun.NUM_INFO);
0064 ss_regs_label_mod = size( regs_label_mod );
0065 
0066 for mm = 1:num_regs_mod;
0067     [xx_,yy_] = getBBpad( regs_props_mod(mm).BoundingBox, ss_regs_label_mod, 1);
0068     mask = regs_label_mod(yy_,xx_)==mm;
0069     info(mm,:) = CONST.regionScoreFun.props( mask, regs_props_mod(mm));
0070 end
0071 
0072 state.reg_E = CONST.regionScoreFun.fun(info,CONST.regionScoreFun.E);
0073 state.short_axis_mean = info(:,2);
0074 state.long_axis = info(:,1);
0075 end

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