0001 function answer = syn2blender( imgfolder, outputfolder, 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 answer = false;
0054
0055 if nargin > 3
0056 error('Wrong number of input arguments');
0057 end
0058
0059 if nargin == 2
0060 param = struct([]);
0061 end
0062
0063 try
0064 verbose = param.verbose;
0065 if ~islogical( verbose )
0066 verbose = false;
0067 end
0068 catch
0069 verbose = false;
0070 end
0071
0072 try
0073 debug = param.debug;
0074 if ~islogical( debug )
0075 debug = false;
0076 end
0077 catch
0078 debug = false;
0079 end
0080
0081 try
0082 downsample = param.downsample;
0083 if ~isnumeric( downsample )
0084 downsample = 1;
0085 end
0086 catch
0087 downsample = 1;
0088 end
0089
0090 if isempty( imgfolder )
0091 if debug
0092 warning('Input argument imgfolder cannot be empty')
0093 end
0094 return
0095 end
0096
0097 if ~exist( imgfolder )
0098 if debug
0099 warning('Input argument imgfolder does not exist');
0100 end
0101 return
0102 end
0103
0104 if isempty( outputfolder )
0105 if debug
0106 warning('Input argument savefile cannot be empty');
0107 end
0108 return
0109 end
0110
0111 if ~exist( outputfolder )
0112
0113
0114 mkdir(outputfolder)
0115
0116
0117
0118
0119 end
0120
0121
0122 files = ml_dir( [ imgfolder filesep '*.tif' ] );
0123
0124
0125
0126 for index=1:1:length(files)
0127 file = files{index};
0128 img = tif2img( [imgfolder filesep file] );
0129 if index == 1
0130
0131
0132 shiftvector = [];
0133 end
0134 savefile = [ outputfolder filesep file(1:end-3) 'obj' ];
0135 if verbose
0136 disp( [ 'Exporting ' file ' to ' savefile ] );
0137 end
0138 try
0139 if length(downsample)==1
0140
0141 if isfield(param,'patchsample')
0142 if length(param.patchsample) == 1
0143 im2blender( img, savefile, downsample,param.patchsample, [], shiftvector );
0144 elseif length(param.patchsample)==length(files)
0145 im2blender( img, savefile, downsample,param.patchsample(index),[], shiftvector);
0146 else
0147 warning('Unable to generate blender files, invalid patchsample vector specified.');
0148 return;
0149 end
0150 else
0151 im2blender( img, savefile, downsample, [], shiftvector);
0152 end
0153 elseif length(downsample)>1
0154 if isfield(param,'patchsample')
0155 if length(param.patchsample) ==1
0156 im2blender( img, savefile, downsample(index),param.patchsample);
0157 elseif length(param.patchsample)==length(files)
0158 im2blender( img, savefile, downsample(index),param.patchsample(index));
0159 else
0160 warning('Unable to generate blender files, invalid patchsample vector specified.');
0161 return;
0162 end
0163 else
0164 im2blender( img, savefile, downsample(index));
0165 end
0166 else
0167 warning('Unable to generate blender files, invalid downsampling vector specified.');
0168 return;
0169 end
0170 catch
0171 disp(['Unable to make ' savefile ]);
0172 end
0173 end
0174
0175 answer = true;