PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kvicanon.m

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