PageRenderTime 74ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/matlab_tools/Converted/kvthick.m

http://github.com/aludnam/MATLAB
Objective C | 211 lines | 208 code | 3 blank | 0 comment | 56 complexity | a5dff6c3edb33e1728a00dc277c2b3dd MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvthick 'Thickening'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vthick.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. % OutputFile: o 'Output Image ', required: 'resulting output image'
  9. %
  10. % Example: o = kvthick({i, str1, str2}, {'i','';'str1','';'str2','';'o',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % vthick - Thickening
  16. %
  17. % DESCRIPTION
  18. % .I vthick
  19. % will do the thickening of an input image by two set structuring elements.
  20. %
  21. % The output image data type will be the same as that of the highest data type
  22. % of the input image.
  23. %
  24. % Some useful pairs of structuring elements:
  25. %
  26. % 0 0 0 1 1 1
  27. % Conditional Segmentation 0 1 0 0 0 0
  28. % 1 1 1 0 0 0
  29. %
  30. % 0 0 0 1 0 0
  31. % Pseudo Convex Hull 0 1 1 1 0 0
  32. % 0 0 0 1 0 0
  33. %
  34. % 1 0 0 0 0 0
  35. % Convex Hull 1 0 0 0 1 0
  36. % 1 0 0 0 0 0
  37. %
  38. % 0 0 0 1 1 1
  39. % Homotopic Pruning 0 1 0 1 0 1
  40. % 0 0 0 1 1 1
  41. %
  42. %
  43. %
  44. % EXAMPLES
  45. % vthick -i ball.xv -str1 b272.str -str2 b273.str -o outimage.xv
  46. %
  47. % Will do the thickening of image "ball.xv" by the structuring set b272.str and b273.str, with the resulting image written to "outimage.xv".
  48. %
  49. % "SEE ALSO"
  50. % vcast1(1)
  51. %
  52. % RESTRICTIONS
  53. % .I vthick
  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 = kvthick(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,..] = kvthick(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';'o', '__output'};
  75. maxval={0,0,0,0};
  76. minval={0,0,0,0};
  77. istoggle=[0,0,0,0];
  78. was_set=istoggle * 0;
  79. paramtype={'InputFile','InputFile','InputFile','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 'vthick" '],Inputs,narglist);