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

/matlab_tools/Converted/kvcondskthin.m

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