PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kvclohole.m

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