segsInfoCurv : Calculates the properties of the segments used for segment scoring. Uses the image curvature to calculate some of the properties. 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/>.
0001 function seg_info = segsInfoCurv(segs_props, segs_props_tmp, regs_prop, regs_label,disk1) 0002 % segsInfoCurv : Calculates the properties of the segments used for segment scoring. 0003 % Uses the image curvature to calculate some of the properties. 0004 % 0005 % INPUT : 0006 % segs_props : calculated segment properties 0007 % segs_props_tmp : calculated segment properties tmp 0008 % regs_prop : region properties 0009 % regs_label : region labels 0010 % disk1 : disk for dilating/eroding 0011 % OUTPUT : 0012 % seg_info : array with parameters used for segment scoring 0013 % 0014 % Copyright (C) 2016 Wiggins Lab 0015 % Written by Paul Wiggins & Stella Stylianidou. 0016 % University of Washington, 2016 0017 % This file is part of SuperSegger. 0018 % 0019 % SuperSegger is free software: you can redistribute it and/or modify 0020 % it under the terms of the GNU General Public License as published by 0021 % the Free Software Foundation, either version 3 of the License, or 0022 % (at your option) any later version. 0023 % 0024 % SuperSegger is distributed in the hope that it will be useful, 0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0027 % GNU General Public License for more details. 0028 % 0029 % You should have received a copy of the GNU General Public License 0030 % along with SuperSegger. If not, see <http://www.gnu.org/licenses/>. 0031 0032 0033 nn = segs_props.Area; 0034 sim_ii = size(segs_props_tmp.phase); 0035 % mask_ii_out are the pixels around the segment so that a second d over 0036 % the segment can be computed. 0037 if nn>2 0038 mask_ii_end = (compConn(segs_props_tmp.mask,4)==1); 0039 mask_ii_out = xor(bwmorph( xor(segs_props_tmp.mask,mask_ii_end), 'dilate' ),segs_props_tmp.mask); 0040 elseif nn == 1 0041 mask_ii_out = xor(bwmorph( segs_props_tmp.mask, 'dilate'),segs_props_tmp.mask); 0042 else 0043 mask_ii_out = imdilate( segs_props_tmp.mask, disk1)-segs_props_tmp.mask; 0044 mask_ii_out = and(mask_ii_out,(compConn(mask_ii_out,4)>0)); 0045 end 0046 0047 % seg_info(:,1) is the minimum phase intensity on the seg 0048 [seg_info(1),ind] = min(segs_props_tmp.phase(:).*double(segs_props_tmp.mask(:))+1e6*double(~segs_props_tmp.mask(:))); 0049 0050 % seg_info(:,2) is the mean phase intensity on the seg 0051 seg_info(2) = mean(segs_props_tmp.phase(segs_props_tmp.mask)); 0052 0053 % seg_info(:,3) is area of the seg 0054 seg_info(3) = nn; 0055 0056 % seg_info(:,4) is the mean second d of the phase normal to the seg 0057 seg_info(4) = mean(segs_props_tmp.phase(mask_ii_out)) - seg_info(2); 0058 0059 % next we want to do some more calculation around the minimum phase 0060 % pixel. sub1 and sub2 are the indicies in the cropped image 0061 [sub1,sub2] = ind2sub(sim_ii,ind); 0062 % sub1_ and sub2_ are the indices in the whole image. 0063 % sub1_ = sub1-1+yymin; 0064 % sub2_ = sub2-1+xxmin; 0065 0066 % calculate the local second d of the phase at the min pixel 0067 % normal to the seg and parallel to it. 0068 % min_pixel is the mask of the min pixel 0069 min_pixel = false(sim_ii); 0070 min_pixel(sub1,sub2) = true; 0071 % outline the min pixel 0072 min_pixel_out = bwmorph( min_pixel, 'dilate'); 0073 % and mask/anti-mask it 0074 ii_min_para = and(min_pixel_out,segs_props_tmp.mask); 0075 ii_min_norm = xor(min_pixel_out,ii_min_para); 0076 0077 % seg_info(:,5) is the second d of the phase normal to the seg at the 0078 % min pixel 0079 seg_info(5) = mean(segs_props_tmp.phase(ii_min_norm))-mean(segs_props_tmp.phase(ii_min_para)); 0080 0081 % seg_info(:,6) is the second d of the phase parallel to the seg at the 0082 % min pixel 0083 tmp_mask = xor(ii_min_para,min_pixel); 0084 seg_info(6) = mean(segs_props_tmp.phase(tmp_mask))-seg_info(1); 0085 0086 if isnan(seg_info(6)) 0087 disp([header,'NaN in seg_info!']); 0088 end 0089 0090 % We also wish to add information about the neighboring regions. First we 0091 % have to determine what these regions are... ie the regs_label number 0092 % By construction, each seg touches two regions. Ind_reg is the vector 0093 % of the region indexes--after we eliminate '0'. 0094 uu = segs_props_tmp.regs_label(imdilate( segs_props_tmp.mask, disk1)); 0095 ind_reg = unique(uu(logical(uu))); 0096 0097 % seg_info(:,7) and seg_info(:,8) are the min and max area of the 0098 % neighboring regions 0099 seg_info(7) = min( regs_prop(ind_reg(:)).Area); 0100 seg_info(8) = max( regs_prop(ind_reg(:)).Area); 0101 0102 % seg_info(:,9) and seg_info(:,10) are the min and max minor axis 0103 % length of the neighboring regions 0104 seg_info(9) = min( regs_prop(ind_reg(:)).MinorAxisLength); 0105 seg_info(10) = max( regs_prop(ind_reg(:)).MinorAxisLength); 0106 0107 % seg_info(:,11) and seg_info(:,12) are the min and max major axis 0108 % length of the neighboring regions 0109 seg_info(11) = min( regs_prop(ind_reg(:)).MajorAxisLength); 0110 seg_info(12) = max( regs_prop(ind_reg(:)).MajorAxisLength); 0111 0112 % seg_info(:,11), seg_info(:,12), and seg_info(:,13) are the min 0113 % and max major axis length of the segment itself, including the 0114 % square of the major axis length... which would allow a non- 0115 % linarity in the length cutoff. No evidence that this helps... 0116 % just added it because I could. 0117 seg_info(13) = segs_props.MinorAxisLength; 0118 seg_info(14) = segs_props.MajorAxisLength; 0119 seg_info(15) = segs_props.MajorAxisLength^2; 0120 0121 0122 % Next we want to do some calculation looking at the size of 0123 % the regions, normal and parallel to the direction of the 0124 % segment. This is a bit computationally expensive, but worth 0125 % it I think. 0126 0127 % Get size of the regions in local coords 0128 0129 % This function computes the principal axes of the segment 0130 % mask. e1 is aligned with the major axis and e2 with the 0131 % minor axis and com is the center of mass. 0132 [e1,e2] = makeRegionAxisFast( segs_props.Orientation ); 0133 0134 % L1 is the length of the projection of the region on the 0135 % major axis and L2 is the lenght of the projection on the 0136 % minor axis. 0137 L1 = [0 0]; 0138 L2 = [0 0]; 0139 0140 % Loop through the two regions 0141 0142 0143 for kk = 1:numel(ind_reg); 0144 % get a new cropping region for each region with 2 pix padding 0145 [xx_,yy_] = getBBpad(regs_prop(ind_reg(kk)).BoundingBox,segs_props_tmp.sim,2); 0146 0147 % mask the region of interest 0148 kk_mask = (regs_label(yy_, xx_) == ind_reg(kk)); 0149 0150 % This function computes the projections lengths on e1 and e2. 0151 [L1(kk),L2(kk)] = makeRegionSize( kk_mask,e1,e2); 0152 end 0153 0154 % seg_info(:,16) and seg_info(:,17) are the min and max Length of the 0155 % regions projected onto the major axis of the segment. 0156 seg_info(16) = max(L1); % max and min region length para to seg 0157 seg_info(17) = min(L1); 0158 % seg_info(:,16) and seg_info(:,17) are the min and max Length of the 0159 % regions projected onto the minor axis of the segment. 0160 seg_info(18) = max(L2); % max and min region length normal to seg 0161 seg_info(19) = min(L2); 0162 0163 % put in the curvatures 0164 Cmaj = e1(1).^2.*segs_props.f_xx + 2*e1(1).*e1(2).*segs_props.f_xy + e1(2).^2.*segs_props.f_yy; 0165 Cmin = e2(1).^2.*segs_props.f_xx + 2*e2(1).*e2(2).*segs_props.f_xy + e2(2).^2.*segs_props.f_yy; 0166 0167 seg_info(20) = segs_props.G; 0168 seg_info(21) = segs_props.G_; 0169 0170 seg_info(22) = Cmaj; 0171 seg_info(23) = Cmin; 0172 0173 seg_info(24) = segs_props.C1; 0174 seg_info(25) = segs_props.C2; 0175 0176 0177 end