/matlab_tools/Converted/kvskelthinP.m

http://github.com/aludnam/MATLAB · Objective C · 200 lines · 197 code · 3 blank · 0 comment · 56 complexity · 437906e651225ddc9062f12a1be9a74e MD5 · raw file

  1. %kvskelthinP 'Skeleton by Thinning Mult. P'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vskelthinP.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. % InputFile: str3 'Struct Element 3', required: 'Structuring Element'
  9. % InputFile: str4 'Struct Element 4', required: 'Structuring Element'
  10. % OutputFile: o 'Output Image ', required: 'resulting output image'
  11. %
  12. % Example: o = kvskelthinP({i, str1, str2, str3, str4}, {'i','';'str1','';'str2','';'str3','';'str4','';'o',''})
  13. %
  14. % Khoros helpfile follows below:
  15. %
  16. % PROGRAM
  17. % vskelthinP - Skeleton by Thinning Mult. P
  18. %
  19. % DESCRIPTION
  20. % .I vskelthinP
  21. % will do the skeleton by thinning with mult. str. sets of an input image by a set of structuring elements. This program is based on an algorithm proposed by Roland T. Chin and Ben-Kwei Jang.
  22. %
  23. % The output image data type will be the same as that of the highest data type
  24. % of the input image.
  25. %
  26. % Useful set of structuring elements:
  27. %
  28. % 0 0 0 1 1 0 0 0 0 0 1 0
  29. % Homotopic Skeleton 0 1 1 1 0 0 1 1 1 0 0 0
  30. % 0 1 0 0 0 0 0 1 0 0 0 0
  31. %
  32. %
  33. %
  34. % EXAMPLES
  35. % vskelthinP -i ball.xv -str1 b272 -str2 b273 -str3 b274 -str4 b275 -o outimage.xv
  36. %
  37. % Will do the skeleton by thinning with mult. str. sets of image "ball.xv" by the structuring sets b272, b273, b274 and b275, with the resulting image written to "outimage.xv".
  38. %
  39. % "SEE ALSO"
  40. %
  41. % RESTRICTIONS
  42. % .I vskelthinP
  43. % 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.
  44. % The structuring elements are subsets of the 3x3 matrix and the origin is always at the center of this matrix.
  45. %
  46. % REFERENCES
  47. %
  48. % COPYRIGHT
  49. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  50. %
  51. function varargout = kvskelthinP(varargin)
  52. if nargin ==0
  53. Inputs={};arglist={'',''};
  54. elseif nargin ==1
  55. Inputs=varargin{1};arglist={'',''};
  56. elseif nargin ==2
  57. Inputs=varargin{1}; arglist=varargin{2};
  58. else error('Usage: [out1,..] = kvskelthinP(Inputs,arglist).');
  59. end
  60. if size(arglist,2)~=2
  61. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  62. end
  63. narglist={'i', '__input';'str1', '__input';'str2', '__input';'str3', '__input';'str4', '__input';'o', '__output'};
  64. maxval={0,0,0,0,0,0};
  65. minval={0,0,0,0,0,0};
  66. istoggle=[0,0,0,0,0,0];
  67. was_set=istoggle * 0;
  68. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','OutputFile'};
  69. % identify the input arrays and assign them to the arguments as stated by the user
  70. if ~iscell(Inputs)
  71. Inputs = {Inputs};
  72. end
  73. NumReqOutputs=1; nextinput=1; nextoutput=1;
  74. for ii=1:size(arglist,1)
  75. wasmatched=0;
  76. for jj=1:size(narglist,1)
  77. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  78. wasmatched = 1;
  79. was_set(jj) = 1;
  80. if strcmp(narglist{jj,2}, '__input')
  81. if (nextinput > length(Inputs))
  82. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  83. end
  84. narglist{jj,2} = 'OK_in';
  85. nextinput = nextinput + 1;
  86. elseif strcmp(narglist{jj,2}, '__output')
  87. if (nextoutput > nargout)
  88. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  89. end
  90. if (isempty(arglist{ii,2}))
  91. narglist{jj,2} = 'OK_out';
  92. else
  93. narglist{jj,2} = arglist{ii,2};
  94. end
  95. nextoutput = nextoutput + 1;
  96. if (minval{jj} == 0)
  97. NumReqOutputs = NumReqOutputs - 1;
  98. end
  99. elseif isstr(arglist{ii,2})
  100. narglist{jj,2} = arglist{ii,2};
  101. else
  102. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  103. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  104. end
  105. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  106. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  107. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  108. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  109. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  110. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  111. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  112. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  113. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  114. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  115. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  116. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  117. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  118. end
  119. end
  120. end
  121. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  122. narglist{jj,2} = arglist{ii,2};
  123. end
  124. end
  125. end
  126. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  127. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  128. end
  129. end
  130. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  131. for jj=1:size(narglist,1)
  132. if strcmp(paramtype{jj}, 'Toggle')
  133. if (narglist{jj,2} ==0)
  134. narglist{jj,1} = '';
  135. end;
  136. narglist{jj,2} = '';
  137. end;
  138. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  139. narglist{jj,1} = '';
  140. narglist{jj,2} = '';
  141. end;
  142. if strcmp(narglist{jj,2}, '__input')
  143. if (minval{jj} == 0) % meaning this input is required
  144. if (nextinput > size(Inputs))
  145. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  146. else
  147. narglist{jj,2} = 'OK_in';
  148. nextinput = nextinput + 1;
  149. end
  150. else % this is an optional input
  151. if (nextinput <= length(Inputs))
  152. narglist{jj,2} = 'OK_in';
  153. nextinput = nextinput + 1;
  154. else
  155. narglist{jj,1} = '';
  156. narglist{jj,2} = '';
  157. end;
  158. end;
  159. else
  160. if strcmp(narglist{jj,2}, '__output')
  161. if (minval{jj} == 0) % this is a required output
  162. if (nextoutput > nargout & nargout > 1)
  163. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  164. else
  165. narglist{jj,2} = 'OK_out';
  166. nextoutput = nextoutput + 1;
  167. NumReqOutputs = NumReqOutputs-1;
  168. end
  169. else % this is an optional output
  170. if (nargout - nextoutput >= NumReqOutputs)
  171. narglist{jj,2} = 'OK_out';
  172. nextoutput = nextoutput + 1;
  173. else
  174. narglist{jj,1} = '';
  175. narglist{jj,2} = '';
  176. end;
  177. end
  178. end
  179. end
  180. end
  181. if nargout
  182. varargout = cell(1,nargout);
  183. else
  184. varargout = cell(1,1);
  185. end
  186. global KhorosRoot
  187. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  188. w=['"' KhorosRoot];
  189. else
  190. if ispc
  191. w='"C:\Program Files\dip\khorosBin\';
  192. else
  193. [s,w] = system('which cantata');
  194. w=['"' w(1:end-8)];
  195. end
  196. end
  197. [varargout{:}]=callKhoros([w 'vskelthinP" '],Inputs,narglist);