PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/matlab_tools/Converted/kvgettilt.m

http://github.com/aludnam/MATLAB
Objective C | 197 lines | 194 code | 3 blank | 0 comment | 57 complexity | e85b02aea88cb06e4a1d6f16d5fb2a27 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvgettilt 'Compute the Best-Fit Plane Parameters for Input File (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vgettilt.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Image ', required: 'input image'
  6. % InputFile: m 'Masking Image', optional: 'statistics operation masking image'
  7. % OutputFile: f 'Ouput ASCII File', required: 'output ASCII file'
  8. %
  9. % Example: f = kvgettilt({i, m}, {'i','';'m','';'f',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % vgettilt - Compute the Best-Fit Plane Parameters for Input File (K1)
  15. %
  16. % DESCRIPTION
  17. % "vgettilt"
  18. % computes the least-squares best fit plane for an image.
  19. % The plane will be given by f(x,y)=Ax+By+C
  20. % with the tilt coefficients in inverse pixels.
  21. %
  22. % If the mask file is specified then only those points in the input image with
  23. % a corresponding nonzero mask file pixel are used in the computation. The
  24. % number of points actually contributing to the computation is given with the
  25. % output data.
  26. %
  27. % The output device or file is specified after the -f option, a filename
  28. % of # will send the output to stderr.
  29. %
  30. %
  31. %
  32. % EXAMPLES
  33. % vgettilt -i input -f tilt_info -m mask
  34. %
  35. % "SEE ALSO"
  36. % vtilt, vdetilt
  37. %
  38. % RESTRICTIONS
  39. % "vgettilt"
  40. % will not operate on bit or complex
  41. % data storage types, and will not work on multiband images.
  42. %
  43. % REFERENCES
  44. %
  45. % COPYRIGHT
  46. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  47. %
  48. function varargout = kvgettilt(varargin)
  49. if nargin ==0
  50. Inputs={};arglist={'',''};
  51. elseif nargin ==1
  52. Inputs=varargin{1};arglist={'',''};
  53. elseif nargin ==2
  54. Inputs=varargin{1}; arglist=varargin{2};
  55. else error('Usage: [out1,..] = kvgettilt(Inputs,arglist).');
  56. end
  57. if size(arglist,2)~=2
  58. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  59. end
  60. narglist={'i', '__input';'m', '__input';'f', '__output'};
  61. maxval={0,1,0};
  62. minval={0,1,0};
  63. istoggle=[0,1,0];
  64. was_set=istoggle * 0;
  65. paramtype={'InputFile','InputFile','OutputFile'};
  66. % identify the input arrays and assign them to the arguments as stated by the user
  67. if ~iscell(Inputs)
  68. Inputs = {Inputs};
  69. end
  70. NumReqOutputs=1; nextinput=1; nextoutput=1;
  71. for ii=1:size(arglist,1)
  72. wasmatched=0;
  73. for jj=1:size(narglist,1)
  74. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  75. wasmatched = 1;
  76. was_set(jj) = 1;
  77. if strcmp(narglist{jj,2}, '__input')
  78. if (nextinput > length(Inputs))
  79. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  80. end
  81. narglist{jj,2} = 'OK_in';
  82. nextinput = nextinput + 1;
  83. elseif strcmp(narglist{jj,2}, '__output')
  84. if (nextoutput > nargout)
  85. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  86. end
  87. if (isempty(arglist{ii,2}))
  88. narglist{jj,2} = 'OK_out';
  89. else
  90. narglist{jj,2} = arglist{ii,2};
  91. end
  92. nextoutput = nextoutput + 1;
  93. if (minval{jj} == 0)
  94. NumReqOutputs = NumReqOutputs - 1;
  95. end
  96. elseif isstr(arglist{ii,2})
  97. narglist{jj,2} = arglist{ii,2};
  98. else
  99. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  100. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  101. end
  102. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  103. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  104. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  105. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  106. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  107. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  108. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  109. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  110. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  111. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  112. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  113. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  114. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  115. end
  116. end
  117. end
  118. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  119. narglist{jj,2} = arglist{ii,2};
  120. end
  121. end
  122. end
  123. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  124. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  125. end
  126. end
  127. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  128. for jj=1:size(narglist,1)
  129. if strcmp(paramtype{jj}, 'Toggle')
  130. if (narglist{jj,2} ==0)
  131. narglist{jj,1} = '';
  132. end;
  133. narglist{jj,2} = '';
  134. end;
  135. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  136. narglist{jj,1} = '';
  137. narglist{jj,2} = '';
  138. end;
  139. if strcmp(narglist{jj,2}, '__input')
  140. if (minval{jj} == 0) % meaning this input is required
  141. if (nextinput > size(Inputs))
  142. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  143. else
  144. narglist{jj,2} = 'OK_in';
  145. nextinput = nextinput + 1;
  146. end
  147. else % this is an optional input
  148. if (nextinput <= length(Inputs))
  149. narglist{jj,2} = 'OK_in';
  150. nextinput = nextinput + 1;
  151. else
  152. narglist{jj,1} = '';
  153. narglist{jj,2} = '';
  154. end;
  155. end;
  156. else
  157. if strcmp(narglist{jj,2}, '__output')
  158. if (minval{jj} == 0) % this is a required output
  159. if (nextoutput > nargout & nargout > 1)
  160. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  161. else
  162. narglist{jj,2} = 'OK_out';
  163. nextoutput = nextoutput + 1;
  164. NumReqOutputs = NumReqOutputs-1;
  165. end
  166. else % this is an optional output
  167. if (nargout - nextoutput >= NumReqOutputs)
  168. narglist{jj,2} = 'OK_out';
  169. nextoutput = nextoutput + 1;
  170. else
  171. narglist{jj,1} = '';
  172. narglist{jj,2} = '';
  173. end;
  174. end
  175. end
  176. end
  177. end
  178. if nargout
  179. varargout = cell(1,nargout);
  180. else
  181. varargout = cell(1,1);
  182. end
  183. global KhorosRoot
  184. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  185. w=['"' KhorosRoot];
  186. else
  187. if ispc
  188. w='"C:\Program Files\dip\khorosBin\';
  189. else
  190. [s,w] = system('which cantata');
  191. w=['"' w(1:end-8)];
  192. end
  193. end
  194. [varargout{:}]=callKhoros([w 'vgettilt" '],Inputs,narglist);