PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/krp_affine.m

http://github.com/aludnam/MATLAB
Objective C | 192 lines | 189 code | 3 blank | 0 comment | 56 complexity | 3432f33974992a360a5055309c3df505 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %krp_affine 'compute igeowarp coefficients by linear regression of point lists'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros rp_affine.pane file
  3. %
  4. % Parameters:
  5. % InputFile: iref 'Reference Image', required: 'reference image'
  6. % InputFile: idist 'Distorted Image', required: 'distorted image'
  7. % OutputFile: owc 'Width Coeffs', required: 'width igeowarp coeffs file'
  8. % OutputFile: ohc 'Height Coeffs', required: 'height igeowarp coeffs file'
  9. %
  10. % Example: [owc, ohc] = krp_affine({iref, idist}, {'iref','';'idist','';'owc','';'ohc',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % rp_affine - compute igeowarp coefficients by linear regression of point lists
  16. %
  17. % DESCRIPTION
  18. % This routine finds the coefficients for a generalized affine transform
  19. % that transforms the control points from a distorted image to the
  20. % control points from the reference image. In particular, it generates
  21. % coefficient files suitable for input to the igeowarp program. You may
  22. % optionally set any of the parameters to fixed values.
  23. %
  24. % Fitting is accomplished by linear regression (which implies minimizing
  25. % the sum of squared errors). The system of equations are solved with
  26. % singular value decomposition.
  27. %
  28. %
  29. %
  30. % EXAMPLES
  31. % See the html tutorial in $REGISTER/examples/html/README_FIRST.html
  32. %
  33. % "SEE ALSO"
  34. % igeowarp(1)
  35. %
  36. % RESTRICTIONS
  37. %
  38. % REFERENCES
  39. %
  40. % COPYRIGHT
  41. % Copyright (C) 1996 - 1997, University of New Mexico. All rights reserved.
  42. %
  43. function varargout = krp_affine(varargin)
  44. if nargin ==0
  45. Inputs={};arglist={'',''};
  46. elseif nargin ==1
  47. Inputs=varargin{1};arglist={'',''};
  48. elseif nargin ==2
  49. Inputs=varargin{1}; arglist=varargin{2};
  50. else error('Usage: [out1,..] = krp_affine(Inputs,arglist).');
  51. end
  52. if size(arglist,2)~=2
  53. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  54. end
  55. narglist={'iref', '__input';'idist', '__input';'owc', '__output';'ohc', '__output'};
  56. maxval={0,0,0,0};
  57. minval={0,0,0,0};
  58. istoggle=[0,0,0,0];
  59. was_set=istoggle * 0;
  60. paramtype={'InputFile','InputFile','OutputFile','OutputFile'};
  61. % identify the input arrays and assign them to the arguments as stated by the user
  62. if ~iscell(Inputs)
  63. Inputs = {Inputs};
  64. end
  65. NumReqOutputs=2; nextinput=1; nextoutput=1;
  66. for ii=1:size(arglist,1)
  67. wasmatched=0;
  68. for jj=1:size(narglist,1)
  69. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  70. wasmatched = 1;
  71. was_set(jj) = 1;
  72. if strcmp(narglist{jj,2}, '__input')
  73. if (nextinput > length(Inputs))
  74. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  75. end
  76. narglist{jj,2} = 'OK_in';
  77. nextinput = nextinput + 1;
  78. elseif strcmp(narglist{jj,2}, '__output')
  79. if (nextoutput > nargout)
  80. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  81. end
  82. if (isempty(arglist{ii,2}))
  83. narglist{jj,2} = 'OK_out';
  84. else
  85. narglist{jj,2} = arglist{ii,2};
  86. end
  87. nextoutput = nextoutput + 1;
  88. if (minval{jj} == 0)
  89. NumReqOutputs = NumReqOutputs - 1;
  90. end
  91. elseif isstr(arglist{ii,2})
  92. narglist{jj,2} = arglist{ii,2};
  93. else
  94. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  95. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  96. end
  97. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  98. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  99. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  100. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  101. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  102. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  103. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  104. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  105. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  106. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  107. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  108. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  109. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  110. end
  111. end
  112. end
  113. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  114. narglist{jj,2} = arglist{ii,2};
  115. end
  116. end
  117. end
  118. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  119. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  120. end
  121. end
  122. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  123. for jj=1:size(narglist,1)
  124. if strcmp(paramtype{jj}, 'Toggle')
  125. if (narglist{jj,2} ==0)
  126. narglist{jj,1} = '';
  127. end;
  128. narglist{jj,2} = '';
  129. end;
  130. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  131. narglist{jj,1} = '';
  132. narglist{jj,2} = '';
  133. end;
  134. if strcmp(narglist{jj,2}, '__input')
  135. if (minval{jj} == 0) % meaning this input is required
  136. if (nextinput > size(Inputs))
  137. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  138. else
  139. narglist{jj,2} = 'OK_in';
  140. nextinput = nextinput + 1;
  141. end
  142. else % this is an optional input
  143. if (nextinput <= length(Inputs))
  144. narglist{jj,2} = 'OK_in';
  145. nextinput = nextinput + 1;
  146. else
  147. narglist{jj,1} = '';
  148. narglist{jj,2} = '';
  149. end;
  150. end;
  151. else
  152. if strcmp(narglist{jj,2}, '__output')
  153. if (minval{jj} == 0) % this is a required output
  154. if (nextoutput > nargout & nargout > 1)
  155. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  156. else
  157. narglist{jj,2} = 'OK_out';
  158. nextoutput = nextoutput + 1;
  159. NumReqOutputs = NumReqOutputs-1;
  160. end
  161. else % this is an optional output
  162. if (nargout - nextoutput >= NumReqOutputs)
  163. narglist{jj,2} = 'OK_out';
  164. nextoutput = nextoutput + 1;
  165. else
  166. narglist{jj,1} = '';
  167. narglist{jj,2} = '';
  168. end;
  169. end
  170. end
  171. end
  172. end
  173. if nargout
  174. varargout = cell(1,nargout);
  175. else
  176. varargout = cell(1,1);
  177. end
  178. global KhorosRoot
  179. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  180. w=['"' KhorosRoot];
  181. else
  182. if ispc
  183. w='"C:\Program Files\dip\khorosBin\';
  184. else
  185. [s,w] = system('which cantata');
  186. w=['"' w(1:end-8)];
  187. end
  188. end
  189. [varargout{:}]=callKhoros([w 'rp_affine" '],Inputs,narglist);