PageRenderTime 62ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkwt.m

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