PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kigeowarp.m

http://github.com/aludnam/MATLAB
Objective C | 245 lines | 242 code | 3 blank | 0 comment | 60 complexity | e1c01781dae2e7f91965cc4b533658ff MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kigeowarp 'Perform Direct Bilinear Geometric Warping'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros igeowarp.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input ', required: 'Input data object'
  6. % Toggle: planes 'Process by planes', default: 0: 'Process data by full planes instead of small prisms'
  7. % OutputFile: o 'Output', required: 'Output data object'
  8. % InputFile: wcoeffs 'W warp coeffs object', optional: 'W warp function coeffs object'
  9. % InputFile: hcoeffs 'H warp coeffs object', optional: 'H warp function coeffs object'
  10. %
  11. % Example: o = kigeowarp({i, wcoeffs, hcoeffs}, {'i','';'planes',0;'o','';'wcoeffs','';'hcoeffs',''})
  12. %
  13. % Khoros helpfile follows below:
  14. %
  15. % PROGRAM
  16. % igeowarp - Perform Direct Bilinear Geometric Warping
  17. %
  18. % DESCRIPTION
  19. % .I igeowarp
  20. % is used to apply a direct bilinear warping to an image. In this mode, the
  21. % bilinear mapping equations give the mapping of output data coordinates to
  22. % input data coordinates. A given output data coordinate is operated on by the
  23. % mapping functions to give the input data coordinate. The value of the input
  24. % data coordinate is interpolated using bilinear interpolation, and the resulting
  25. % value is assigned to the output data coordinate.
  26. %
  27. % All warping is assumed to occur only in the WxH plane.
  28. % If warping in a different plane is desired, it is necessary to use the kaxis
  29. % program to reorient the data such that the desired plane is the WxH plane before
  30. % applying igeowarp. This limitation is due to computational complexity and
  31. % performance issues, particularly when dealing with large data sets.
  32. %
  33. % The mapping functions used by igeowarp are:
  34. %
  35. %
  36. % f(w,h) = output image
  37. %
  38. % g(w',h') = input image coordinate
  39. %
  40. % w' = a00 + a01*w + a10*h +a11*w*h
  41. % h' = b00 + b01*w + b10*h +b11*w*h
  42. %
  43. %
  44. % Note that in general, w' and h' are not integers for a given integer pair
  45. % w and h. The
  46. % data value at g(w',h') is obtained by bilinear interpolation of the four
  47. % nearest neighbors to coordinate (w',h').
  48. %
  49. % The mapping is called direct because it directly gives the location in the
  50. % input data that corresponds to a given location in the output data. The
  51. % opposite case gives the location in the output data that corresponds to a
  52. % given input data location; this requires much trickier and computationally
  53. % expensive interpolation methods to obtain good results.
  54. %
  55. % The input parameters a00, a01, a10, a11, b00, b01, b10, b11 are exactly as
  56. % specified in the mapping functions above. These parameters can also be supplied
  57. % in the form of object value data where the data is assumed to be organized with
  58. % the parameters a00, a01, a10, and a11 present in that storage order for the
  59. % W coefficients and likewise for the H coefficients.
  60. %
  61. % If the input object has a mask, a new mask will be computed for the output
  62. % object indicating which data points contain reliable data.
  63. %
  64. % If the input object has a map, the data is pulled through the map prior to
  65. % rotation, and the output object will have no map.
  66. %
  67. % The -planes flag is used to change the way the data is accessed for processing.
  68. % If the data set is small enough that individual planes of data (including the
  69. % E data) parallel to the WxH plane will fit in memory, then use of the -planes
  70. % flag will permit processing to happen in a plane-by-plane basis; this can
  71. % occur with efficiency and speed. Otherwise,
  72. % processing will occur in prisms down the D axis, which is much slower but will
  73. % work on data sets of any size. If you have lots of memory, you may be able to
  74. % get away with using -planes even for quite large data sets, say around 2Kx2K
  75. % or more points per plane.
  76. %
  77. %
  78. %
  79. % EXAMPLES
  80. %
  81. % "SEE ALSO"
  82. % irotate(1)
  83. %
  84. % RESTRICTIONS
  85. %
  86. % For this initial release, the E dimension data is "not\fR handled
  87. % correctly. Data in WxHxD "is\fR handled correctly. This deficiency
  88. % will be corrected in the next version of
  89. % .I igeowarp.
  90. %
  91. % REFERENCES
  92. %
  93. % COPYRIGHT
  94. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  95. %
  96. function varargout = kigeowarp(varargin)
  97. if nargin ==0
  98. Inputs={};arglist={'',''};
  99. elseif nargin ==1
  100. Inputs=varargin{1};arglist={'',''};
  101. elseif nargin ==2
  102. Inputs=varargin{1}; arglist=varargin{2};
  103. else error('Usage: [out1,..] = kigeowarp(Inputs,arglist).');
  104. end
  105. if size(arglist,2)~=2
  106. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  107. end
  108. narglist={'i', '__input';'planes', 0;'o', '__output';'wcoeffs', '__input';'hcoeffs', '__input'};
  109. maxval={0,0,0,1,1};
  110. minval={0,0,0,1,1};
  111. istoggle=[0,1,0,1,1];
  112. was_set=istoggle * 0;
  113. paramtype={'InputFile','Toggle','OutputFile','InputFile','InputFile'};
  114. % identify the input arrays and assign them to the arguments as stated by the user
  115. if ~iscell(Inputs)
  116. Inputs = {Inputs};
  117. end
  118. NumReqOutputs=1; nextinput=1; nextoutput=1;
  119. for ii=1:size(arglist,1)
  120. wasmatched=0;
  121. for jj=1:size(narglist,1)
  122. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  123. wasmatched = 1;
  124. was_set(jj) = 1;
  125. if strcmp(narglist{jj,2}, '__input')
  126. if (nextinput > length(Inputs))
  127. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  128. end
  129. narglist{jj,2} = 'OK_in';
  130. nextinput = nextinput + 1;
  131. elseif strcmp(narglist{jj,2}, '__output')
  132. if (nextoutput > nargout)
  133. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  134. end
  135. if (isempty(arglist{ii,2}))
  136. narglist{jj,2} = 'OK_out';
  137. else
  138. narglist{jj,2} = arglist{ii,2};
  139. end
  140. nextoutput = nextoutput + 1;
  141. if (minval{jj} == 0)
  142. NumReqOutputs = NumReqOutputs - 1;
  143. end
  144. elseif isstr(arglist{ii,2})
  145. narglist{jj,2} = arglist{ii,2};
  146. else
  147. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  148. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  149. end
  150. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  151. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  152. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  153. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  154. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  155. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  156. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  157. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  158. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  159. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  160. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  161. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  162. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  163. end
  164. end
  165. end
  166. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  167. narglist{jj,2} = arglist{ii,2};
  168. end
  169. end
  170. end
  171. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  172. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  173. end
  174. end
  175. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  176. for jj=1:size(narglist,1)
  177. if strcmp(paramtype{jj}, 'Toggle')
  178. if (narglist{jj,2} ==0)
  179. narglist{jj,1} = '';
  180. end;
  181. narglist{jj,2} = '';
  182. end;
  183. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  184. narglist{jj,1} = '';
  185. narglist{jj,2} = '';
  186. end;
  187. if strcmp(narglist{jj,2}, '__input')
  188. if (minval{jj} == 0) % meaning this input is required
  189. if (nextinput > size(Inputs))
  190. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  191. else
  192. narglist{jj,2} = 'OK_in';
  193. nextinput = nextinput + 1;
  194. end
  195. else % this is an optional input
  196. if (nextinput <= length(Inputs))
  197. narglist{jj,2} = 'OK_in';
  198. nextinput = nextinput + 1;
  199. else
  200. narglist{jj,1} = '';
  201. narglist{jj,2} = '';
  202. end;
  203. end;
  204. else
  205. if strcmp(narglist{jj,2}, '__output')
  206. if (minval{jj} == 0) % this is a required output
  207. if (nextoutput > nargout & nargout > 1)
  208. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  209. else
  210. narglist{jj,2} = 'OK_out';
  211. nextoutput = nextoutput + 1;
  212. NumReqOutputs = NumReqOutputs-1;
  213. end
  214. else % this is an optional output
  215. if (nargout - nextoutput >= NumReqOutputs)
  216. narglist{jj,2} = 'OK_out';
  217. nextoutput = nextoutput + 1;
  218. else
  219. narglist{jj,1} = '';
  220. narglist{jj,2} = '';
  221. end;
  222. end
  223. end
  224. end
  225. end
  226. if nargout
  227. varargout = cell(1,nargout);
  228. else
  229. varargout = cell(1,1);
  230. end
  231. global KhorosRoot
  232. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  233. w=['"' KhorosRoot];
  234. else
  235. if ispc
  236. w='"C:\Program Files\dip\khorosBin\';
  237. else
  238. [s,w] = system('which cantata');
  239. w=['"' w(1:end-8)];
  240. end
  241. end
  242. [varargout{:}]=callKhoros([w 'igeowarp" '],Inputs,narglist);