PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkmwt.m

http://github.com/aludnam/MATLAB
Objective C | 248 lines | 248 code | 0 blank | 0 comment | 3 complexity | 234fd26ab7d0c6092a906f379d298966 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkmwt '5D multlevel wavelet transform'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kmwt.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Object ', required: 'Input object filename '
  6. % InputFile: fh 'Highpass', required: 'Input highpass filter coefficients'
  7. % InputFile: fl 'Lowpass ', required: 'Input lowpass filter coefficients'
  8. % OutputFile: o 'Output Object ', required: 'Output object filename'
  9. % Toggle: w 'Width', default: 0: 'filter in the WIDTH direction'
  10. % Toggle: h 'Height', default: 0: 'filter in the HEIGHT direction'
  11. % Toggle: d 'Depth', default: 0: 'filter in the DEPTH direction'
  12. % Toggle: t 'Time', default: 0: 'filter in the TIME direction'
  13. % Toggle: e 'Elements', default: 0: 'filter in the ELEMENTS direction'
  14. % MultiChoice: dir 'Transform Selection', default: 1: 'Transform direction selection'
  15. % Choices are:
  16. % 1: 'Direct'
  17. % 2: 'Inverse'
  18. % Integer: l 'Levels ', default: 1: 'Number of levels for decomposition'
  19. % Toggle: tinv 'Total Inverse (for wavelet objects only)', default: 1: 'Select transform direction to total'
  20. %
  21. % Example: o = kkmwt({i, fh, fl}, {'i','';'fh','';'fl','';'o','';'w',0;'h',0;'d',0;'t',0;'e',0;'dir',1;'l',1;'tinv',1})
  22. %
  23. % Khoros helpfile follows below:
  24. %
  25. % PROGRAM
  26. % kmwt - Performs multlevel wavelet transforms
  27. %
  28. % DESCRIPTION
  29. % \flkmwt" performs wavelet decomposition of the input object defined
  30. % by \fBInput" in any dimension or combination of the 5 dimensions, and
  31. % with a number of layers defined by the user. The filters for both
  32. % transform directions (forward and inverse) are defined by
  33. % \fBHighpass" for the highpass filter and \fBLowpass\fP for the
  34. % lowpass filter. These filter must be defined acordlingly to the
  35. % transform direction. The output object of "kmwt" corresponds to
  36. % the coefficients of the wavelet expansion. Default values are: width
  37. % and height dimensions, transform direction forward and number of layers
  38. % equal to one. If the direct transform is carried out by "kmwt" the
  39. % inverse transform can be performed by using the flag Total Inverse. In
  40. % this case the user do not need to define the number of layers.
  41. %
  42. % The "kmwt" routine uses tensorial product to perform the multidimensional
  43. % wavelet transform in each level. That is, this wavelet
  44. % transform routine assumes separability (decoupling) in the multidimensional
  45. % case.
  46. %
  47. % "Data Type" 5
  48. % The "kmwt" routine accepts any kind of data type for the input
  49. % object, except complex. Internally "kmwt" casts the data of
  50. % input object to double before processing and changes the
  51. % destination object data type (output) accordingly. The data is
  52. % processed using double data type despite the data type of any source
  53. % object. Note that data is not casted to a lower type for processing.
  54. %
  55. % "Map Data" 5
  56. % If any source object contains map data as well as value data, then
  57. % "kmwt" removes the map. The destination object is always unmapped.
  58. %
  59. % "Mask, Time and Location Segments" 5
  60. % If any source object contains a mask, time or location segment, then an
  61. % error message is printed out. Mask, time and location segments have to
  62. % be removed before processing.
  63. %
  64. %
  65. %
  66. % EXAMPLES
  67. % 2D forward wavelet transform of a 2D object using daub_2_f_h (highpass
  68. % Daubechies filter, order 2, forward direction) as a highpass filter and
  69. % daub_2_f_l (lowpass Daubechies filter, order 2, forward direction) as a
  70. % lowpass filter and number of levels equal to 3.
  71. % kmwt -i image_input -w -h -fh daub_2_f_h -fl daub_2_f_l -dir 1 -o image_output -l 3
  72. % 2D inverse wavelet transform of a 2D object using daub_2_i_h (highpass
  73. % Daubechies filter, order 2, inverse direction) as a highpass filter and
  74. % daub_2_i_l (lowpass Daubechies filter, order 2, inverse direction) as a
  75. % lowpass filter and number of levels equal to 3.
  76. % kmwt -i image_input -w -h -fh daub_2_i_h -fl daub_2_i_l -dir 2 -o image_output -l 3
  77. %
  78. % "SEE ALSO"
  79. % kwt
  80. %
  81. % RESTRICTIONS
  82. % Dimension of data record must be a power of 2.
  83. %
  84. % REFERENCES
  85. % 1) WAVELETS ANALYSIS AND ITS APPLICATIONS, Vol. I, II and III, edited by
  86. % Charles K. Chui, Academis Press, 1992.
  87. %
  88. % 2) ADAPTED WAVELET ANALYSIS FROM THEORY TO SOFTWARE,
  89. % Mladen Victor Wickerhauser, A K Peters, 1994.
  90. %
  91. % 3) TEN LECTURES ON WAVELETS, I. Daubechies, Siam, 1992.
  92. %
  93. % 4) DIFFERENT PERSPECTIVAS ON WAVELETS, Proceedings of Symposia in
  94. % Applied Mathematics, 1993.
  95. %
  96. % COPYRIGHT
  97. % Copyright (C) 1993 - 1997, Khoral Research, Inc. All rights reserved.
  98. %
  99. function varargout = kkmwt(varargin)
  100. if nargin ==0
  101. Inputs={};arglist={'',''};
  102. elseif nargin ==1
  103. Inputs=varargin{1};arglist={'',''};
  104. elseif nargin ==2
  105. Inputs=varargin{1}; arglist=varargin{2};
  106. else error('Usage: [out1,..] = kkmwt(Inputs,arglist).');
  107. end
  108. if size(arglist,2)~=2
  109. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  110. end
  111. narglist={'i', '__input';'fh', '__input';'fl', '__input';'o', '__output';'w', 0;'h', 0;'d', 0;'t', 0;'e', 0;'dir', 1;'l', 1;'tinv', 1};
  112. maxval={0,0,0,0,0,0,0,0,0,0,2,0};
  113. minval={0,0,0,0,0,0,0,0,0,0,2,0};
  114. istoggle=[0,0,0,0,1,1,1,1,1,0,1,1];
  115. was_set=istoggle * 0;
  116. paramtype={'InputFile','InputFile','InputFile','OutputFile','Toggle','Toggle','Toggle','Toggle','Toggle','MultiChoice','Integer','Toggle'};
  117. % identify the input arrays and assign them to the arguments as stated by the user
  118. if ~iscell(Inputs)
  119. Inputs = {Inputs};
  120. end
  121. NumReqOutputs=1; nextinput=1; nextoutput=1;
  122. for ii=1:size(arglist,1)
  123. wasmatched=0;
  124. for jj=1:size(narglist,1)
  125. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  126. wasmatched = 1;
  127. was_set(jj) = 1;
  128. if strcmp(narglist{jj,2}, '__input')
  129. if (nextinput > length(Inputs))
  130. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  131. end
  132. narglist{jj,2} = 'OK_in';
  133. nextinput = nextinput + 1;
  134. elseif strcmp(narglist{jj,2}, '__output')
  135. if (nextoutput > nargout)
  136. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  137. end
  138. if (isempty(arglist{ii,2}))
  139. narglist{jj,2} = 'OK_out';
  140. else
  141. narglist{jj,2} = arglist{ii,2};
  142. end
  143. nextoutput = nextoutput + 1;
  144. if (minval{jj} == 0)
  145. NumReqOutputs = NumReqOutputs - 1;
  146. end
  147. elseif isstr(arglist{ii,2})
  148. narglist{jj,2} = arglist{ii,2};
  149. else
  150. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  151. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  152. end
  153. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  154. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  155. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  156. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  157. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  158. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  159. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  160. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  161. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  162. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  163. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  164. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  165. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  166. end
  167. end
  168. end
  169. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  170. narglist{jj,2} = arglist{ii,2};
  171. end
  172. end
  173. end
  174. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  175. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  176. end
  177. end
  178. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  179. for jj=1:size(narglist,1)
  180. if strcmp(paramtype{jj}, 'Toggle')
  181. if (narglist{jj,2} ==0)
  182. narglist{jj,1} = '';
  183. end;
  184. narglist{jj,2} = '';
  185. end;
  186. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  187. narglist{jj,1} = '';
  188. narglist{jj,2} = '';
  189. end;
  190. if strcmp(narglist{jj,2}, '__input')
  191. if (minval{jj} == 0) % meaning this input is required
  192. if (nextinput > size(Inputs))
  193. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  194. else
  195. narglist{jj,2} = 'OK_in';
  196. nextinput = nextinput + 1;
  197. end
  198. else % this is an optional input
  199. if (nextinput <= length(Inputs))
  200. narglist{jj,2} = 'OK_in';
  201. nextinput = nextinput + 1;
  202. else
  203. narglist{jj,1} = '';
  204. narglist{jj,2} = '';
  205. end;
  206. end;
  207. else
  208. if strcmp(narglist{jj,2}, '__output')
  209. if (minval{jj} == 0) % this is a required output
  210. if (nextoutput > nargout & nargout > 1)
  211. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  212. else
  213. narglist{jj,2} = 'OK_out';
  214. nextoutput = nextoutput + 1;
  215. NumReqOutputs = NumReqOutputs-1;
  216. end
  217. else % this is an optional output
  218. if (nargout - nextoutput >= NumReqOutputs)
  219. narglist{jj,2} = 'OK_out';
  220. nextoutput = nextoutput + 1;
  221. else
  222. narglist{jj,1} = '';
  223. narglist{jj,2} = '';
  224. end;
  225. end
  226. end
  227. end
  228. end
  229. if nargout
  230. varargout = cell(1,nargout);
  231. else
  232. varargout = cell(1,1);
  233. end
  234. global KhorosRoot
  235. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  236. w=['"' KhorosRoot];
  237. else
  238. if ispc
  239. w='"C:\Program Files\dip\khorosBin\';
  240. else
  241. [s,w] = system('which cantata');
  242. w=['"' w(1:end-8)];
  243. end
  244. end
  245. [varargout{:}]=callKhoros([w 'kmwt" '],Inputs,narglist);