PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvskthin.m

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