PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvnthick.m

http://github.com/aludnam/MATLAB
Objective C | 216 lines | 213 code | 3 blank | 0 comment | 56 complexity | 19cd28dfa8c02ba059e175ea565659f2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvnthick 'N-1 Compositions of Thickenings'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vnthick.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Image ', required: 'input image'
  6. % InputFile: str1 'Struct Element 1', required: 'Structuring Element'
  7. % InputFile: str2 'Struct Element 2', required: 'Structuring Element'
  8. % Integer: n 'Number of Thickenings', default: 5: 'number of thickenings'
  9. % MultiChoice: r 'Struct El. Rotation Step', default: 1: 'Rotation step'
  10. % Choices are:
  11. % 1: '1 '
  12. % 2: '2 '
  13. % 3: '4 '
  14. % OutputFile: o 'Output Image ', required: 'resulting output image'
  15. %
  16. % Example: o = kvnthick({i, str1, str2}, {'i','';'str1','';'str2','';'n',5;'r',1;'o',''})
  17. %
  18. % Khoros helpfile follows below:
  19. %
  20. % PROGRAM
  21. % vnthick - N-1 compositions of Thickenings
  22. %
  23. % DESCRIPTION
  24. % .I vnthick
  25. % will do N successive thickenings of an image.
  26. %
  27. % The output image data type will be the same as that of the highest data type
  28. % of the input image.
  29. %
  30. % Some useful pairs of structuring elements:
  31. %
  32. % 0 0 0 1 1 1
  33. % Conditional Segmentation 0 1 0 0 0 0
  34. % 1 1 1 0 0 0
  35. %
  36. % 0 0 0 1 0 0
  37. % Pseudo Convex Hull 0 1 1 1 0 0
  38. % 0 0 0 1 0 0
  39. %
  40. % 1 0 0 0 0 0
  41. % Convex Hull 1 0 0 0 1 0
  42. % 1 0 0 0 0 0
  43. %
  44. % 0 0 0 1 1 1
  45. % Homotopic Pruning 0 1 0 1 0 1
  46. % 0 0 0 1 1 1
  47. %
  48. %
  49. %
  50. % EXAMPLES
  51. % vnthick -i feath.xv -str1 b1.str -str2 b2.str -n 5 -r 1 -o outimage.xv
  52. %
  53. % Will do 5 successive thickenings (vnthick) of the input image "feath.xv" by the structuring element b1.str and b2.str, rotating the struct. els. 1 step after each thinning. The resulting image will be written to "outimage.xv".
  54. %
  55. % "SEE ALSO"
  56. % vcast1(1)
  57. %
  58. % RESTRICTIONS
  59. % .I vnthick
  60. % can be defined for all data types supported by Khoros, but at the moment it has been implemented just for the bit and unsigned char types.
  61. %
  62. % REFERENCES
  63. %
  64. % COPYRIGHT
  65. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  66. %
  67. function varargout = kvnthick(varargin)
  68. if nargin ==0
  69. Inputs={};arglist={'',''};
  70. elseif nargin ==1
  71. Inputs=varargin{1};arglist={'',''};
  72. elseif nargin ==2
  73. Inputs=varargin{1}; arglist=varargin{2};
  74. else error('Usage: [out1,..] = kvnthick(Inputs,arglist).');
  75. end
  76. if size(arglist,2)~=2
  77. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  78. end
  79. narglist={'i', '__input';'str1', '__input';'str2', '__input';'n', 5;'r', 1;'o', '__output'};
  80. maxval={0,0,0,2,0,0};
  81. minval={0,0,0,2,0,0};
  82. istoggle=[0,0,0,0,0,0];
  83. was_set=istoggle * 0;
  84. paramtype={'InputFile','InputFile','InputFile','Integer','MultiChoice','OutputFile'};
  85. % identify the input arrays and assign them to the arguments as stated by the user
  86. if ~iscell(Inputs)
  87. Inputs = {Inputs};
  88. end
  89. NumReqOutputs=1; nextinput=1; nextoutput=1;
  90. for ii=1:size(arglist,1)
  91. wasmatched=0;
  92. for jj=1:size(narglist,1)
  93. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  94. wasmatched = 1;
  95. was_set(jj) = 1;
  96. if strcmp(narglist{jj,2}, '__input')
  97. if (nextinput > length(Inputs))
  98. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  99. end
  100. narglist{jj,2} = 'OK_in';
  101. nextinput = nextinput + 1;
  102. elseif strcmp(narglist{jj,2}, '__output')
  103. if (nextoutput > nargout)
  104. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  105. end
  106. if (isempty(arglist{ii,2}))
  107. narglist{jj,2} = 'OK_out';
  108. else
  109. narglist{jj,2} = arglist{ii,2};
  110. end
  111. nextoutput = nextoutput + 1;
  112. if (minval{jj} == 0)
  113. NumReqOutputs = NumReqOutputs - 1;
  114. end
  115. elseif isstr(arglist{ii,2})
  116. narglist{jj,2} = arglist{ii,2};
  117. else
  118. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  119. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  120. end
  121. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  122. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  123. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  124. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  125. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  126. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  127. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  128. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  129. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  130. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  131. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  132. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  133. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  134. end
  135. end
  136. end
  137. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  138. narglist{jj,2} = arglist{ii,2};
  139. end
  140. end
  141. end
  142. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  143. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  144. end
  145. end
  146. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  147. for jj=1:size(narglist,1)
  148. if strcmp(paramtype{jj}, 'Toggle')
  149. if (narglist{jj,2} ==0)
  150. narglist{jj,1} = '';
  151. end;
  152. narglist{jj,2} = '';
  153. end;
  154. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  155. narglist{jj,1} = '';
  156. narglist{jj,2} = '';
  157. end;
  158. if strcmp(narglist{jj,2}, '__input')
  159. if (minval{jj} == 0) % meaning this input is required
  160. if (nextinput > size(Inputs))
  161. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  162. else
  163. narglist{jj,2} = 'OK_in';
  164. nextinput = nextinput + 1;
  165. end
  166. else % this is an optional input
  167. if (nextinput <= length(Inputs))
  168. narglist{jj,2} = 'OK_in';
  169. nextinput = nextinput + 1;
  170. else
  171. narglist{jj,1} = '';
  172. narglist{jj,2} = '';
  173. end;
  174. end;
  175. else
  176. if strcmp(narglist{jj,2}, '__output')
  177. if (minval{jj} == 0) % this is a required output
  178. if (nextoutput > nargout & nargout > 1)
  179. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  180. else
  181. narglist{jj,2} = 'OK_out';
  182. nextoutput = nextoutput + 1;
  183. NumReqOutputs = NumReqOutputs-1;
  184. end
  185. else % this is an optional output
  186. if (nargout - nextoutput >= NumReqOutputs)
  187. narglist{jj,2} = 'OK_out';
  188. nextoutput = nextoutput + 1;
  189. else
  190. narglist{jj,1} = '';
  191. narglist{jj,2} = '';
  192. end;
  193. end
  194. end
  195. end
  196. end
  197. if nargout
  198. varargout = cell(1,nargout);
  199. else
  200. varargout = cell(1,1);
  201. end
  202. global KhorosRoot
  203. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  204. w=['"' KhorosRoot];
  205. else
  206. if ispc
  207. w='"C:\Program Files\dip\khorosBin\';
  208. else
  209. [s,w] = system('which cantata');
  210. w=['"' w(1:end-8)];
  211. end
  212. end
  213. [varargout{:}]=callKhoros([w 'vnthick" '],Inputs,narglist);