Home > cellorganizer > slml2img.m

slml2img

PURPOSE ^

SLML2IMG Synthesizes an instance from a collection

SYNOPSIS ^

function answer = slml2img( varargin )

DESCRIPTION ^

 SLML2IMG Synthesizes an instance from a collection
 of SLML Level 1.0 Version 1.* models.
 instances may be saved in the following forms:
 Tiff stacks = a 3D tiff image stack for each pattern generated using the input models
 indexed images = a single 3D tiff image stack where each pattern is represented by a number 1-n
 object mesh = a .obj mesh file for each pattern generated using the input models (blenderfile option)
 SBML-Spatial file = a systems biology markup language(SBML) formatted xml file utilizing the spatial extension in level 3 version 1


 COMMENT: When the method is not deployed the shape of the input arguments is
 slml2img( models, param )

 List Of Input Arguments  Descriptions
 -----------------------  ------------
 models                   A cell array of filenames
 param                    A structure holding the function options

 The shape of param is described

 List Of Parameters        Descriptions
 ------------------        ------------
 targetDirectory           (optional) Directory where the images are going to be saved. Default is current directory.
 prefix                    (optional) Filename prefix for the synthesized images. Default is 'demo'
 numberOfSynthesizedImages (optional) Number of synthesized images. Default is 1.
 compression               (optional) Compression of tiff, i.e. 'none', 'lzw' and 'packbits'
 debug                     (optional) Keeps temporary results and catches errors with full reports
 display                   (optional) Display flag for figures
 verbose                   (optional) Print the intermediate steps to screen. Default is true.
 microscope                (optional) Microscope model from which we select a point spread function. Default is 'none'
 synthesis                 (optional) Synthesis parameter that allows to
                                      synthesize 'nucleus', 'framework' or 'all'. Default is 'all'
 protein.cytonuclearflag   (optional) Defines the allowable region for protein placement.
                                      The default is the cytonuclearflag included in the model.
 sampling.method           (optional) Can be 'disc' or 'sampled'. Default is trimmed
 savePDF                   (optional) Saves the probability density function for a given pattern during 2D synthesis. Default is False.
 spherical_cell            (optional) Boolean flag that indicates whether a cell is spherical. Default is False.
 synthesis.diffeomorphic.maximum_iterations (optional) Integer defining the maximum number of iterations during diffeo inference. Default is 100.
 randomwalk                (optional) Boolean flag of whether to perform a shape space walk. Default is False.
 framefolder               (optional) The folder in which to look for completed frames and save finished frames from the diffeomorphic synthesis.
                                      The default is './frames/'.
 walksteps                 (optional) The integer number of steps to walk during a shape space walk. Default is 1.
 walk_type                 (optional) Type of random walk to perform. Default is 'willmore'.
 overlapsubsize            (optional) Defines the downsampling fraction to perform during object overlap avoidance. Default is 0.3.
 overlapthresh             (optional) Defines the amount of overlap that is allowed between objects. Default is 1.
 rendAtStd                 (optional) Defines the number of standard deviations to render gaussian objects at. Default is 2.
 sampling.method.density   (optional) An integer. Default is empty.
 protein.cytonuclearflag   (optional) Can 'cyto', 'nucleus' or 'all'. Default is all.
 resolution.cell           (optional) The resolution of the cell and nucleus that are being passed in
 resolution.objects        (optional) The resolution of the object model being synthesized
 instance.cell             (optional) A binary cell image to be filled with objects. Default is empty.
 instance.nucleus          (optional) A binary nuclear image to be filled with objects. Default is empty.
 image_size                (optional) The image size. Default is [1024 1024] for both 2D and 3D in x and y
 spherical_cell            (optional) Indicates whether the cell is spherical or not. Default is FALSE

 output.tifimages           (optional) boolean flag specifying whether to write out tif images
 output.indexedimage        (optional) boolean flag specifying whether to write out indexed image
 output.blenderfile         (optional) boolean flag specifying whether to write out (.obj) files for use in blender
 output.blender.downsample  (optional) downsampling fraction for the creation of object files (1 means no downsampling, 1/5 means 1/5 the size)
 output.SBML                (optional) boolean flag specifying whether to write out (.xml) files with SBML-Spatial representations of geometries

 Example
 -------
 instances = { 'model01.xml', 'model02.mat', 'model03.mat' };
 param.targetDirectory = pwd;
 param.prefix = 'demo'
 param.numberOfSynthesizedImages = 100;
 param.compression = 'lzw';
 param.microscope = 'svi';
 param.verbose = true;

 >> slml2img( instances, param );

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function answer = slml2img( varargin )
0002 % SLML2IMG Synthesizes an instance from a collection
0003 % of SLML Level 1.0 Version 1.* models.
0004 % instances may be saved in the following forms:
0005 % Tiff stacks = a 3D tiff image stack for each pattern generated using the input models
0006 % indexed images = a single 3D tiff image stack where each pattern is represented by a number 1-n
0007 % object mesh = a .obj mesh file for each pattern generated using the input models (blenderfile option)
0008 % SBML-Spatial file = a systems biology markup language(SBML) formatted xml file utilizing the spatial extension in level 3 version 1
0009 %
0010 %
0011 % COMMENT: When the method is not deployed the shape of the input arguments is
0012 % slml2img( models, param )
0013 %
0014 % List Of Input Arguments  Descriptions
0015 % -----------------------  ------------
0016 % models                   A cell array of filenames
0017 % param                    A structure holding the function options
0018 %
0019 % The shape of param is described
0020 %
0021 % List Of Parameters        Descriptions
0022 % ------------------        ------------
0023 % targetDirectory           (optional) Directory where the images are going to be saved. Default is current directory.
0024 % prefix                    (optional) Filename prefix for the synthesized images. Default is 'demo'
0025 % numberOfSynthesizedImages (optional) Number of synthesized images. Default is 1.
0026 % compression               (optional) Compression of tiff, i.e. 'none', 'lzw' and 'packbits'
0027 % debug                     (optional) Keeps temporary results and catches errors with full reports
0028 % display                   (optional) Display flag for figures
0029 % verbose                   (optional) Print the intermediate steps to screen. Default is true.
0030 % microscope                (optional) Microscope model from which we select a point spread function. Default is 'none'
0031 % synthesis                 (optional) Synthesis parameter that allows to
0032 %                                      synthesize 'nucleus', 'framework' or 'all'. Default is 'all'
0033 % protein.cytonuclearflag   (optional) Defines the allowable region for protein placement.
0034 %                                      The default is the cytonuclearflag included in the model.
0035 % sampling.method           (optional) Can be 'disc' or 'sampled'. Default is trimmed
0036 % savePDF                   (optional) Saves the probability density function for a given pattern during 2D synthesis. Default is False.
0037 % spherical_cell            (optional) Boolean flag that indicates whether a cell is spherical. Default is False.
0038 % synthesis.diffeomorphic.maximum_iterations (optional) Integer defining the maximum number of iterations during diffeo inference. Default is 100.
0039 % randomwalk                (optional) Boolean flag of whether to perform a shape space walk. Default is False.
0040 % framefolder               (optional) The folder in which to look for completed frames and save finished frames from the diffeomorphic synthesis.
0041 %                                      The default is './frames/'.
0042 % walksteps                 (optional) The integer number of steps to walk during a shape space walk. Default is 1.
0043 % walk_type                 (optional) Type of random walk to perform. Default is 'willmore'.
0044 % overlapsubsize            (optional) Defines the downsampling fraction to perform during object overlap avoidance. Default is 0.3.
0045 % overlapthresh             (optional) Defines the amount of overlap that is allowed between objects. Default is 1.
0046 % rendAtStd                 (optional) Defines the number of standard deviations to render gaussian objects at. Default is 2.
0047 % sampling.method.density   (optional) An integer. Default is empty.
0048 % protein.cytonuclearflag   (optional) Can 'cyto', 'nucleus' or 'all'. Default is all.
0049 % resolution.cell           (optional) The resolution of the cell and nucleus that are being passed in
0050 % resolution.objects        (optional) The resolution of the object model being synthesized
0051 % instance.cell             (optional) A binary cell image to be filled with objects. Default is empty.
0052 % instance.nucleus          (optional) A binary nuclear image to be filled with objects. Default is empty.
0053 % image_size                (optional) The image size. Default is [1024 1024] for both 2D and 3D in x and y
0054 % spherical_cell            (optional) Indicates whether the cell is spherical or not. Default is FALSE
0055 %
0056 % output.tifimages           (optional) boolean flag specifying whether to write out tif images
0057 % output.indexedimage        (optional) boolean flag specifying whether to write out indexed image
0058 % output.blenderfile         (optional) boolean flag specifying whether to write out (.obj) files for use in blender
0059 % output.blender.downsample  (optional) downsampling fraction for the creation of object files (1 means no downsampling, 1/5 means 1/5 the size)
0060 % output.SBML                (optional) boolean flag specifying whether to write out (.xml) files with SBML-Spatial representations of geometries
0061 %
0062 % Example
0063 % -------
0064 % instances = { 'model01.xml', 'model02.mat', 'model03.mat' };
0065 % param.targetDirectory = pwd;
0066 % param.prefix = 'demo'
0067 % param.numberOfSynthesizedImages = 100;
0068 % param.compression = 'lzw';
0069 % param.microscope = 'svi';
0070 % param.verbose = true;
0071 %
0072 % >> slml2img( instances, param );
0073 
0074 % Author: Ivan E. Cao-Berg (icaoberg@cmu.edu)
0075 % Created: May 8, 2007
0076 % March 7, 2012 R.F.Murphy  Don't create directory to hold 3D images if
0077 %                           generating 2D
0078 % March 8, 2012 I. Cao-Berg Documented the method
0079 % March 9, 2012 I. Cao-Berg Changed disp to fprintf and improved logs
0080 % March 9, 2012 I. Cao-Berg Removed print of progress bar from log file
0081 % March 21, 2012 I. Cao-Berg Changed protein.location to protein.cytonuclearflag
0082 % April 11, 2012 I. Cao-Berg Removed removal of temporary folder
0083 % June 5, 2012 M. Mackie    Added option to save as an index image using
0084 %                           param.image.type and param.image.option
0085 % June 6, 2012 M. Mackie    Removed parameter image.option (index images
0086 %                            may only be saved as 'priority'
0087 % July 25, 2012 D. Sullivan Added fields param.blender.file and param.blender.downsample
0088 %                           Created option for saving .obj files for exporting to blender
0089 % July 26, 2012 D. Sullivan Changed param.image and param.blender structures
0090 %                           to param.output structure (see header for usage)
0091 % July 30, 2012 I. Cao-Berg Modified code that is res files in the temporary folder rather than
0092 %                           the folder itself. This way if a user trains a model and synthesizes
0093 %                           images in the same script, the temp folder remains intact in case it is
0094 %                           run in debug mode
0095 % August 20, 2012 I. Cao-Berg Renamed img2blender to im2blender
0096 % October 1, 2012 I. Cao-Berg Removed deprecated code from previous versions
0097 % October 9, 2012 I. Cao-Berg Added print of the error stack if method
0098 % fails to synthesize an image
0099 % January 28, 2012 I. Cao-Berg Updated try/catch statement to print an
0100 % error report when running debug mode
0101 % April 29, 2013 D. Sullivan added documentation for param.debug
0102 % May 18, 2013 I . Cao-Berg Updated method so if framework fails to
0103 % synthesize it returns an empty framework
0104 % June 7, 2013 R. Arepally added the variable shiftvector as a parameter to
0105 % the im2blender function. This fixes the bug of inconsistant shifting of
0106 % different objects when the blender files are created.
0107 % July 23, 2013 D. Sullivan added primitives type of output
0108 
0109 % Copyright (C) 2007-2013 Murphy Lab
0110 % Carnegie Mellon University
0111 %
0112 % This program is free software; you can redistribute it and/or modify
0113 % it under the terms of the GNU General Public License as published
0114 % by the Free Software Foundation; either version 2 of the License,
0115 % or (at your option) any later version.
0116 %
0117 % This program is distributed in the hope that it will be useful, but
0118 % WITHOUT ANY WARRANTY; without even the implied warranty of
0119 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0120 % General Public License for more details.
0121 %
0122 % You should have received a copy of the GNU General Public License
0123 % along with this program; if not, write to the Free Software
0124 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0125 % 02110-1301, USA.
0126 %
0127 % For additional information visit http://murphylab.web.cmu.edu or
0128 % send email to murphy@cmu.edu
0129 
0130 %icaoberg 6/1/2013
0131 answer = false;
0132 
0133 % if ~isdeployed
0134 %     if nargin ~= 2
0135 %         error( ['CellOrganizer: Wrong number of input arguments. If slml2img ' ...
0136 %             ' is not deployed, then the number of input arguments must be 2.'] );
0137 %     end
0138 %
0139 % end
0140 
0141 %check if files exists and are valid SLML instances
0142 %INPUT ARGUMENTS
0143 param = varargin{2};
0144 
0145 %INPUT ARGUMENTS
0146 try
0147     verbose = param.verbose;
0148     if ~islogical( verbose )
0149         verbose = true;
0150     end
0151 catch
0152     verbose = true;
0153 end
0154 
0155 try
0156     debug = param.debug;
0157     if ~islogical( debug )
0158         debug = false;
0159     end
0160 catch
0161     debug = false;
0162 end
0163 
0164 %icaoberg 02/06/2013
0165 if ~isfield( param, 'display' )
0166     param.display = false;
0167 end
0168 
0169 %D. Sullivan 7/23/13 check for new randomwalk parameter
0170 if ~isfield(param,'randomwalk')
0171     param.randomwalk = false;
0172 end
0173 
0174 %icaoberg 10/9/2012
0175 try
0176     synthesis = param.synthesis;
0177     if ~isa( synthesis, 'char' )
0178         synthesis = 'all';
0179     else
0180         if ~strcmpi( synthesis, 'nucleus' ) && ~strcmpi( synthesis, 'cell' ) && ...
0181                 ~strcmpi( synthesis, 'framework' ) && ~strcmpi( synthesis, 'all' )
0182             synthesis = 'all';
0183         else
0184             synthesis = lower( synthesis );
0185         end
0186     end
0187 catch
0188     synthesis = 'all';
0189 end
0190 
0191 % R. Arepally 6/7/13 shiftvector empty array is instantiated
0192 % so that it can be passed to im2blender.
0193 shiftvector = [];
0194 
0195 %mmackie June 1st 2012
0196 %see what type of image to return, default is tif
0197 %dsullivan July 26 2012
0198 %edited from try-catch to if statement and changed from
0199 %param.image to param.output
0200 %moved to top of program, no reason to be checking this now
0201 if ~isfield(param,'output')
0202     param.output.tifimages = true;
0203 elseif ~isfield(param.output,'tifimages') && ~isfield(param.output,'indexedimage')&& ~isfield(param.output,'blenderfile')
0204     error('CellOrganizer: Unsupported output specified. Supported outputs for param.output are tifimages,indexedimage, and blenderfile. ')
0205 end
0206 
0207 %LOGS
0208 try
0209     if verbose
0210         disp( 'Checking existence of log folder' );
0211     end
0212     
0213     if ~exist( [ pwd filesep 'log'], 'dir' )
0214         if verbose
0215             disp( ['Making log directory ' pwd filesep 'log' ] );
0216         end
0217         mkdir( 'log' );
0218     end
0219     
0220     c = clock;
0221     logfile = '';
0222     for i=1:1:length(c)
0223         logfile = ['',logfile,num2str(c(i))]; %#ok<AGROW>
0224     end
0225     logfile = [ pwd filesep 'log' filesep logfile, '.log' ];
0226     
0227     fileID = fopen( logfile, 'w' );
0228 catch err
0229     warning( 'CellOrganizer: Failed to create log file. Exiting program.' ) %#ok<*WNTAG>
0230     
0231     %icaoberg 1/28/2013
0232     if debug
0233         getReport( err, 'extended' );
0234     end
0235     
0236     if ~isdeployed
0237         return
0238     else
0239         exit
0240     end
0241 end
0242 
0243 filenames = varargin{1};
0244 if verbose
0245     fprintf( 1, '%s', 'Checking the validity of input files');
0246 end
0247 
0248 %icaoberg 7/1/2013
0249 if isempty( filenames )
0250     disp( 'List of models cannnot be empty. Exiting method.' );
0251     return
0252 end
0253 
0254 if ~isa( filenames, 'cell' )
0255     disp( 'List of models must be a cell array. Exiting method.' );
0256     return
0257 end
0258 
0259 fprintf( fileID, '%s', 'Checking the validity of input files' );
0260 for i=1:1:length(filenames)
0261     if ~isaFile( filenames{i} )
0262         if verbose
0263             fprintf( 1, '\n%s', ['Input argument ' filenames{i} ' is not a file'] );
0264         end
0265         
0266         fprintf( fileID, '\n%s', ['Input argument ' filenames{i} ' is not a file'] );
0267         fclose( fileID );
0268         
0269         %icaoberg 7/1/2013
0270         disp( ['Input argument ' filenames{i} ' is not a file'] );
0271         return
0272     else
0273         n=length(filenames);
0274         %icaoberg 7/1/2013
0275 %         if verbose
0276 %             %indicate an object has been successfully added
0277 %             fprintf( 1, [ repmat('\b', 1, length(num2str(100*(i-1)/n))+1) '%s'], ...
0278 %                 repmat(' ', 1, length(num2str(100*(i-1)/n))+1) );
0279 %             fprintf( 1, [ repmat('\b', 1, length(num2str(100*(i-1)/n))+1) '%s%%'], num2str(100*i/n) );
0280 %             pause(0.1)
0281 %         end
0282     end
0283 end
0284 
0285 % %parse SLML instances into Matlab structures
0286 % icaoberg 7/1/2013
0287 if verbose
0288     fprintf( 1, '\n%s', 'Parsing SLML instances' );
0289 end
0290 
0291 fprintf( fileID, '%s', 'Parsing SLML instances' );
0292 try
0293     for j=1:1:length(filenames)
0294         %if it is a mat file then load directly into memory
0295         if( isMatFile(filenames{j}) )
0296             load(filenames{j});
0297             models{j} = model;
0298         else
0299             models{j} = slml2model( filenames{j} );
0300         end
0301         
0302         n=length(filenames);
0303         %icaoberg 7/1/2013
0304 %         if verbose
0305 %             %indicate an object has been successfully added
0306 %             fprintf( 1, [ repmat('\b', 1, length(num2str(100*(j-1)/n))+1) '%s'], ...
0307 %                 repmat(' ', 1, length(num2str(100*(j-1)/n))+1) );
0308 %             fprintf( 1, [ repmat('\b', 1, length(num2str(100*(j-1)/n))+1) '%s%%'], num2str(100*j/n) );
0309 %             pause(0.1)
0310 %         end
0311     end
0312 catch err
0313     warning( 'Unable to parse SLML instances. Exiting program.' );
0314     fprintf( fileID, '%s\n', 'Unable to parse SLML instances. Exiting progam.' );
0315     
0316     %icaoberg 1/28/2013
0317     if debug
0318         getReport( err, 'extended' );
0319     end
0320     
0321     if verbose
0322         fprintf( 1, '%s\n', 'Unable to parse SLML instances. Exiting progam.' );
0323     end
0324     
0325     fprintf( fileID, '%s\n', 'Closing log file' );
0326     fclose( fileID );
0327     
0328     if ~isdeployed
0329         return
0330     else
0331         exit
0332     end
0333 end
0334 
0335 %TEMPORARY FOLDER
0336 fprintf( fileID, '\n%s\n', 'Checking existence of temporary folder' );
0337 if verbose
0338     fprintf( 1, '\n%s\n', 'Checking existence of temporary folder' );
0339 end
0340 
0341 %icaoberg 7/30/2012
0342 if exist([pwd filesep 'temp'], 'dir' )
0343     fprintf( fileID, '%s\n', ['Temporary folder found in ' pwd filesep 'temp. Removing all temporary files.'] );
0344     if verbose
0345         fprintf( 1, '%s\n', ['Temporary folder found in ' pwd filesep 'temp. Removing all temporary files.'] );
0346     end
0347     %delete([pwd filesep '*.mat']);
0348     %rmdir([pwd filesep 'temp'], 's');
0349     %mkdir([pwd filesep 'temp']);
0350 else
0351     fprintf( fileID, '%s\n', ['Creating temporary folder in: ' pwd filesep 'temp'] );
0352     if verbose
0353         fprintf( 1, '%s\n', ['Creating temporary folder in: ' pwd filesep 'temp'] );
0354     end
0355     mkdir([pwd filesep 'temp']);
0356 end
0357 
0358 %SETTING ARGUMENTS
0359 try
0360     targetDirectory = param.targetDirectory;
0361 catch err
0362     targetDirectory = pwd;
0363 end
0364 
0365 fprintf( fileID, '%s\n', ['Setting target directory to: ' targetDirectory ]  );
0366 if verbose
0367     fprintf( 1, '%s\n', ['Setting target directory to: ' targetDirectory ]  );
0368 end
0369 
0370 %setting prefix
0371 try
0372     prefix = param.prefix;
0373 catch
0374     prefix = 'demo';
0375 end
0376 
0377 fprintf( fileID, '%s\n', ['Setting prefix to: ' prefix ]  );
0378 if verbose
0379     fprintf( 1, '%s\n', ['Setting prefix to: ' prefix ]  );
0380 end
0381 
0382 %setting number of synthesized images
0383 if isdeployed
0384     numberOfSynthesizedImages = str2double( varargin{3} );
0385 else
0386     try
0387         numberOfSynthesizedImages =  param.numberOfSynthesizedImages;
0388     catch err
0389         numberOfSynthesizedImages = 1;
0390     end
0391 end
0392 
0393 fprintf( fileID, '%s\n', ['Setting number of synthesized images to: ' num2str(numberOfSynthesizedImages) ]  );
0394 if verbose
0395     fprintf( 1, '%s\n', ['Setting number of synthesized images to: ' num2str(numberOfSynthesizedImages) ]  );
0396 end
0397 
0398 %setting compression
0399 try
0400     compression = param.compression;
0401 catch err
0402     compression = 'none';
0403 end
0404 
0405 fprintf( fileID, '%s\n', ['Setting compression to: ' compression ] );
0406 if verbose
0407     fprintf( 1, '%s\n', ['Setting compression to: ' compression ] );
0408 end
0409 
0410 %synthesize multicolor images and save them to disk
0411 for i=1:1:numberOfSynthesizedImages
0412     if verbose
0413         disp( ['Synthesizing image ' num2str(i) '. Please wait, this might take several minutes.' ] );
0414     end
0415     
0416     fprintf( fileID, '%s\n', ['Synthesizing image ' num2str(i) '. Please wait, this might take several minutes.' ] );
0417     
0418     %     try
0419     param.fileID = fileID;
0420     imgs = model2img( models, param );
0421     
0422     %mmackie June 1st 2012
0423     %see what method for determining index, default is summation
0424     %dsullivan July 26 2012
0425     %changed to param.output boolean flag structure
0426     if isfield(param.output,'indexedimage') && param.output.indexedimage
0427         mapping = 1:length(imgs);
0428         mapping(1) = 2;
0429         mapping(2) = 1;
0430         
0431         %icaoberg 8/10/2012
0432         imgs = ims2index(imgs,mapping);
0433     end
0434     
0435     if isempty( imgs )
0436         disp( ['Unable to synthesize image ' ...
0437             num2str(i) ' from the given models. Continuing synthesis.'] );
0438         continue
0439     end
0440 %     catch err
0441 %         %icaoberg 1/28/2013
0442 %         getReport( err, 'extended' );
0443 %
0444 %         warning( 'CellOrganizer: Unable to synthesize an image from the given models. Exiting program.' );
0445 %         fprintf( fileID, '%s\n', 'Unable to synthesize an image from the given models. Exiting progam.' );
0446 %         if verbose
0447 %             disp('Closing log file.')
0448 %         end
0449 %
0450 %         fprintf( fileID, '%s\n', 'Closing log file' );
0451 %         fclose( fileID );
0452 %
0453 %         if ~exist([pwd filesep 'temp'], 'dir' )
0454 %             rmdir([pwd filesep 'temp'],'s');
0455 %         end
0456 %
0457 %         if ~isdeployed
0458 %             return
0459 %         else
0460 %             exit
0461 %         end
0462 %     end
0463     
0464     if strcmpi( models{1}.dimensionality, '2d' )
0465         temporary_file = [ pwd filesep 'temp' filesep 'image.mat' ];
0466         if exist( temporary_file )
0467             load( temporary_file );
0468             
0469             %icaoberg 7/1/2013
0470             img2tif( imgs{1},[ targetDirectory filesep prefix num2str(i) ...
0471                 '.tif'], compression );
0472             clear img
0473             delete( temporary_file );
0474         end
0475         
0476         %mmackie June 1st 2012
0477         %dsullivan July 26 2012
0478         %changed to boolean param.output options (can turn all on at once)
0479     else
0480         outdir = [ targetDirectory filesep prefix filesep 'cell' num2str(i) ];
0481         if ~exist( outdir, 'dir' )
0482             mkdir ( outdir )
0483         end
0484         
0485         %if indexed image flag is true, save as indexed image
0486         if isfield(param.output,'indexedimage') && param.output.indexedimage
0487             if verbose
0488                 disp( 'Saving indexed image' );
0489             end
0490             
0491             fprintf( fileID, '%s\n', 'Saving indexed image' );
0492             img2tif( imgs, [ outdir filesep 'indexed.tif'], compression, true) ;
0493         end
0494         
0495         %icaoberg 10/9/2012
0496         if strcmpi( synthesis, 'nucleus' ) || strcmpi( synthesis, ...
0497                 'framework' ) || strcmpi( synthesis, 'all' )
0498             load( [ pwd filesep 'temp' filesep 'image1.mat' ] );
0499             %added conditional for synthesis option
0500             if isfield(param.output,'tifimages') && param.output.tifimages
0501                 if verbose
0502                     disp( 'Saving nuclear channel tif image' );
0503                 end
0504                 
0505                 fprintf( fileID, '%s\n', 'Saving nuclear channel tif image'  );
0506                 img2tif( img, [ outdir filesep 'nucleus.tif'], compression );
0507             end
0508             
0509             %added conditional for synthesis option
0510             if isfield(param.output,'blenderfile')&& param.output.blenderfile
0511                 %7/25/12 DPS blender files
0512                 if verbose
0513                     disp( 'Saving nuclear channel object file' );
0514                 end
0515                 fprintf( fileID, '%s\n', 'Saving nuclear channel .obj file'  );
0516                 
0517                 %icaoberg 8/10/2012
0518 %                 im2blender(img,[ outdir filesep 'nucleus.obj'], ...
0519 %                     param.output.blender.downsample )
0520                 % Rohan Arepally 6/7/13 added [] and shiftvector to parameters
0521                 % also shiftvector is returned by the function im2blender.
0522                 [shiftvector, ~] = im2blender(img,[ outdir filesep 'nucleus.obj'],param.output.blender.downsample, ...
0523                 [],shiftvector);
0524             end
0525            if isfield(param.output,'SBML')&&param.output.SBML 
0526 %                 framework2SBML('nucleus',imgs{1},'cell.xml',[]);
0527             end
0528             clear image;
0529         end
0530         
0531         %cell membrane
0532         if strcmpi( synthesis, 'cell' ) || strcmpi( synthesis, ...
0533                 'framework' ) || strcmpi( synthesis, 'all' )
0534             load( [ pwd filesep 'temp' filesep 'image2.mat' ] );
0535             if isfield(param.output,'tifimages') && param.output.tifimages
0536                 if verbose
0537                     disp( 'Saving cell channel tif image' );
0538                 end
0539                 
0540                 fprintf( fileID, '%s\n', 'Saving cell channel tif image'  );
0541                 
0542                 img2tif( img, [ outdir filesep 'cell.tif'], compression );
0543             end
0544             
0545             %7/25/12 DPS blender files
0546             if isfield(param.output,'blenderfile') && param.output.blenderfile
0547                 if verbose
0548                     disp( 'Saving cell channel .obj file' );
0549                 end
0550                 fprintf( fileID, '%s\n', 'Saving cell channel .obj file'  );
0551                 
0552                 %icaoberg 8/10/2012
0553 %                 im2blender(img,[ outdir filesep 'cell.obj'],param.output.blender.downsample)
0554                  % Rohan Arepally 6/7/13 added [] and shiftvector to parameters
0555                 % also shiftvector is returned by the function im2blender.
0556                 im2blender(img,[ outdir filesep 'cell.obj'], ...
0557                     param.output.blender.downsample , [], shiftvector);
0558             end
0559             if isfield(param.output,'SBML')&&param.output.SBML 
0560 %                 framework2SBML('cell',imgs{2},'cell.xml',[]);
0561             end
0562             
0563             clear image;
0564         end
0565         
0566         %icaoberg 10/9/2012
0567         %will only perform this tasks if synthesis is set to all
0568         if strcmpi( synthesis, 'all' )
0569             %create framework struct for SBML model using the first two
0570             %images (nuc, cell)
0571             if (isfield(param.output,'SBML')&&param.output.SBML)
0572                 frameworkSBML = createSBMLFrameworkstruct(imgs(1:2))
0573             end
0574             for j=1:1:length(models)
0575                 if ~strcmpi( models{j}.proteinShape.class, 'centrosome' )
0576                     load( [ pwd filesep 'temp' filesep 'image' num2str(j+2) '.mat' ] )
0577                     if isfield(param.output,'tifimages') && param.output.tifimages
0578                         if verbose
0579                             disp( ['Saving protein channel image ' models{j}.proteinShape.class ] );
0580                         end
0581                         fprintf( fileID, '%s\n', ['Saving protein channel image ' models{j}.proteinShape.class] );
0582                         
0583                         img2tif( img, [ outdir filesep models{j}.proteinShape.class '.tif'], compression );
0584                     end
0585                     %7/25/12 DPS blender files
0586                     if isfield(param.output,'blenderfile') && param.output.blenderfile
0587                         if verbose
0588                             disp( ['Saving protein channel object file ' models{j}.proteinShape.class ] );
0589                         end
0590                         % R. Arepally 6/7/13 added [] and shiftvector as
0591                         % parameters to im2blender.
0592                         im2blender(img,[ outdir filesep models{j}.proteinShape.class '.obj'],param.output.blender.downsample ...
0593                         ,[], shiftvector);
0594 %                         im2blender(img,[ outdir filesep models{j}.proteinShape.class '.obj'],param.output.blender.downsample)
0595                     end
0596                     %7/25/12 DPS end addition
0597                     %D. Sullivan 7/23/13 added primitives type of output
0598                     if (isfield(param.output,'SBML')&&param.output.SBML)
0599 %                         savedatfile([outdir filesep models{j}.proteinShape.class filesep models{j}.proteinShape.class],models{j}.proteinShape.resolution,param.output.blender.downsample);
0600                        primitives = createSBMLstruct(models{j}.proteinShape,num2str(j));
0601                        if isfield(param.output.SBML,'primitives')&&param.output.primitives ==1
0602                            primitives.primitiveOnly = 1;
0603                        end
0604                        instance2SBML(primitives,frameworkSBML,'TfR.xml')
0605 %                         perobjmdl([outdir filesep models{j}.proteinShape.class filesep],models{j}.proteinShape.resolution);
0606                     end
0607                 end
0608             end
0609         end
0610         
0611     end
0612     
0613     %icaoberg 7/1/2013
0614     %if we got here at least one image was succesfully synthesized
0615     answer = true;
0616 end
0617 
0618 %icaoberg 6/1/2013
0619 if debug
0620     save( [ pwd filesep 'temp' filesep 'param.mat' ], 'param' );
0621 end
0622 
0623 if debug
0624     save( [ pwd filesep 'temp' filesep 'param.mat' ], 'param' );
0625 end
0626 
0627 if ~debug
0628     fprintf( fileID, '%s\n', 'Removing temporary folder' );
0629     if verbose
0630         fprintf( 1, '%s\n', 'Removing temporary files' );
0631         delete( [ pwd filesep 'temp' filesep 'image*.mat'] );
0632         rmdir( [ pwd filesep 'temp'], 's' );
0633     end
0634 end
0635 
0636 if verbose
0637     disp('Closing log file.')
0638 end
0639 
0640 fprintf( fileID, '%s\n', 'Closing log file' );
0641 fclose( fileID );
0642 
0643 %icaoberg 7/1/2013
0644 disp( 'Finished synthesis' );

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