Home > cellorganizer > utilities > model2framework.m

model2framework

PURPOSE ^

MODEL2FRAMEWORK Helper method that generates a 2D/3D framework from a

SYNOPSIS ^

function [ nucimg, cellimg, outres ] = model2framework( model, param )

DESCRIPTION ^

MODEL2FRAMEWORK Helper method that generates a 2D/3D framework from a
valid SLML model. The models that are currently supported are
 (1) 2D spline model of the nucleus + 2D ratio model of the cell membrane
 (2) 3D spline model of the nucleus + 3D ratio model of the cell membrane
 (3) 3D diffeomorphic model of the nucleus and cell membrane

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ nucimg, cellimg, outres ] = model2framework( model, param )
0002 %MODEL2FRAMEWORK Helper method that generates a 2D/3D framework from a
0003 %valid SLML model. The models that are currently supported are
0004 % (1) 2D spline model of the nucleus + 2D ratio model of the cell membrane
0005 % (2) 3D spline model of the nucleus + 3D ratio model of the cell membrane
0006 % (3) 3D diffeomorphic model of the nucleus and cell membrane
0007 
0008 % Author: Ivan E. Cao-Berg (icaoberg@cs.cmu.edu)
0009 %
0010 % Copyright (C) 2012-2013 Murphy Lab
0011 % Lane Center for Computational Biology
0012 % School of Computer Science
0013 % Carnegie Mellon University
0014 %
0015 % April 7, 2012 R.F. Murphy Use modified function for synthesizing cell
0016 % shape; adding additional models for height ratios and nuclear position
0017 % September 28, 2012 I. Cao-Berg Added documentation and checking of input
0018 % arguments
0019 % October 1, 2012 I. Cao-Berg Added diffeomorphic model structure so that
0020 % the method knows what to do when a model of this type is added. I also
0021 % added a default value so that if the model type is not recognized, the
0022 % method returns empty nuclear and cell images
0023 % October 1, 2012 I. Cao-Berg Added helper method that synthesizes an
0024 % instance from a diffeomorphic model
0025 % November 1, 2012 I. Cao-Berg Added option to parameter structure that allows
0026 % the selection between two methods when synthesizing instances from diffeomorphic
0027 % models. This option is meant for testing, and it is not documented in top
0028 % level methods
0029 % November 5, 2012 I. Cao-Berg Fixed bug in method that synthesizes images from
0030 % diffeomorphic models that was returning an empty image due to wrong index
0031 % November 6, 2012 I. Cao-Berg Updated synthesis code to use Euler integrator
0032 % January 20, 2013 T. Buck Updated method to match new options from newly
0033 % trained diffeomorphic model
0034 % February 4, 2013 D. Sullivan made file return a resolution associated
0035 % with the cell and nuclear shapes. If there is none specified, prints a
0036 % warning and returns the outres field as blank.
0037 % February 22, 2013 D. Sullivan made the nuclear shape synthesis dependent
0038 %                               on the object model resolution
0039 % February 24, 2013 D. Sullivan Moved resolution checks to model2img
0040 % March 3, 2013 D. Sullivan Added resolution outres to the 2D synthesis
0041 % March 5, 2013 D. Sullivan Added check for an existing framework
0042 % May 18, 2013 I. Cao-Berg Updated method so if framework fails to
0043 % synthesize it returns an empty framework
0044 % July 1, 2013 I. Cao-Berg Updated method so that when parameter.resolution
0045 % is not present, it will inherit the resolution of the model. This will
0046 % only happen in the 2D case where images are not downsampled
0047 %
0048 % April 7, 2012 R.F. Murphy Use modified function for synthesizing cell
0049 % shape; adding additional models for height ratios and nuclear position
0050 % June 25, 2013 R.F. Murphy Added param.spherical_cell
0051 % This program is free software; you can redistribute it and/or modify
0052 % it under the terms of the GNU General Public License as published
0053 % by the Free Software Foundation; either version 2 of the License,
0054 % or (at your option) any later version.
0055 %
0056 % This program is distributed in the hope that it will be useful, but
0057 % WITHOUT ANY WARRANTY; without even the implied warranty of
0058 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0059 % General Public License for more details.
0060 %
0061 % You should have received a copy of the GNU General Public License
0062 % along with this program; if not, write to the Free Software
0063 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0064 % 02110-1301, USA.
0065 %
0066 % For additional information visit http://murphylab.web.cmu.edu or
0067 % send email to murphy@cmu.edu
0068 
0069 
0070 if nargin > 2
0071     error('Wrong number of input arguments.' );
0072 end
0073 
0074 %icaoberg 7/1/2013
0075 if length(model) > 1 || ( isa( model, 'cell' ) && length(model) == 1 )
0076     %icaoberg 9/28/2012
0077     warning(['More than one model has been found. Synthesizing framework ' ...
0078         ' from the first model in the cell array']);
0079     model = model{1};
0080 end
0081 
0082 if ~exist( 'param', 'var' )
0083     param = [];
0084 end
0085 
0086 %icaoberg 10/1/2012
0087 param = ml_initparam( param, struct( 'debug', false ) );
0088 param = ml_initparam( param, struct( 'display', false ) );
0089 param = ml_initparam( param, struct( 'verbose', false ) );
0090 
0091 %yajing 7/2/2013 Added field spherical_cell from bob's update
0092 param = ml_initparam( param, struct( 'spherical_cell', false ) );
0093 try
0094     dimensionality = model.dimensionality;
0095 catch
0096     %icaoberg 9/28/2012
0097     disp( 'Unable to set dimensionality. Exiting method' );
0098     nucimg = [];
0099     cellimg = [];
0100     outres = [];
0101     return
0102 end
0103 
0104 %icaoberg 7/1/2013
0105 if ~isfield( param, 'synthesis' ) && ...
0106         ( ~strcmpi( param.synthesis, 'all' ) || ...
0107         ~strcmpi( param.synthesis, 'framework' ) || ...
0108         ~strcmpi( param.synthesis, 'nucleus' ) )
0109     disp( 'Unrecognized synthesis flag. Setting to default value' );
0110     param.synthesis = 'all';
0111 end
0112 
0113 switch lower(dimensionality)
0114     case '2d'
0115         %generate 2D framework
0116         %D. Sullivan 4/29/13 Removed this param init since it is done
0117         %immediately before call in model2img.m
0118         %         param = ml_initparam(param, ...
0119         %             struct('imageSize',[1024 1024],'gentex',0,'loc','all','spherical_cell',false));
0120         %
0121         %generate cell framework
0122         %yajing 7/2/2013 Added spherical_cell case from bob's update
0123         if param.spherical_cell
0124             [nucimg,cellimg] = rm_gencellcomp2D_circle( model, param);
0125         else
0126             [nucimg,cellimg] = ml_gencellcomp2D( model, param );
0127         end
0128         %icaobeg 5/18/2013
0129         %make sure the nuclear edge is not empty
0130         %the nuclear edge can never be empty
0131         if isempty( nucimg ) && isempty( cellimg )
0132             disp( 'Nuclear image is empty. Returning empty framework.' );
0133             outres = [];
0134             return
0135         end
0136         
0137         if strcmpi( param.synthesis, 'framework' ) || ...
0138                 strcmpi( param.synthesis, 'all' )
0139             
0140             if isempty( cellimg )
0141                 disp( 'Cell image is empty. Returning empty framework.' );
0142                 nucimg = [];
0143                 cellimg = [];
0144                 return
0145             else
0146                 box = tp_imbox(cellimg);
0147                 nucimg = nucimg(box(1):box(2),box(3):box(4),:);
0148                 cellimg = cellimg(box(1):box(2),box(3):box(4),:);
0149             end
0150         else
0151             if isempty( nucimg )
0152                 disp( 'Nuclear image is empty. Returning empty framework.' );
0153                 nucimg = [];
0154                 cellimg = [];
0155             else
0156                 box = tp_imbox(nucimg);
0157                 nucimg = nucimg(box(1):box(2),box(3):box(4),:);
0158             end
0159         end
0160         
0161         %D. Sullivan 3/3/12
0162         %Set the output resolution
0163         if isfield( param,'resolution' )
0164             if isfield( param.resolution,'objects' )
0165                 outres = param.resolution.objects;
0166             end
0167             outres = param.resolution;
0168         else
0169             %icaoberg 7/1/2013
0170             disp( 'Generated framework from 2D models are not downsampled. Inheriting resolution from model.' );
0171             outres = model.nuclearShapeModel.resolution;
0172         end
0173     case '3d'
0174         %D. Sullivan 3/5/13
0175         %check if we already have a framework (as in from raw data)
0176         
0177         if isfield( param, 'instance' ) && isfield(param.instance,'nucleus')
0178             if isfield(param.instance,'cell')
0179                 %check if the images are the same size in all dimensions
0180                 if all(size(param.instance.cell)==size(param.instance.nucleus))
0181                     nucimg = param.instance.nucleus;
0182                     cellimg = param.instance.cell;
0183                     if isfield(param,'resolution')
0184                         if isfield(param.resolution,'cell')
0185                             outres = param.resolution.cell;
0186                             
0187                         end
0188                     else
0189                         outres = [];
0190                     end
0191                     return
0192                     
0193                 end
0194                 if debug
0195                     warning('Cell and nucleus found, but the images were not the same size, synthesizing new framework');
0196                 end
0197             end
0198         end
0199         
0200         if strcmpi( param.synthesis, 'nucleus' ) && strcmpi( model.nuclearShapeModel.type, 'medial axis' )
0201             %generate 3D framework
0202             model.nuclearShapeModel.height.stat.mu = model.nuclearShapeModel.height.stat.mu;
0203             model.nuclearShapeModel.height.stat.sigma = model.nuclearShapeModel.height.stat.sigma;
0204             
0205             %icaoberg 8/7/2013
0206             %resolution is always needed
0207             param.resolution.nucleus = model.nuclearShapeModel.resolution;
0208             
0209             %D. Sullivan 2/22/13 added param structure to pass the cell and
0210             %object resolutions
0211             instance = tp_genspsurf(model.nuclearShapeModel,param);
0212             %instance = tp_genspsurf(model.nuclearShapeModel);
0213             
0214             %disp('Generating nuclear shape instance');
0215             %Yajing Tang 7/2/2013 Added spherical_cell case from Bob's update
0216             [nucimg,nucsurf,outres] = tp_gennucshape(instance,param);
0217             
0218             nucleus.nucimgsize = size(nucimg);
0219             nucleus.nucsurf = nucsurf;
0220             nucleus.nucimg = nucimg;
0221             
0222             box = tp_imbox(nucimg);
0223             nucimg = nucimg(box(1):box(2),box(3):box(4),:);
0224             cellimg = [];
0225         
0226         elseif ( strcmpi( param.synthesis, 'framework' ) || ...
0227                 strcmpi( param.synthesis, 'all' ) ) && strcmpi( model.nuclearShapeModel.type, 'medial axis' ) && ...
0228                 strcmpi( model.cellShapeModel.type, 'ratio' )
0229             
0230             %generate 3D framework
0231             model.nuclearShapeModel.height.stat.mu = model.nuclearShapeModel.height.stat.mu;
0232             model.nuclearShapeModel.height.stat.sigma = model.nuclearShapeModel.height.stat.sigma;
0233             
0234             %D. Sullivan 2/22/13 added param structure to pass the cell and
0235             %object resolutions
0236             instance = tp_genspsurf(model.nuclearShapeModel,param);
0237             %instance = tp_genspsurf(model.nuclearShapeModel);
0238             
0239             %disp('Generating nuclear shape instance');
0240             %Yajing Tang 7/2/2013 Added spherical_cell case from Bob's update
0241             if param.spherical_cell
0242                 % this doesn't work yet
0243                 [nucimg,nucsurf] = rm_gensphere([1024*1.25, 1024*1.25, 5*instance.height],[0.33, 0.33, 0.33]);
0244             else
0245                 [nucimg,nucsurf,outres] = tp_gennucshape(instance,param);
0246             end
0247             
0248             nucleus.nucimgsize = size(nucimg);
0249             nucleus.nucsurf = nucsurf;
0250             nucleus.nucimg = nucimg;
0251             
0252             %disp('Generating cell shape instance');
0253             %Yajing Tang 7/2/2013 Added spherical_cell case from Bob's update
0254             if param.spherical_cell
0255                 [cellimg,cellsurf] = rm_gensphere(1.0);
0256             else
0257                 [cellimg,nucimg] = ml_gencellshape3d( ...
0258                     model.cellShapeModel, nucleus,param );
0259             end
0260             
0261             
0262             box = tp_imbox(cellimg);
0263             nucimg = nucimg(box(1):box(2),box(3):box(4),:);
0264             cellimg = cellimg(box(1):box(2),box(3):box(4),:);
0265             
0266         elseif strcmpi( model.nuclearShapeModel.type, 'diffeomorphic' ) && ...
0267                 strcmpi( model.cellShapeModel.type, 'diffeomorphic' )
0268             %icaoberg 10/1/2012
0269             outres = param.resolution.cell;
0270             [nucimg, cellimg] = model2diffeomorphicInstance( model, param );
0271         else
0272             %icaoberg 10/1/2012
0273             warning( 'CellOrganizer: Unrecognized model type or combination of model types.' );
0274             nucimg = [];
0275             cellimg = [];
0276         end
0277     otherwise
0278         return
0279 end
0280 end

Generated on Sun 29-Sep-2013 18:44:06 by m2html © 2005