PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kvcost.m

http://github.com/aludnam/MATLAB
Objective C | 201 lines | 198 code | 3 blank | 0 comment | 58 complexity | 483166eddcb1e67fc76c3f39cc71ef07 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvcost 'Compute Cost (Surface Arc Length) for Image (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vcost.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Image ', required: 'input image'
  6. % InputFile: m 'Mask Image ', optional: 'mask image'
  7. % Integer: x 'X coordinate of reference pixel', default: 0: 'X coordinate of reference pixel'
  8. % Integer: y 'Y coordinate of reference pixel', default: 0: 'Y coordinate of reference pixel'
  9. % OutputFile: o 'Output Image ', required: 'output image'
  10. %
  11. % Example: o = kvcost({i, m}, {'i','';'m','';'x',0;'y',0;'o',''})
  12. %
  13. % Khoros helpfile follows below:
  14. %
  15. % PROGRAM
  16. % vcost - Compute Cost (Surface Arc Length) for Image (K1)
  17. %
  18. % DESCRIPTION
  19. % .I vcost
  20. % computes the surface arc length from a given pixel location to every other
  21. % pixel in the image. The surface distance from a particular pixel to
  22. % the reference pixel location is stored in the corresponding location in
  23. % the output image. Image pixels are resampled at 1/10 of their spacing
  24. % using bilinear interpolation for use in forming the surface profile between
  25. % any two points. This provides an surface distance accurate to around 1% for
  26. % relatively smooth images. An image with very sharp transitions or other
  27. % high frequencies will produce less accurate results.
  28. %
  29. % If the mask image is used, then only those pixels that have
  30. % a non-zero value at the corresponding pixel in the mask will be
  31. % evaluated for surface distance. All other output pixels are set to -1.
  32. %
  33. % The output is of type float.
  34. %
  35. %
  36. %
  37. % EXAMPLES
  38. %
  39. % % vcost -i surface -o dist -x 16 -y 21
  40. %
  41. % "SEE ALSO"
  42. %
  43. % RESTRICTIONS
  44. % .I lvcost
  45. % works on all data types.
  46. %
  47. % REFERENCES
  48. %
  49. % COPYRIGHT
  50. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  51. %
  52. function varargout = kvcost(varargin)
  53. if nargin ==0
  54. Inputs={};arglist={'',''};
  55. elseif nargin ==1
  56. Inputs=varargin{1};arglist={'',''};
  57. elseif nargin ==2
  58. Inputs=varargin{1}; arglist=varargin{2};
  59. else error('Usage: [out1,..] = kvcost(Inputs,arglist).');
  60. end
  61. if size(arglist,2)~=2
  62. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  63. end
  64. narglist={'i', '__input';'m', '__input';'x', 0;'y', 0;'o', '__output'};
  65. maxval={0,1,0,0,0};
  66. minval={0,1,0,0,0};
  67. istoggle=[0,1,1,1,0];
  68. was_set=istoggle * 0;
  69. paramtype={'InputFile','InputFile','Integer','Integer','OutputFile'};
  70. % identify the input arrays and assign them to the arguments as stated by the user
  71. if ~iscell(Inputs)
  72. Inputs = {Inputs};
  73. end
  74. NumReqOutputs=1; nextinput=1; nextoutput=1;
  75. for ii=1:size(arglist,1)
  76. wasmatched=0;
  77. for jj=1:size(narglist,1)
  78. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  79. wasmatched = 1;
  80. was_set(jj) = 1;
  81. if strcmp(narglist{jj,2}, '__input')
  82. if (nextinput > length(Inputs))
  83. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  84. end
  85. narglist{jj,2} = 'OK_in';
  86. nextinput = nextinput + 1;
  87. elseif strcmp(narglist{jj,2}, '__output')
  88. if (nextoutput > nargout)
  89. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  90. end
  91. if (isempty(arglist{ii,2}))
  92. narglist{jj,2} = 'OK_out';
  93. else
  94. narglist{jj,2} = arglist{ii,2};
  95. end
  96. nextoutput = nextoutput + 1;
  97. if (minval{jj} == 0)
  98. NumReqOutputs = NumReqOutputs - 1;
  99. end
  100. elseif isstr(arglist{ii,2})
  101. narglist{jj,2} = arglist{ii,2};
  102. else
  103. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  104. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  105. end
  106. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  107. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  108. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  109. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  110. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  111. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  112. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  113. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  114. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  115. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  116. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  117. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  118. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  119. end
  120. end
  121. end
  122. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  123. narglist{jj,2} = arglist{ii,2};
  124. end
  125. end
  126. end
  127. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  128. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  129. end
  130. end
  131. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  132. for jj=1:size(narglist,1)
  133. if strcmp(paramtype{jj}, 'Toggle')
  134. if (narglist{jj,2} ==0)
  135. narglist{jj,1} = '';
  136. end;
  137. narglist{jj,2} = '';
  138. end;
  139. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  140. narglist{jj,1} = '';
  141. narglist{jj,2} = '';
  142. end;
  143. if strcmp(narglist{jj,2}, '__input')
  144. if (minval{jj} == 0) % meaning this input is required
  145. if (nextinput > size(Inputs))
  146. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  147. else
  148. narglist{jj,2} = 'OK_in';
  149. nextinput = nextinput + 1;
  150. end
  151. else % this is an optional input
  152. if (nextinput <= length(Inputs))
  153. narglist{jj,2} = 'OK_in';
  154. nextinput = nextinput + 1;
  155. else
  156. narglist{jj,1} = '';
  157. narglist{jj,2} = '';
  158. end;
  159. end;
  160. else
  161. if strcmp(narglist{jj,2}, '__output')
  162. if (minval{jj} == 0) % this is a required output
  163. if (nextoutput > nargout & nargout > 1)
  164. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  165. else
  166. narglist{jj,2} = 'OK_out';
  167. nextoutput = nextoutput + 1;
  168. NumReqOutputs = NumReqOutputs-1;
  169. end
  170. else % this is an optional output
  171. if (nargout - nextoutput >= NumReqOutputs)
  172. narglist{jj,2} = 'OK_out';
  173. nextoutput = nextoutput + 1;
  174. else
  175. narglist{jj,1} = '';
  176. narglist{jj,2} = '';
  177. end;
  178. end
  179. end
  180. end
  181. end
  182. if nargout
  183. varargout = cell(1,nargout);
  184. else
  185. varargout = cell(1,1);
  186. end
  187. global KhorosRoot
  188. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  189. w=['"' KhorosRoot];
  190. else
  191. if ispc
  192. w='"C:\Program Files\dip\khorosBin\';
  193. else
  194. [s,w] = system('which cantata');
  195. w=['"' w(1:end-8)];
  196. end
  197. end
  198. [varargout{:}]=callKhoros([w 'vcost" '],Inputs,narglist);