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

/matlab_tools/Converted/kvopenth.m

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