Home > SuperSegger > cell > toMakeCell.m

toMakeCell

PURPOSE ^

toMakeCell : calls toMakeCellFast to calculate the properties of a cell.

SYNOPSIS ^

function celld = toMakeCell(celld, e1_old, props)

DESCRIPTION ^

 toMakeCell : calls toMakeCellFast to calculate the properties of a cell.
 This includes center (center of mass) as well as the principle axis which
 is assumed to be the axis that diagonalizes the moment of inertia tensor.
 This gives the axis up to a sign, which is determined by aligning the
 current axis with the last axis (e1_old).

 The properties added to celld are the following :
 length : length of cell (widest/lengthest)
 coord.A: Area of cell mask
 coord.r_center: geometrical center of the cell
 coord.box: coordinated of box surrounding cell
 corrd.xaxis: coord of major axis
 coord.yaxis:coord of minor axis
 coord.e1: priniple axis (major) unit vector
 coord.e2: priniple axis (minor) unit vector
 coord.rcm: center of mass position of mask

 INPUT :
celld : Cell file
props : contains information about the cell such as bounding box, area,
and centroid
e1_old : is the last axis of the cell
 OUTPUT :
celld : new cell file with calculated properties

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function celld = toMakeCell(celld, e1_old, props)
0002 % toMakeCell : calls toMakeCellFast to calculate the properties of a cell.
0003 % This includes center (center of mass) as well as the principle axis which
0004 % is assumed to be the axis that diagonalizes the moment of inertia tensor.
0005 % This gives the axis up to a sign, which is determined by aligning the
0006 % current axis with the last axis (e1_old).
0007 %
0008 % The properties added to celld are the following :
0009 % length : length of cell (widest/lengthest)
0010 % coord.A: Area of cell mask
0011 % coord.r_center: geometrical center of the cell
0012 % coord.box: coordinated of box surrounding cell
0013 % corrd.xaxis: coord of major axis
0014 % coord.yaxis:coord of minor axis
0015 % coord.e1: priniple axis (major) unit vector
0016 % coord.e2: priniple axis (minor) unit vector
0017 % coord.rcm: center of mass position of mask
0018 %
0019 % INPUT :
0020 %celld : Cell file
0021 %props : contains information about the cell such as bounding box, area,
0022 %and centroid
0023 %e1_old : is the last axis of the cell
0024 % OUTPUT :
0025 %celld : new cell file with calculated properties
0026 %
0027 % Copyright (C) 2016 Wiggins Lab
0028 % Written by Stella Stylianidou & Paul Wiggins.
0029 % University of Washington, 2016
0030 % This file is part of SuperSegger.
0031 %
0032 % SuperSegger is free software: you can redistribute it and/or modify
0033 % it under the terms of the GNU General Public License as published by
0034 % the Free Software Foundation, either version 3 of the License, or
0035 % (at your option) any later version.
0036 %
0037 % SuperSegger is distributed in the hope that it will be useful,
0038 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0039 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
0040 % GNU General Public License for more details.
0041 %
0042 % You should have received a copy of the GNU General Public License
0043 % along with SuperSegger.If not, see <http://www.gnu.org/licenses/>.
0044 
0045 theta = (-props.Orientation)*pi/180;
0046 A = props.Area;
0047 mask= logical(celld.mask);
0048 
0049 imRot = (fast_rotate_loose_double(uint8(mask), -props.Orientation));
0050 imRot = double(imRot);
0051 ss = size(imRot);
0052 ss_mask = size(mask);
0053 
0054 xind = any(imRot);
0055 yind = any(imRot');
0056 
0057 % the sum of non zeros in the mask along the y and x axis
0058 % widest and longest part of the cell
0059 len = [sum(double(xind)),sum(double(yind))];
0060 
0061 xxx = (1:ss(2));
0062 yyy = (1:ss(1));
0063 
0064 % major and minor axis
0065 e1= [ cos(theta); sin(theta)];
0066 e2= [-sin(theta); cos(theta)];
0067 Mrot = [e1,e2];
0068 
0069 % cell centroid
0070 r_center = Mrot*([mean(xxx(xind)),mean(yyy(yind))]'-(ss(2:-1:1))'/2)+...
0071  (ss_mask(2:-1:1)/2+celld.r_offset-[0.5,0.5])';
0072 
0073 % center of mass for cell
0074 Xcm = props.Centroid(1);
0075 Ycm = props.Centroid(2);
0076 rcm = [Xcm,Ycm];
0077 
0078 if ~isempty( e1_old );
0079  if sum(e1.*e1_old) < 0
0080 e1 = -e1;
0081  end
0082 end
0083 
0084 if sum(e1(1)*e2(2)-e1(2)*e2(1)) < 0
0085  e2 = -e2;
0086 end
0087 
0088 
0089 % box around the cell
0090 xbox = ...
0091  [e1(1)*len(1)+e2(1)*len(2),...
0092  -e1(1)*len(1)+e2(1)*len(2),...
0093  -e1(1)*len(1)-e2(1)*len(2),...
0094  e1(1)*len(1)-e2(1)*len(2),...
0095  e1(1)*len(1)+e2(1)*len(2)]/2 + r_center(1);
0096 
0097 ybox = ...
0098  [ e1(2)*len(1)+e2(2)*len(2),...
0099  -e1(2)*len(1)+e2(2)*len(2),...
0100  -e1(2)*len(1)-e2(2)*len(2),...
0101  e1(2)*len(1)-e2(2)*len(2),...
0102  e1(2)*len(1)+e2(2)*len(2)]/2 + r_center(2);
0103 
0104 % half axes inside the cell along the major and minor principal axes
0105 xaxisx = [e1(1)*len(1),-e1(1)*len(1)]/2 + r_center(1);
0106 xaxisy = [e1(2)*len(1),-e1(2)*len(1)]/2 + r_center(2);
0107 yaxisx = [e2(1)*len(2),-e2(1)*len(2)]/2 + r_center(1);
0108 yaxisy = [e2(2)*len(2),-e2(2)*len(2)]/2 + r_center(2);
0109 
0110 
0111 % copy all the info into the cell structure.
0112 celld.coord.orientation = -props.Orientation;
0113 celld.length = len;
0114 celld.coord.A = A;
0115 celld.coord.r_center = r_center;
0116 celld.coord.box = [xbox',ybox'];
0117 celld.coord.xaxis = [xaxisx',xaxisy'];
0118 celld.coord.yaxis = [yaxisx',yaxisy'];
0119 celld.coord.e1= e1;
0120 celld.coord.e2= e2;
0121 celld.coord.rcm = rcm;
0122 celld.pole.e1= e1;
0123 celld.pole.op_ori = 0;
0124 celld.pole.op_age = NaN;
0125 celld.pole.np_age = NaN;
0126 
0127 % Debugging info.
0128 debug_flag = 0;
0129 
0130 if debug_flag;
0131  
0132  im_size= size(mask);
0133  im_size_x = im_size(2);
0134  im_size_y = im_size(1);
0135  
0136  xx = 1:im_size_x;
0137  yy = 1:im_size_y;
0138  
0139  % add the offset
0140  % xxx and yyy are used to plot the mask at the correct global x and y
0141  xxx = xx + celld.r_offset(1)-1;
0142  yyy = yy + celld.r_offset(2)-1;
0143  
0144  % length and width along e1 and e2
0145  xaxisxp = [e1(1)*len(1),0]/2 + r_center(1);
0146  xaxisyp = [e1(2)*len(1),0]/2 + r_center(2);
0147  yaxisxp = [e2(1)*len(2),0]/2 + r_center(1);
0148  yaxisyp = [e2(2)*len(2),0]/2 + r_center(2);
0149  
0150  clf;
0151  imagesc(xxx, yyy, ag(mask));
0152  axis equal
0153  
0154  colormap gray
0155  hold on;
0156  plot(celld.coord.rcm(1), celld.coord.rcm(2), 'c.'); % center of mass
0157  plot(celld.coord.r_center(1), celld.coord.r_center(2), 'c*'); % centroid
0158  plot(celld.coord.xaxis(:,1),celld.coord.xaxis(:,2),'r:') % along e1
0159  plot(celld.coord.yaxis(:,1),celld.coord.yaxis(:,2),'r:') % along e2
0160  plot(xaxisxp, xaxisyp,'r-') % other half of e1
0161  plot(yaxisxp, yaxisyp,'r-') % other half of e2
0162  plot(celld.r_offset(1), celld.r_offset(2),'co') % offset
0163  plot(celld.coord.box(:,1), celld.coord.box(:,2),'c-') % box around the cell
0164 end
0165 
0166 
0167 end
0168

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