Home > SuperSegger > segmentation > segInfoL2.m

segInfoL2

PURPOSE ^

segInfoL2 : Calculates the properties of the segments used for segment scoring.

SYNOPSIS ^

function seg_info = segInfoL2(segs_props, segs_props_tmp, regs_prop, regs_label,disk1)

DESCRIPTION ^

 segInfoL2 : Calculates the properties of the segments used for segment scoring.

 INPUT :
   segs_props : calculated segment properties
   segs_props_tmp : calculated segment properties tmp
   regs_prop : region properties
   regs_label : region labels
   disk1 : disk for dilating/eroding
 OUTPUT :
   seg_info : array with parameters used for segment scoring

 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 seg_info = segInfoL2(segs_props, segs_props_tmp, regs_prop, regs_label,disk1)
0002 % segInfoL2 : Calculates the properties of the segments used for segment scoring.
0003 %
0004 % INPUT :
0005 %   segs_props : calculated segment properties
0006 %   segs_props_tmp : calculated segment properties tmp
0007 %   regs_prop : region properties
0008 %   regs_label : region labels
0009 %   disk1 : disk for dilating/eroding
0010 % OUTPUT :
0011 %   seg_info : array with parameters used for segment scoring
0012 %
0013 % Copyright (C) 2016 Wiggins Lab
0014 % Written by Paul Wiggins & 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 nn = segs_props.Area;
0033 sim_ii = size(segs_props_tmp.phaseC2);
0034 % mask_ii_out are the pixels around the segment so that a second d over
0035 % the segment can be computed.
0036 if nn>2
0037     mask_ii_end  = (compConn(segs_props_tmp.mask,4)==1);
0038     mask_ii_out  = xor(bwmorph( xor(segs_props_tmp.mask,mask_ii_end), 'dilate' ),segs_props_tmp.mask);
0039 elseif nn == 1
0040     mask_ii_out  = xor(bwmorph( segs_props_tmp.mask, 'dilate'),segs_props_tmp.mask);
0041 else
0042     mask_ii_out  = imdilate( segs_props_tmp.mask, disk1)-segs_props_tmp.mask;
0043     mask_ii_out  = and(mask_ii_out,(compConn(mask_ii_out,4)>0));
0044 end
0045 
0046 % seg_info(:,1) is the minimum phase intensity on the seg
0047 [seg_info(1),ind] = min(segs_props_tmp.phaseC2(:).*double(segs_props_tmp.mask(:))+1e6*double(~segs_props_tmp.mask(:)));
0048 
0049 % seg_info(:,2) is the mean phase intensity on the seg
0050 seg_info(2) = mean(segs_props_tmp.phaseC2(segs_props_tmp.mask));
0051 
0052 % seg_info(:,3) is area of the seg
0053 seg_info(3) = nn;
0054 
0055 % seg_info(:,4) is the mean second d of the phase normal to the seg
0056 seg_info(4) = mean(segs_props_tmp.phaseC2(mask_ii_out)) - seg_info(2);
0057 
0058 % next we want to do some more calculation around the minimum phase
0059 % pixel. sub1 and sub2 are the indicies in the cropped image
0060 [sub1,sub2] = ind2sub(sim_ii,ind);
0061 % sub1_ and sub2_ are the indices in the whole image.
0062 %     sub1_ = sub1-1+yymin;
0063 %     sub2_ = sub2-1+xxmin;
0064 
0065 % calculate the local second d of the phase at the min pixel
0066 % normal to the seg and parallel to it.
0067 % min_pixel is the mask of the min pixel
0068 min_pixel = false(sim_ii);
0069 min_pixel(sub1,sub2) = true;
0070 % outline the min pixel
0071 min_pixel_out = bwmorph( min_pixel, 'dilate');
0072 % and mask/anti-mask it
0073 ii_min_para   = and(min_pixel_out,segs_props_tmp.mask);
0074 ii_min_norm   = xor(min_pixel_out,ii_min_para);
0075 
0076 % seg_info(:,5) is the second d of the phase normal to the seg at the
0077 % min pixel
0078 seg_info(5) = mean(segs_props_tmp.phaseC2(ii_min_norm))-mean(segs_props_tmp.phaseC2(ii_min_para));
0079 
0080 % seg_info(:,6) is the second d of the phase parallel to the seg at the
0081 % min pixel
0082 tmp_mask = xor(ii_min_para,min_pixel);
0083 seg_info(6) = mean(segs_props_tmp.phaseC2(tmp_mask))-seg_info(1);
0084 
0085 if isnan(seg_info(6))
0086     disp([header,'NaN in seg_info!']);
0087 end
0088 
0089 % We also wish to add information about the neighboring regions. First we
0090 % have to determine what these regions are... ie the regs_label number
0091 % By construction, each seg touches two regions. Ind_reg is the vector
0092 % of the region indexes--after we eliminate '0'.
0093 uu = segs_props_tmp.regs_label(imdilate( segs_props_tmp.mask, disk1));
0094 ind_reg = unique(uu(logical(uu)));
0095 
0096 % seg_info(:,7) and seg_info(:,8) are the min and max area of the
0097 % neighboring regions
0098 seg_info(7)  = min( regs_prop(ind_reg(:)).Area);
0099 seg_info(8)  = max( regs_prop(ind_reg(:)).Area);
0100 
0101 % seg_info(:,9) and seg_info(:,10) are the min and max minor axis
0102 % length of the neighboring regions
0103 seg_info(9)  = min( regs_prop(ind_reg(:)).MinorAxisLength);
0104 seg_info(10) = max( regs_prop(ind_reg(:)).MinorAxisLength);
0105 
0106 % seg_info(:,11) and seg_info(:,12) are the min and max major axis
0107 % length of the neighboring regions
0108 seg_info(11) = min( regs_prop(ind_reg(:)).MajorAxisLength);
0109 seg_info(12) = max( regs_prop(ind_reg(:)).MajorAxisLength);
0110 
0111 % seg_info(:,11), seg_info(:,12), and seg_info(:,13) are the min
0112 % and max major axis length of the segment itself, including the
0113 % square of the major axis length... which would allow a non-
0114 % linarity in the length cutoff. No evidence that this helps...
0115 % just added it because I could.
0116 seg_info(13) = segs_props.MinorAxisLength;
0117 seg_info(14) = segs_props.MajorAxisLength;
0118 seg_info(15) = segs_props.MajorAxisLength^2;
0119 
0120 
0121 % Next we want to do some calculation looking at the size of
0122 % the regions, normal and parallel to the direction of the
0123 % segment. This is a bit computationally expensive, but worth
0124 % it I think.
0125 
0126 % Get size of the regions in local coords
0127 
0128 % This function computes the principal axes of the segment
0129 % mask. e1 is aligned with the major axis and e2 with the
0130 % minor axis and com is the center of mass.
0131 [e1,e2] = makeRegionAxisFast( segs_props.Orientation );
0132 
0133 % L1 is the length of the projection of the region on the
0134 % major axis and L2 is the lenght of the projection on the
0135 % minor axis.
0136 L1 = [0 0];
0137 L2 = [0 0];
0138 
0139 % Loop through the two regions
0140 
0141 
0142 for kk = 1:numel(ind_reg);
0143     % get a new cropping region for each region with 2 pix padding
0144     [xx_,yy_] = getBBpad(regs_prop(ind_reg(kk)).BoundingBox,segs_props_tmp.sim,2);
0145     
0146     % mask the region of interest
0147     kk_mask = (regs_label(yy_, xx_) == ind_reg(kk));
0148     
0149     % This function computes the projections lengths on e1 and e2.
0150     [L1(kk),L2(kk)] = makeRegionSize( kk_mask,e1,e2);
0151 end
0152 
0153 % seg_info(:,16) and seg_info(:,17) are the min and max Length of the
0154 % regions projected onto the major axis of the segment.
0155 seg_info(16) = max(L1); % max and min region length para to seg
0156 seg_info(17) = min(L1);
0157 % seg_info(:,16) and seg_info(:,17) are the min and max Length of the
0158 % regions projected onto the minor axis of the segment.
0159 seg_info(18) = max(L2); % max and min region length normal to seg
0160 seg_info(19) = min(L2);
0161 
0162 end

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