0001 function [object,outres] = model2instance( model, param )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 object = [];
0065 outres=[];
0066 if nargin > 2
0067 error('CellOrganizer: Wrong number of input arguments.');
0068 end
0069
0070 if length(model) > 1
0071 if isstruct(model)
0072 model=model(1);
0073 else
0074 model = model{1};
0075 end
0076 end
0077
0078
0079 try
0080 dimensionality = model.dimensionality;
0081 catch
0082 warning( 'CellOrganizer: Unable to set dimensionality' );
0083 return
0084 end
0085
0086 try
0087 nucleus = param.nucleus;
0088 catch
0089 warning('CellOrganizer: Parameter nuclear shape instance not set.')
0090 return
0091 end
0092
0093 try
0094 cellMembrane = param.cell;
0095 catch
0096 warning('CellOrganizer: Parameter cell shape instance not set.')
0097 return
0098 end
0099
0100 try
0101 modelClass = model.class;
0102 catch
0103 warning('CellOrganizer: Parameter model class not set.')
0104 return
0105 end
0106
0107 try
0108 modelType = model.type;
0109 catch
0110 warning('CellOrganizer: Parameter model type not set.');
0111 return
0112 end
0113
0114 try
0115 microscope = param.microscope;
0116 catch
0117 microscope = 'none';
0118 end
0119
0120 switch lower(dimensionality)
0121 case '2d'
0122 switch lower(modelType)
0123 case 'vesicle'
0124 param = ml_initparam(param, ...
0125 struct('imageSize',[1024 1024],'gentex',0,'loc','all'));
0126 object = ml_genprotimg( model, nucleus, cellMembrane, param );
0127 otherwise
0128 warning('CellOrganizer: Unknown or unsupported model type.');
0129 object = [];
0130 return
0131 end
0132 case '3d'
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 try
0143 cellMemOriginal = cellMembrane;
0144 nucleusOriginal = nucleus;
0145 if(size(param.resolution.objects,1)>1)
0146
0147
0148
0149 initres = param.resolution.cell;
0150
0151
0152 if strcmpi(model.class,'centrosome')||strcmpi(model.type,'network')
0153 finalres = model.resolution;
0154 else
0155 finalres = param.resolution.objects(param.currentmodelnum,:);
0156 end
0157
0158
0159 finalsize_xRaw = initres(1)./finalres(1).*size(nucleus,1);
0160 finalsize_x = floor(finalsize_xRaw);
0161 finalsize_yRaw = initres(2)./finalres(2).*size(nucleus,2);
0162 finalsize_y = floor(finalsize_yRaw);
0163 finalsize_zRaw = initres(3)./finalres(3).*size(nucleus,3);
0164 finalsize_z = floor(finalsize_zRaw);
0165 nucleus = imresize(nucleus,[finalsize_x finalsize_y]);
0166 nucleardisttmp = imresize(param.nucleardist,[finalsize_x finalsize_y]);
0167
0168
0169 nucleus = tp_stretch3d(nucleus,finalsize_z);
0170 param.nucleus = nucleus;
0171 nucleardisttmp = tp_stretch3d(nucleardisttmp,finalsize_z);
0172 param.nucleardist = nucleardisttmp;
0173
0174
0175
0176
0177
0178
0179
0180 finalsize_xRaw = initres(1)./finalres(1).*size(cellMembrane,1);
0181 finalsize_x = floor(finalsize_xRaw);
0182 finalsize_yRaw = initres(2)./finalres(2).*size(cellMembrane,2);
0183 finalsize_y = floor(finalsize_yRaw);
0184 finalsize_zRaw = initres(3)./finalres(3).*size(cellMembrane,3);
0185 finalsize_z = floor(finalsize_zRaw);
0186 cellMembrane = imresize(cellMembrane,[finalsize_x finalsize_y],'bilinear');
0187 celldisttmp = imresize(param.celldist,[finalsize_x finalsize_y],'bilinear');
0188 cellMembrane = cellMembrane>0;
0189
0190 cellMembrane = tp_stretch3d(cellMembrane,finalsize_z);
0191 param.cell = cellMembrane;
0192 celldisttmp = tp_stretch3d(celldisttmp,finalsize_z);
0193 param.celldist = celldisttmp;
0194 end
0195 catch
0196
0197
0198
0199 disp(['No resolution specified for either cell or object class',...
0200 ' assuming no resizing necessary. If this is incorrect unexpected results will occur'])
0201 end
0202 switch lower(modelType)
0203 case 'vesicle'
0204
0205 try
0206 sampling = param.sampling.method;
0207 catch
0208 param.sampling.method = 0;
0209 end
0210
0211 try
0212 N = param.sampling.N;
0213 catch
0214 param.sampling.N = [];
0215 end
0216
0217 try
0218 location = param.sampling.location;
0219 catch
0220 param.sampling.location = 'all';
0221 end
0222
0223 object = tp_genprotimage( model, param );
0224
0225
0226
0227
0228
0229
0230 case 'centrosome'
0231 [object,resolution] = model2centrosome(nucleus, cellMembrane, model,param);
0232 case 'network'
0233 try
0234 centrosome = param.centrosome;
0235 catch
0236 warning(['CellOrganizer: A centrosome instance is needed to ' ...
0237 'synthesize a cytoskeletal instance. Remember to initialize param.centrosome.'])
0238 object = [];
0239 return;
0240 end
0241
0242
0243
0244 [object,imXYZ,resolution] = model2microtubules( cellMembrane, nucleus, centrosome, model, param );
0245
0246
0247
0248
0249
0250 otherwise
0251 warning('CellOrganizer: Unknown or unsupported model type.');
0252 object = [];
0253 return
0254 end
0255
0256
0257
0258
0259
0260
0261
0262
0263 if( isfield( param, 'resolution' ) && ...
0264 size(param.resolution.objects,1)>1) && ~strcmpi(modelType,'centrosome')
0265
0266
0267
0268
0269
0270 outsize_x = ceil(finalres(1)./param.outputres(1).*finalsize_xRaw);
0271 outsize_y = ceil(finalres(2)./param.outputres(2).*finalsize_yRaw);
0272 outsize_z = ceil(finalres(3)./param.outputres(3).*finalsize_zRaw);
0273 object = imresize(object,[outsize_x outsize_y],'bilinear');
0274
0275
0276 object = tp_stretch3d(object,outsize_z);
0277
0278
0279
0280 object = object.*cast((cellMemOriginal>0),class(object));
0281
0282
0283
0284 if strcmpi(model.cytonuclearflag,'cyto');
0285 object = object.*cast((~(nucleusOriginal)>0),class(object));
0286 end
0287
0288
0289
0290 if strcmpi(param.sampling.method,'disc')&& strcmpi(modelType,'vesicle')
0291 object = object>0;
0292 end
0293
0294 end
0295
0296
0297 outres = param.outputres;
0298
0299
0300 [psf,psfres] = micro2psf( microscope );
0301 if ~isempty( psf )&&~strcmpi(modelType,'centrosome')
0302
0303
0304
0305 if isfield(param,'outputres')&&sum(psfres~=param.outputres)~=0
0306 disp(['Different final resolution specified than trained PSF, ',...
0307 'resizing PSF to match final resolution'])
0308
0309 outpsf_x = floor(psfres(1)./param.outputres(1).*size(psf,1));
0310 outpsf_y = floor(psfres(2)./param.outputres(2).*size(psf,2));
0311 outpsf_z = floor(psfres(3)./param.outputres(3).*size(psf,3));
0312 psf = imresize(psf,[outpsf_x outpsf_y],'bilinear');
0313
0314
0315 psf = tp_stretch3d(psf,outpsf_z);
0316
0317 end
0318
0319
0320 object = psf_blur_hela_mean_dps( object, psf );
0321 end
0322 otherwise
0323 warning('CellOrganizer: Unknown or unsupported dimensionality.')
0324 object = [];
0325 return
0326 end
0327