PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kSeedSeg.m

http://github.com/aludnam/MATLAB
Objective C | 188 lines | 185 code | 3 blank | 0 comment | 54 complexity | b70c1ba0dc6e23133261f70eb635aaea MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kSeedSeg 'Segments Lamin Cells using seeding '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros SeedSeg.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input ', required: 'First Input data object'
  6. % InputFile: v 'Seed vector file', required: 'file with seed vectors (starting X at component X=1)'
  7. % InputFile: s 'Spot vector file', optional: 'when given, the spots inside the cells will be counted'
  8. % Double: t 'Initial Thresh', default: 5: 'a growing by this amount will be initiated'
  9. % Double: pZ 'Penalty Z', default: 1: 'penalty during initial growth in Z'
  10. % Double: pXY 'Penalty XY', default: 1: 'penalty during initial growth in XY'
  11. % Double: pG 'Second Growth Penalty', default: 1: 'groth penalty during secondary growth (for maximum)'
  12. % Integer: mX 'Max Size X', default: 30: 'maximal allowed size along X'
  13. % Integer: mY 'Y', default: 30: 'maximal allowed size along Y'
  14. % Integer: mZ 'Z', default: 20: 'maximal allowed size along Z'
  15. % OutputFile: o 'Output', required: 'Resulting output data object'
  16. %
  17. % Example: o = kSeedSeg({i, v, s}, {'i','';'v','';'s','';'t',5;'pZ',1;'pXY',1;'pG',1;'mX',30;'mY',30;'mZ',20;'o',''})
  18. %
  19. % Khoros helpfile follows below:
  20. %
  21. % PROGRAM
  22. % SeedSeg - Segments Lamin Cells using seeding
  23. %
  24. % DESCRIPTION
  25. %
  26. %
  27. %
  28. % EXAMPLES
  29. %
  30. % "SEE ALSO"
  31. %
  32. % RESTRICTIONS
  33. %
  34. % REFERENCES
  35. %
  36. % COPYRIGHT
  37. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  38. %
  39. function varargout = kSeedSeg(varargin)
  40. if nargin ==0
  41. Inputs={};arglist={'',''};
  42. elseif nargin ==1
  43. Inputs=varargin{1};arglist={'',''};
  44. elseif nargin ==2
  45. Inputs=varargin{1}; arglist=varargin{2};
  46. else error('Usage: [out1,..] = kSeedSeg(Inputs,arglist).');
  47. end
  48. if size(arglist,2)~=2
  49. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  50. end
  51. narglist={'i', '__input';'v', '__input';'s', '__input';'t', 5;'pZ', 1;'pXY', 1;'pG', 1;'mX', 30;'mY', 30;'mZ', 20;'o', '__output'};
  52. maxval={0,0,1,0,0,0,0,0,0,0,0};
  53. minval={0,0,1,0,0,0,0,0,0,0,0};
  54. istoggle=[0,0,1,0,0,0,0,0,0,0,0];
  55. was_set=istoggle * 0;
  56. paramtype={'InputFile','InputFile','InputFile','Double','Double','Double','Double','Integer','Integer','Integer','OutputFile'};
  57. % identify the input arrays and assign them to the arguments as stated by the user
  58. if ~iscell(Inputs)
  59. Inputs = {Inputs};
  60. end
  61. NumReqOutputs=1; nextinput=1; nextoutput=1;
  62. for ii=1:size(arglist,1)
  63. wasmatched=0;
  64. for jj=1:size(narglist,1)
  65. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  66. wasmatched = 1;
  67. was_set(jj) = 1;
  68. if strcmp(narglist{jj,2}, '__input')
  69. if (nextinput > length(Inputs))
  70. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  71. end
  72. narglist{jj,2} = 'OK_in';
  73. nextinput = nextinput + 1;
  74. elseif strcmp(narglist{jj,2}, '__output')
  75. if (nextoutput > nargout)
  76. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  77. end
  78. if (isempty(arglist{ii,2}))
  79. narglist{jj,2} = 'OK_out';
  80. else
  81. narglist{jj,2} = arglist{ii,2};
  82. end
  83. nextoutput = nextoutput + 1;
  84. if (minval{jj} == 0)
  85. NumReqOutputs = NumReqOutputs - 1;
  86. end
  87. elseif isstr(arglist{ii,2})
  88. narglist{jj,2} = arglist{ii,2};
  89. else
  90. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  91. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  92. end
  93. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  94. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  95. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  96. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  97. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  98. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  99. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  100. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  101. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  102. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  103. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  104. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  105. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  106. end
  107. end
  108. end
  109. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  110. narglist{jj,2} = arglist{ii,2};
  111. end
  112. end
  113. end
  114. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  115. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  116. end
  117. end
  118. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  119. for jj=1:size(narglist,1)
  120. if strcmp(paramtype{jj}, 'Toggle')
  121. if (narglist{jj,2} ==0)
  122. narglist{jj,1} = '';
  123. end;
  124. narglist{jj,2} = '';
  125. end;
  126. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  127. narglist{jj,1} = '';
  128. narglist{jj,2} = '';
  129. end;
  130. if strcmp(narglist{jj,2}, '__input')
  131. if (minval{jj} == 0) % meaning this input is required
  132. if (nextinput > size(Inputs))
  133. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  134. else
  135. narglist{jj,2} = 'OK_in';
  136. nextinput = nextinput + 1;
  137. end
  138. else % this is an optional input
  139. if (nextinput <= length(Inputs))
  140. narglist{jj,2} = 'OK_in';
  141. nextinput = nextinput + 1;
  142. else
  143. narglist{jj,1} = '';
  144. narglist{jj,2} = '';
  145. end;
  146. end;
  147. else
  148. if strcmp(narglist{jj,2}, '__output')
  149. if (minval{jj} == 0) % this is a required output
  150. if (nextoutput > nargout & nargout > 1)
  151. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  152. else
  153. narglist{jj,2} = 'OK_out';
  154. nextoutput = nextoutput + 1;
  155. NumReqOutputs = NumReqOutputs-1;
  156. end
  157. else % this is an optional output
  158. if (nargout - nextoutput >= NumReqOutputs)
  159. narglist{jj,2} = 'OK_out';
  160. nextoutput = nextoutput + 1;
  161. else
  162. narglist{jj,1} = '';
  163. narglist{jj,2} = '';
  164. end;
  165. end
  166. end
  167. end
  168. end
  169. if nargout
  170. varargout = cell(1,nargout);
  171. else
  172. varargout = cell(1,1);
  173. end
  174. global KhorosRoot
  175. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  176. w=['"' KhorosRoot];
  177. else
  178. if ispc
  179. w='"C:\Program Files\dip\khorosBin\';
  180. else
  181. [s,w] = system('which cantata');
  182. w=['"' w(1:end-8)];
  183. end
  184. end
  185. [varargout{:}]=callKhoros([w 'seedseg" -k'],Inputs,narglist);