PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kkinverse.m

http://github.com/aludnam/MATLAB
Objective C | 202 lines | 202 code | 0 blank | 0 comment | 2 complexity | 5bf13a00e56ccc117519a19e8f10d579 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkinverse 'Inverse Filtering (Restoration) in Fourier Frequency Domain'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kinverse.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 = kkinverse({i1, i2}, {'i1','';'i2','';'o',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % kinverse - Inverse Filtering (Restoration) in Fourier Frequency Domain
  15. %
  16. % DESCRIPTION
  17. % .I kinverse
  18. % performs restoration of data in the spatial domain by inverse 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. % The major difficulty lies in how small the denominator is allowed to be
  24. % before you call it garbage. The value chosen is supplied as the
  25. % -t thresh value. Ideally, this will be just above the noise floor in the
  26. % image, but experimentation is the best guide here.
  27. % .I kinverse
  28. % places zeros in the output data for those data points where the PSF data object
  29. % magnitude is below the threshold. In this respect, kinverse is actually an
  30. % implementation of a "pseudoinverse\fR filter.
  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.
  37. %
  38. %
  39. %
  40. % EXAMPLES
  41. %
  42. % "SEE ALSO"
  43. %
  44. % RESTRICTIONS
  45. %
  46. % REFERENCES
  47. % R.C. Gonzalez, P. Wintz, "Digital Image Processing", Addison-Wesley 1987,
  48. % ISBN 0-201-11026-1, pp. 221-224.
  49. %
  50. % COPYRIGHT
  51. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  52. %
  53. function varargout = kkinverse(varargin)
  54. if nargin ==0
  55. Inputs={};arglist={'',''};
  56. elseif nargin ==1
  57. Inputs=varargin{1};arglist={'',''};
  58. elseif nargin ==2
  59. Inputs=varargin{1}; arglist=varargin{2};
  60. else error('Usage: [out1,..] = kkinverse(Inputs,arglist).');
  61. end
  62. if size(arglist,2)~=2
  63. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  64. end
  65. narglist={'i1', '__input';'i2', '__input';'o', '__output'};
  66. maxval={0,0,0};
  67. minval={0,0,0};
  68. istoggle=[0,0,0];
  69. was_set=istoggle * 0;
  70. paramtype={'InputFile','InputFile','OutputFile'};
  71. % identify the input arrays and assign them to the arguments as stated by the user
  72. if ~iscell(Inputs)
  73. Inputs = {Inputs};
  74. end
  75. NumReqOutputs=1; nextinput=1; nextoutput=1;
  76. for ii=1:size(arglist,1)
  77. wasmatched=0;
  78. for jj=1:size(narglist,1)
  79. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  80. wasmatched = 1;
  81. was_set(jj) = 1;
  82. if strcmp(narglist{jj,2}, '__input')
  83. if (nextinput > length(Inputs))
  84. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  85. end
  86. narglist{jj,2} = 'OK_in';
  87. nextinput = nextinput + 1;
  88. elseif strcmp(narglist{jj,2}, '__output')
  89. if (nextoutput > nargout)
  90. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  91. end
  92. if (isempty(arglist{ii,2}))
  93. narglist{jj,2} = 'OK_out';
  94. else
  95. narglist{jj,2} = arglist{ii,2};
  96. end
  97. nextoutput = nextoutput + 1;
  98. if (minval{jj} == 0)
  99. NumReqOutputs = NumReqOutputs - 1;
  100. end
  101. elseif isstr(arglist{ii,2})
  102. narglist{jj,2} = arglist{ii,2};
  103. else
  104. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  105. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  106. end
  107. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  108. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  109. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  110. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  111. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  112. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  113. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  114. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  115. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  116. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  117. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  118. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  119. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  120. end
  121. end
  122. end
  123. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  124. narglist{jj,2} = arglist{ii,2};
  125. end
  126. end
  127. end
  128. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  129. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  130. end
  131. end
  132. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  133. for jj=1:size(narglist,1)
  134. if strcmp(paramtype{jj}, 'Toggle')
  135. if (narglist{jj,2} ==0)
  136. narglist{jj,1} = '';
  137. end;
  138. narglist{jj,2} = '';
  139. end;
  140. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  141. narglist{jj,1} = '';
  142. narglist{jj,2} = '';
  143. end;
  144. if strcmp(narglist{jj,2}, '__input')
  145. if (minval{jj} == 0) % meaning this input is required
  146. if (nextinput > size(Inputs))
  147. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  148. else
  149. narglist{jj,2} = 'OK_in';
  150. nextinput = nextinput + 1;
  151. end
  152. else % this is an optional input
  153. if (nextinput <= length(Inputs))
  154. narglist{jj,2} = 'OK_in';
  155. nextinput = nextinput + 1;
  156. else
  157. narglist{jj,1} = '';
  158. narglist{jj,2} = '';
  159. end;
  160. end;
  161. else
  162. if strcmp(narglist{jj,2}, '__output')
  163. if (minval{jj} == 0) % this is a required output
  164. if (nextoutput > nargout & nargout > 1)
  165. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  166. else
  167. narglist{jj,2} = 'OK_out';
  168. nextoutput = nextoutput + 1;
  169. NumReqOutputs = NumReqOutputs-1;
  170. end
  171. else % this is an optional output
  172. if (nargout - nextoutput >= NumReqOutputs)
  173. narglist{jj,2} = 'OK_out';
  174. nextoutput = nextoutput + 1;
  175. else
  176. narglist{jj,1} = '';
  177. narglist{jj,2} = '';
  178. end;
  179. end
  180. end
  181. end
  182. end
  183. if nargout
  184. varargout = cell(1,nargout);
  185. else
  186. varargout = cell(1,1);
  187. end
  188. global KhorosRoot
  189. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  190. w=['"' KhorosRoot];
  191. else
  192. if ispc
  193. w='"C:\Program Files\dip\khorosBin\';
  194. else
  195. [s,w] = system('which cantata');
  196. w=['"' w(1:end-8)];
  197. end
  198. end
  199. [varargout{:}]=callKhoros([w 'kinverse" '],Inputs,narglist);