PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvncondero.m

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