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

/matlab_tools/Converted/kvcloserecth.m

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