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

/matlab_tools/Converted/kkwiener.m

http://github.com/aludnam/MATLAB
Objective C | 205 lines | 205 code | 0 blank | 0 comment | 1 complexity | 8b09864bdf8150a1ee575d775985d8cd MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkwiener 'Wiener Filtering (Restoration) in Fourier Frequency Domain'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kwiener.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Source data object (FFT)', required: 'source data object (FFT)'
  6. % InputFile: i2 ' PSF data object (FFT)', required: 'PSF data object (FFT)'
  7. % OutputFile: o 'Filtered data object (FFT)', required: 'filtered data object (FFT)'
  8. %
  9. % Example: o = kkwiener({i1, i2}, {'i1','';'i2','';'o',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % kwiener - Wiener Filtering (Restoration) in Fourier Frequency Domain
  15. %
  16. % DESCRIPTION
  17. % .I kwiener
  18. % performs restoration of data in the spatial domain by Wiener filtering in
  19. % the frequency domain. The idea is to deconvolve the blurring function
  20. % from the blurred data. A few problems exist in performing this operation,
  21. % as described in great detail in any good image processing book.
  22. %
  23. % A full implementation of a Wiener filter requires detailed knowledge of the
  24. % signal and noise power spectra. Many times this information is simply
  25. % unavailable or is very poorly known. In such situations, it is convenient
  26. % to assign some constant value to the SNR and use that in the Wiener filter
  27. % implentation. This is a somewhat extreme restriction of the Wiener filter,
  28. % but it makes the filter very easy to use and can produce better results than
  29. % the pseudoinverse filter in "kinverse\fR. (Better in the sense of much
  30. % less ringing).
  31. %
  32. % Note that the input data objects will be treated simply as a field of complex
  33. % data, presumably obtained by application of an FFT, although the data could
  34. % be generated by many other means. The output data will be either KCOMPLEX if
  35. % the input data is any type other than KDCOMPLEX. Otherwise, the output will be
  36. % of type KDCOMPLEX. Data objects with maps attached are not supported. Mask
  37. % data is ignored, if present.
  38. %
  39. %
  40. %
  41. % EXAMPLES
  42. %
  43. % "SEE ALSO"
  44. % kinverse(1), kfft(1), kcmplx2real(1)
  45. %
  46. % RESTRICTIONS
  47. %
  48. % REFERENCES
  49. % K.R. Castleman, "Digital Image Processing", Prentice-Hall, 1979,
  50. % ISBN 0-13-212365-7, p281 Eq. 2.
  51. % Rosenfeld & Kak, p287.
  52. %
  53. % COPYRIGHT
  54. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  55. %
  56. function varargout = kkwiener(varargin)
  57. if nargin ==0
  58. Inputs={};arglist={'',''};
  59. elseif nargin ==1
  60. Inputs=varargin{1};arglist={'',''};
  61. elseif nargin ==2
  62. Inputs=varargin{1}; arglist=varargin{2};
  63. else error('Usage: [out1,..] = kkwiener(Inputs,arglist).');
  64. end
  65. if size(arglist,2)~=2
  66. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  67. end
  68. narglist={'i1', '__input';'i2', '__input';'o', '__output'};
  69. maxval={0,0,0};
  70. minval={0,0,0};
  71. istoggle=[0,0,0];
  72. was_set=istoggle * 0;
  73. paramtype={'InputFile','InputFile','OutputFile'};
  74. % identify the input arrays and assign them to the arguments as stated by the user
  75. if ~iscell(Inputs)
  76. Inputs = {Inputs};
  77. end
  78. NumReqOutputs=1; nextinput=1; nextoutput=1;
  79. for ii=1:size(arglist,1)
  80. wasmatched=0;
  81. for jj=1:size(narglist,1)
  82. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  83. wasmatched = 1;
  84. was_set(jj) = 1;
  85. if strcmp(narglist{jj,2}, '__input')
  86. if (nextinput > length(Inputs))
  87. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  88. end
  89. narglist{jj,2} = 'OK_in';
  90. nextinput = nextinput + 1;
  91. elseif strcmp(narglist{jj,2}, '__output')
  92. if (nextoutput > nargout)
  93. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  94. end
  95. if (isempty(arglist{ii,2}))
  96. narglist{jj,2} = 'OK_out';
  97. else
  98. narglist{jj,2} = arglist{ii,2};
  99. end
  100. nextoutput = nextoutput + 1;
  101. if (minval{jj} == 0)
  102. NumReqOutputs = NumReqOutputs - 1;
  103. end
  104. elseif isstr(arglist{ii,2})
  105. narglist{jj,2} = arglist{ii,2};
  106. else
  107. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  108. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  109. end
  110. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  111. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  112. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  113. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  114. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  115. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  116. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  117. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  118. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  119. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  120. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  121. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  122. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  123. end
  124. end
  125. end
  126. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  127. narglist{jj,2} = arglist{ii,2};
  128. end
  129. end
  130. end
  131. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  132. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  133. end
  134. end
  135. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  136. for jj=1:size(narglist,1)
  137. if strcmp(paramtype{jj}, 'Toggle')
  138. if (narglist{jj,2} ==0)
  139. narglist{jj,1} = '';
  140. end;
  141. narglist{jj,2} = '';
  142. end;
  143. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  144. narglist{jj,1} = '';
  145. narglist{jj,2} = '';
  146. end;
  147. if strcmp(narglist{jj,2}, '__input')
  148. if (minval{jj} == 0) % meaning this input is required
  149. if (nextinput > size(Inputs))
  150. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  151. else
  152. narglist{jj,2} = 'OK_in';
  153. nextinput = nextinput + 1;
  154. end
  155. else % this is an optional input
  156. if (nextinput <= length(Inputs))
  157. narglist{jj,2} = 'OK_in';
  158. nextinput = nextinput + 1;
  159. else
  160. narglist{jj,1} = '';
  161. narglist{jj,2} = '';
  162. end;
  163. end;
  164. else
  165. if strcmp(narglist{jj,2}, '__output')
  166. if (minval{jj} == 0) % this is a required output
  167. if (nextoutput > nargout & nargout > 1)
  168. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  169. else
  170. narglist{jj,2} = 'OK_out';
  171. nextoutput = nextoutput + 1;
  172. NumReqOutputs = NumReqOutputs-1;
  173. end
  174. else % this is an optional output
  175. if (nargout - nextoutput >= NumReqOutputs)
  176. narglist{jj,2} = 'OK_out';
  177. nextoutput = nextoutput + 1;
  178. else
  179. narglist{jj,1} = '';
  180. narglist{jj,2} = '';
  181. end;
  182. end
  183. end
  184. end
  185. end
  186. if nargout
  187. varargout = cell(1,nargout);
  188. else
  189. varargout = cell(1,1);
  190. end
  191. global KhorosRoot
  192. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  193. w=['"' KhorosRoot];
  194. else
  195. if ispc
  196. w='"C:\Program Files\dip\khorosBin\';
  197. else
  198. [s,w] = system('which cantata');
  199. w=['"' w(1:end-8)];
  200. end
  201. end
  202. [varargout{:}]=callKhoros([w 'kwiener" '],Inputs,narglist);