PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvclose.m

http://github.com/aludnam/MATLAB
Objective C | 215 lines | 212 code | 3 blank | 0 comment | 55 complexity | af1ee29528256e00d756d5cbce14f66e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvclose 'Close Boundaries of an Edge Image (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vclose.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Boundary Image', required: 'Input Boundary Image (result from vdrf, vgef, vsdef ...)'
  6. % InputFile: i2 'Input Gradient Image', required: 'Input Gradient Image (result from vdrf, vsdef, sobel...)'
  7. % Integer: grad 'Gradient Threshold ', default: 0: 'Gradient Threshold (used by the closing process)'
  8. % Integer: len 'Minimum Gap Size ', default: 1: 'Minimum Gap Size In Pixels'
  9. % OutputFile: o 'Output Image ', required: 'resulting output image or file'
  10. %
  11. % Example: o = kvclose({i1, i2}, {'i1','';'i2','';'grad',0;'len',1;'o',''})
  12. %
  13. % Khoros helpfile follows below:
  14. %
  15. % PROGRAM
  16. % vclose - Close Boundaries of an Edge Image (K1)
  17. %
  18. % DESCRIPTION
  19. % .I vclose
  20. % uses a boundary image and a gradient image as input. Then it tries to close
  21. % the boundaries by following the maximum gradient between two end points of
  22. % two contours.
  23. %
  24. % The new closing part is kept if its length is at least
  25. % "Minimum_Gap_Size" pixels. This parameter is used to prevent the result
  26. % from being covered by small contours (edges of noisy areas...).
  27. %
  28. % The minimum gradient value "Gradient_Threshold" has to be set up to
  29. % indicate to the closing process up to what value it can follow a maximum
  30. % gradient curve to close a boundary.
  31. %
  32. % This Algorithm has been written by:
  33. %
  34. %
  35. % Professor SERGE CASTAN, Prof CHEN and Dr ZHAO
  36. %
  37. %
  38. % IRIT, CNRS, URA 1399
  39. %
  40. %
  41. % 118, route de Narbonne 31062 Toulouse FRANCE
  42. %
  43. %
  44. %
  45. %
  46. % EXAMPLES
  47. % vclose -i1 moon_edge.xv -i2 moon_grad.xv -v 5 -f 0.5 -o closed_boundary.xv
  48. %
  49. % Will use moon_edge.xv and moon_grad.xv as the edges and respectively
  50. % the gradient representation of an image. Then it will close the unclosed
  51. % boundaries using a minimum gap size of 5 pixels and a gradient threshold of 0.5
  52. %
  53. % "SEE ALSO"
  54. %
  55. % RESTRICTIONS
  56. % .I vclose
  57. % will only work with single band images. Then the first image has to be of data
  58. % storage type VFF_TYP_1_BYTE. The second input can be anything from VFF_TYP_1_BYTE
  59. % to VFF_TYP_FLOAT.
  60. %
  61. % REFERENCES
  62. %
  63. % COPYRIGHT
  64. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  65. %
  66. function varargout = kvclose(varargin)
  67. if nargin ==0
  68. Inputs={};arglist={'',''};
  69. elseif nargin ==1
  70. Inputs=varargin{1};arglist={'',''};
  71. elseif nargin ==2
  72. Inputs=varargin{1}; arglist=varargin{2};
  73. else error('Usage: [out1,..] = kvclose(Inputs,arglist).');
  74. end
  75. if size(arglist,2)~=2
  76. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  77. end
  78. narglist={'i1', '__input';'i2', '__input';'grad', 0;'len', 1;'o', '__output'};
  79. maxval={0,0,1,1,0};
  80. minval={0,0,1,1,0};
  81. istoggle=[0,0,1,1,0];
  82. was_set=istoggle * 0;
  83. paramtype={'InputFile','InputFile','Integer','Integer','OutputFile'};
  84. % identify the input arrays and assign them to the arguments as stated by the user
  85. if ~iscell(Inputs)
  86. Inputs = {Inputs};
  87. end
  88. NumReqOutputs=1; nextinput=1; nextoutput=1;
  89. for ii=1:size(arglist,1)
  90. wasmatched=0;
  91. for jj=1:size(narglist,1)
  92. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  93. wasmatched = 1;
  94. was_set(jj) = 1;
  95. if strcmp(narglist{jj,2}, '__input')
  96. if (nextinput > length(Inputs))
  97. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  98. end
  99. narglist{jj,2} = 'OK_in';
  100. nextinput = nextinput + 1;
  101. elseif strcmp(narglist{jj,2}, '__output')
  102. if (nextoutput > nargout)
  103. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  104. end
  105. if (isempty(arglist{ii,2}))
  106. narglist{jj,2} = 'OK_out';
  107. else
  108. narglist{jj,2} = arglist{ii,2};
  109. end
  110. nextoutput = nextoutput + 1;
  111. if (minval{jj} == 0)
  112. NumReqOutputs = NumReqOutputs - 1;
  113. end
  114. elseif isstr(arglist{ii,2})
  115. narglist{jj,2} = arglist{ii,2};
  116. else
  117. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  118. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  119. end
  120. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  121. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  122. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  123. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  124. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  125. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  126. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  127. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  128. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  129. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  130. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  131. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  132. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  133. end
  134. end
  135. end
  136. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  137. narglist{jj,2} = arglist{ii,2};
  138. end
  139. end
  140. end
  141. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  142. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  143. end
  144. end
  145. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  146. for jj=1:size(narglist,1)
  147. if strcmp(paramtype{jj}, 'Toggle')
  148. if (narglist{jj,2} ==0)
  149. narglist{jj,1} = '';
  150. end;
  151. narglist{jj,2} = '';
  152. end;
  153. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  154. narglist{jj,1} = '';
  155. narglist{jj,2} = '';
  156. end;
  157. if strcmp(narglist{jj,2}, '__input')
  158. if (minval{jj} == 0) % meaning this input is required
  159. if (nextinput > size(Inputs))
  160. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  161. else
  162. narglist{jj,2} = 'OK_in';
  163. nextinput = nextinput + 1;
  164. end
  165. else % this is an optional input
  166. if (nextinput <= length(Inputs))
  167. narglist{jj,2} = 'OK_in';
  168. nextinput = nextinput + 1;
  169. else
  170. narglist{jj,1} = '';
  171. narglist{jj,2} = '';
  172. end;
  173. end;
  174. else
  175. if strcmp(narglist{jj,2}, '__output')
  176. if (minval{jj} == 0) % this is a required output
  177. if (nextoutput > nargout & nargout > 1)
  178. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  179. else
  180. narglist{jj,2} = 'OK_out';
  181. nextoutput = nextoutput + 1;
  182. NumReqOutputs = NumReqOutputs-1;
  183. end
  184. else % this is an optional output
  185. if (nargout - nextoutput >= NumReqOutputs)
  186. narglist{jj,2} = 'OK_out';
  187. nextoutput = nextoutput + 1;
  188. else
  189. narglist{jj,1} = '';
  190. narglist{jj,2} = '';
  191. end;
  192. end
  193. end
  194. end
  195. end
  196. if nargout
  197. varargout = cell(1,nargout);
  198. else
  199. varargout = cell(1,1);
  200. end
  201. global KhorosRoot
  202. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  203. w=['"' KhorosRoot];
  204. else
  205. if ispc
  206. w='"C:\Program Files\dip\khorosBin\';
  207. else
  208. [s,w] = system('which cantata');
  209. w=['"' w(1:end-8)];
  210. end
  211. end
  212. [varargout{:}]=callKhoros([w 'vclose" '],Inputs,narglist);