Home > cellorganizer > utilities > objectMovementModel.m

objectMovementModel

PURPOSE ^

OBJECTMOVEMENTMODEL creates random walks for each object within a cell ignoring conflicts with other objects and cell/nuclear boundaries.

SYNOPSIS ^

function objectMovementModel(model,param)

DESCRIPTION ^

OBJECTMOVEMENTMODEL creates random walks for each object within a cell ignoring conflicts with other objects and cell/nuclear boundaries.
 This is intended to be used when a shape space walk is generated with objects

Inputs:
 model = the model from which we are synthesizing
 param = struct array containing information about where to load shape space walk from and save object motion walks to.

Outputs:
 generates and saves frames of object movements

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function objectMovementModel(model,param)
0002 %OBJECTMOVEMENTMODEL creates random walks for each object within a cell ignoring conflicts with other objects and cell/nuclear boundaries.
0003 % This is intended to be used when a shape space walk is generated with objects
0004 %
0005 %Inputs:
0006 % model = the model from which we are synthesizing
0007 % param = struct array containing information about where to load shape space walk from and save object motion walks to.
0008 %
0009 %Outputs:
0010 % generates and saves frames of object movements
0011 
0012 %Author: Devin Sullivan August 2013
0013 % Copyright (C) 2007-2013  Murphy Lab
0014 % Carnegie Mellon University
0015 %
0016 % This program is free software; you can redistribute it and/or modify
0017 % it under the terms of the GNU General Public License as published
0018 % by the Free Software Foundation; either version 2 of the License,
0019 % or (at your option) any later version.
0020 %
0021 % This program is distributed in the hope that it will be useful, but
0022 % WITHOUT ANY WARRANTY; without even the implied warranty of
0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0024 % General Public License for more details.
0025 %
0026 % You should have received a copy of the GNU General Public License
0027 % along with this program; if not, write to the Free Software
0028 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0029 % 02110-1301, USA.
0030 %
0031 % For additional information visit http://murphylab.web.cmu.edu or
0032 % send email to murphy@cmu.edu
0033 
0034 
0035 %try to find frame folder
0036 param = ml_initparam(param,struct('framefolder',['.',filesep,'frames',filesep]));
0037 
0038 %assign method for the object movement
0039 if ~isfield(param,'objmovemethod')
0040     objparam.method = 'brownian';
0041 else
0042     objparam.method = param.objmovemethod;
0043 end
0044 
0045 %load the original objects
0046 if ~isfield(param,'tempfolder')
0047     param.tempfolder = './temp';
0048 end
0049 load([param.tempfolder filesep 'OriginalObjects.mat'],...
0050         'GaussObjects','pos');
0051 %define diffusion and time step from model
0052 % diffusion constant
0053 % Dc = 10e-3;
0054 Dc = model.proteinShape.motion.Dc;
0055 
0056 %time step
0057 % dt = 1;
0058 dt = model.proteinShape.motion.dt;
0059 
0060     
0061 %find segmented cells and nuclei
0062 %These folders should not be hard coded in the future, but since it's not
0063 %currently a user accessible option to set them, it's ok.
0064 donecells = ml_ls([param.framefolder filesep 'Cellwalk' filesep '*.tif']);
0065 donenucs = ml_ls([param.framefolder filesep 'Nucwalk' filesep '*.tif']);
0066 %create a blank image
0067 tmpimg = ml_readimage(donecells{1});
0068 finalsize_x = floor(param.resolution.cell(1)./param.resolution.objects(1).*size(tmpimg,1));
0069 finalsize_y = floor(param.resolution.cell(2)./param.resolution.objects(2).*size(tmpimg,2));
0070 finalsize_z = floor(param.resolution.cell(3)./param.resolution.objects(3).*size(tmpimg,3));
0071 blankimg = zeros(finalsize_x,finalsize_y,finalsize_z);
0072 % blankimg = ml_readimage(donecells{1}).*0;
0073 % blankimg = AdjustResolutions(blankimg,param.resolution.cell,param.resolution.objects);
0074 
0075 
0076 
0077 %initialize newpositions
0078 newpos = pos;
0079 clear pos
0080 
0081 %make output directory
0082 savedir = [param.framefolder filesep 'Protwalk' filesep];
0083 if ~exist( savedir )
0084     mkdir( savedir )
0085 end
0086 
0087 %for each step, move the objects according to the motion model.
0088 for frame = 1:param.walksteps
0089     %first move all the objects
0090     newpos = moveObjects(newpos,Dc,dt,objparam);
0091     
0092     %put objects into image
0093     protimg = ml_imaddobj2(blankimg,GaussObjects,...
0094         struct('method','replace','pos',newpos,'objectmethod',param.sampling.method));
0095     
0096     %Load current cell and nucleus
0097     currcell = ml_readimage(donecells{frame});
0098     currcell = AdjustResolutions(currcell,param.resolution.cell,param.resolution.objects);
0099     currnuc = ml_readimage(donenucs{frame});
0100     currnuc = AdjustResolutions(currnuc,param.resolution.cell,param.resolution.objects);
0101     
0102     %mask image based on the allowed compartment
0103     %eliminate samples outside the cell.
0104     switch model.proteinShape.cytonuclearflag
0105         case {'cyt','cyto'}
0106             codemask = double(currcell)-double(currnuc);
0107         case {'nuc','nuclear'}
0108             codemask = double(currnuc - bwperim(currnuc));
0109         case 'all'
0110             codemask = double(currcell - bwperim(currcell));
0111         otherwise
0112             error(['Unrecognized location name: ' loc]);
0113     end
0114 
0115     protimg = protimg.*logical(codemask);
0116     
0117     %Save the frame
0118     img2tif(protimg,[savedir filesep 'frame' num2str(frame) '.tif']);
0119 end

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