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

/matlab_tools/Converted/kvsupgen.m

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