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

/matlab_tools/Converted/kvcondthin.m

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