PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/matlab_tools/Converted/kvdilexpan.m

http://github.com/aludnam/MATLAB
Objective C | 238 lines | 235 code | 3 blank | 0 comment | 57 complexity | e053fde4232b905eeb34adf601237c62 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvdilexpan 'Expansion by Dilation'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vdilexpan.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Image', required: 'input image'
  6. % InputFile: str 'Struct Element', optional: 'Structuring Element'
  7. % Integer: vs ' Vertical Scale Factor ', default: 2: 'expansion scale factor'
  8. % Integer: hs ' Horizontal Scale Factor ', default: 2: 'expansion scale factor'
  9. % Integer: voff 'Vertical Offset ', default: 0: 'expansion scale factor'
  10. % Integer: hoff 'Horizontal Offset ', default: 0: 'expansion scale factor'
  11. % OutputFile: o 'Output Image ', required: 'resulting output image'
  12. %
  13. % Example: o = kvdilexpan({i, str}, {'i','';'str','';'vs',2;'hs',2;'voff',0;'hoff',0;'o',''})
  14. %
  15. % Khoros helpfile follows below:
  16. %
  17. % PROGRAM
  18. % vdilexpan - Expansion by Dilation
  19. %
  20. % DESCRIPTION
  21. % .I vdilexpan
  22. % expand an input image in both directions.
  23. %
  24. % Let the domain of the input image be
  25. % E = [0, 1, ..., m - 1] x [0, 1, ..., n - 1].
  26. % Let vs and hs be two positive integer values representing, respectively, the vertical and horizontal scale factors.
  27. % Let the domain of the output image be
  28. % vhE = [0, 2, ..., vs(m - 1)] x [0, 2, ..., hs(n - 1)].
  29. % Let vo and ho be two non negative integer values less or equal than, respectively, vs and hs. vo and ho represent, respectively, the vertical and horizontal offsets.
  30. % Let a be the (conditionally) structuring function from E to P(vhE)
  31. % (the subsets of vhE) given by
  32. % a(y) = (A + (y + (vo, ho))) n vhE (y member of E)
  33. % where n means "intersection" and where A is a subset of the 3 x 3
  34. % square centered at the origim, called structuring element.
  35. % The expansion of the input image Y is the dilation of Y by a, that is:
  36. % expand of Y = U{a(y): y member Y}.
  37. %
  38. % If A is the 2 x 2 square then the dilation expands the input image in
  39. % the usual manner, that is by duplicating each original pixel four times
  40. % (twice in both directions).
  41. % If A is the 3 x 3 square then the expansion of an 8-connected subset
  42. % appears without ambiguity on the screen as a connected subset (in the
  43. % sense of the usual Euclidean topology). In this later case, we say that
  44. % the expansion preserve the connectivity 8.
  45. %
  46. % The input and output images must be of the same data type, and have
  47. % the same number of data bands. The output image column size is vs times
  48. % the input image column size and the output image row size is hs times
  49. % the input image row size.
  50. %
  51. %
  52. %
  53. % EXAMPLES
  54. %
  55. % will do the expansion (dilation) of the input image "ball.xv" by the structuring element "b.str" and the resulting image will be "outimage.xv".
  56. % The vertical scale factor is 2, the horizontal scale factor is 2, the
  57. % vertical offset is 0 and the horizontal offset is 0.
  58. %
  59. % vdilexpan -i ball.xv -vs 2 -hs 2 -voff 0 -hoff 0 -o outimage.xv
  60. %
  61. % will do the expansion (dilation) of the input image "ball.xv" by the
  62. % structuring element reduced to the singleton containing the origin and
  63. % the resulting image will be "outimage.xv". The vertical scale factor
  64. % is 2, the horizontal scale factor is 2, the vertical offset is 0 and
  65. % the horizontal offset is 0.
  66. % This option can be used to realize an expansion without internal dilation.
  67. % In this case a dilation (by a structuring element greater than the 3 x 3 square) or anything else (a median filter) can be used after the expansion.
  68. %
  69. % "SEE ALSO"
  70. % For a definition of conditionally translation invariant dilation see:
  71. % G. Banon and J. Barrera, "Set operator decomposition and conditionally translation invariant elementary operators", Workshop on Mathematical Morphology and its Applications to Signal Processing II, Fontainebleau, France, 7-9 September, 1994.
  72. %
  73. % For more details on Digital Topology see:
  74. % G. Banon and J. Barrera, "Bases da Morfologia Matematica para Analise de Imagens
  75. % binarias", IX Escola de Computacao, Recife, 1994.
  76. %
  77. % related routines are: veroexpan, vdilshrin, veroshrin
  78. %
  79. % RESTRICTIONS
  80. % .I vdilexpan
  81. % can be defined for all data types supported by Khoros, but at the moment it has been implemented just for unsigned char types.
  82. % The structuring elements are subsets of the 3 x 3 square centered at the origin.
  83. %
  84. % REFERENCES
  85. %
  86. % COPYRIGHT
  87. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  88. %
  89. function varargout = kvdilexpan(varargin)
  90. if nargin ==0
  91. Inputs={};arglist={'',''};
  92. elseif nargin ==1
  93. Inputs=varargin{1};arglist={'',''};
  94. elseif nargin ==2
  95. Inputs=varargin{1}; arglist=varargin{2};
  96. else error('Usage: [out1,..] = kvdilexpan(Inputs,arglist).');
  97. end
  98. if size(arglist,2)~=2
  99. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  100. end
  101. narglist={'i', '__input';'str', '__input';'vs', 2;'hs', 2;'voff', 0;'hoff', 0;'o', '__output'};
  102. maxval={0,1,0,0,0,0,0};
  103. minval={0,1,0,0,0,0,0};
  104. istoggle=[0,1,1,1,1,1,0];
  105. was_set=istoggle * 0;
  106. paramtype={'InputFile','InputFile','Integer','Integer','Integer','Integer','OutputFile'};
  107. % identify the input arrays and assign them to the arguments as stated by the user
  108. if ~iscell(Inputs)
  109. Inputs = {Inputs};
  110. end
  111. NumReqOutputs=1; nextinput=1; nextoutput=1;
  112. for ii=1:size(arglist,1)
  113. wasmatched=0;
  114. for jj=1:size(narglist,1)
  115. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  116. wasmatched = 1;
  117. was_set(jj) = 1;
  118. if strcmp(narglist{jj,2}, '__input')
  119. if (nextinput > length(Inputs))
  120. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  121. end
  122. narglist{jj,2} = 'OK_in';
  123. nextinput = nextinput + 1;
  124. elseif strcmp(narglist{jj,2}, '__output')
  125. if (nextoutput > nargout)
  126. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  127. end
  128. if (isempty(arglist{ii,2}))
  129. narglist{jj,2} = 'OK_out';
  130. else
  131. narglist{jj,2} = arglist{ii,2};
  132. end
  133. nextoutput = nextoutput + 1;
  134. if (minval{jj} == 0)
  135. NumReqOutputs = NumReqOutputs - 1;
  136. end
  137. elseif isstr(arglist{ii,2})
  138. narglist{jj,2} = arglist{ii,2};
  139. else
  140. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  141. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  142. end
  143. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  144. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  145. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  146. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  147. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  148. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  149. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  150. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  151. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  152. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  153. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  154. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  155. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  156. end
  157. end
  158. end
  159. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  160. narglist{jj,2} = arglist{ii,2};
  161. end
  162. end
  163. end
  164. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  165. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  166. end
  167. end
  168. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  169. for jj=1:size(narglist,1)
  170. if strcmp(paramtype{jj}, 'Toggle')
  171. if (narglist{jj,2} ==0)
  172. narglist{jj,1} = '';
  173. end;
  174. narglist{jj,2} = '';
  175. end;
  176. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  177. narglist{jj,1} = '';
  178. narglist{jj,2} = '';
  179. end;
  180. if strcmp(narglist{jj,2}, '__input')
  181. if (minval{jj} == 0) % meaning this input is required
  182. if (nextinput > size(Inputs))
  183. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  184. else
  185. narglist{jj,2} = 'OK_in';
  186. nextinput = nextinput + 1;
  187. end
  188. else % this is an optional input
  189. if (nextinput <= length(Inputs))
  190. narglist{jj,2} = 'OK_in';
  191. nextinput = nextinput + 1;
  192. else
  193. narglist{jj,1} = '';
  194. narglist{jj,2} = '';
  195. end;
  196. end;
  197. else
  198. if strcmp(narglist{jj,2}, '__output')
  199. if (minval{jj} == 0) % this is a required output
  200. if (nextoutput > nargout & nargout > 1)
  201. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  202. else
  203. narglist{jj,2} = 'OK_out';
  204. nextoutput = nextoutput + 1;
  205. NumReqOutputs = NumReqOutputs-1;
  206. end
  207. else % this is an optional output
  208. if (nargout - nextoutput >= NumReqOutputs)
  209. narglist{jj,2} = 'OK_out';
  210. nextoutput = nextoutput + 1;
  211. else
  212. narglist{jj,1} = '';
  213. narglist{jj,2} = '';
  214. end;
  215. end
  216. end
  217. end
  218. end
  219. if nargout
  220. varargout = cell(1,nargout);
  221. else
  222. varargout = cell(1,1);
  223. end
  224. global KhorosRoot
  225. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  226. w=['"' KhorosRoot];
  227. else
  228. if ispc
  229. w='"C:\Program Files\dip\khorosBin\';
  230. else
  231. [s,w] = system('which cantata');
  232. w=['"' w(1:end-8)];
  233. end
  234. end
  235. [varargout{:}]=callKhoros([w 'vdilexpan" '],Inputs,narglist);