PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvlastero.m

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