PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kWeightedAvg.m

http://github.com/aludnam/MATLAB
Objective C | 194 lines | 191 code | 3 blank | 0 comment | 54 complexity | ffbb98203754c801003ed5d39c449b13 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kWeightedAvg 'performs a weighted average of two images '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros WeightedAvg.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Image 1', required: 'Image 1 to average'
  6. % Double: sigma1 'Image 1 Std.Dev.', default: 1: 'This can be a relative value. Only its relation to the other Std.Dev. is important'
  7. % InputFile: i2 'Image 2', required: 'Image 2 to average'
  8. % Double: sigma2 'Image 2 Std.Dev.', default: 1: 'This can be a relative value. Only its relation to the other Std.Dev. is important'
  9. % InputFile: otf1 'OTF1', required: 'OTF1 (defining the relative scaling of image 1 in every pixel)'
  10. % InputFile: otf2 'OTF2', required: 'OTF1 (defining the relative scaling of image 2 in every pixel)'
  11. % InputFile: goal 'Goal Function', optional: 'OTF1 (defining the scaling the final result should have'
  12. % MultiChoice: method 'Method', default: 3: 'hape of Goal function'
  13. % Choices are:
  14. % 1: 'Linear'
  15. % 2: 'Inv. Square'
  16. % 3: 'Cos^2'
  17. % 4: 'Cos^4'
  18. % Double: DX 'Border Freq X', default: 1: 'Frequency boarder of goal function in'
  19. % Double: DY 'Y', default: 1: 'Frequency boarder of goal function in'
  20. % Double: DZ 'Z', default: 1: 'Frequency boarder of goal function in'
  21. % OutputFile: o 'Output', required: 'Resulting output data object'
  22. %
  23. % Example: o = kWeightedAvg({i1, i2, otf1, otf2, goal}, {'i1','';'sigma1',1;'i2','';'sigma2',1;'otf1','';'otf2','';'goal','';'method',3;'DX',1;'DY',1;'DZ',1;'o',''})
  24. %
  25. % Khoros helpfile follows below:
  26. %
  27. % PROGRAM
  28. % WeightedAvg - performs a weighted average of two images
  29. %
  30. % DESCRIPTION
  31. %
  32. %
  33. %
  34. % EXAMPLES
  35. %
  36. % "SEE ALSO"
  37. %
  38. % RESTRICTIONS
  39. %
  40. % REFERENCES
  41. %
  42. % COPYRIGHT
  43. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  44. %
  45. function varargout = kWeightedAvg(varargin)
  46. if nargin ==0
  47. Inputs={};arglist={'',''};
  48. elseif nargin ==1
  49. Inputs=varargin{1};arglist={'',''};
  50. elseif nargin ==2
  51. Inputs=varargin{1}; arglist=varargin{2};
  52. else error('Usage: [out1,..] = kWeightedAvg(Inputs,arglist).');
  53. end
  54. if size(arglist,2)~=2
  55. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  56. end
  57. narglist={'i1', '__input';'sigma1', 1;'i2', '__input';'sigma2', 1;'otf1', '__input';'otf2', '__input';'goal', '__input';'method', 3;'DX', 1;'DY', 1;'DZ', 1;'o', '__output'};
  58. maxval={0,0,0,0,0,0,1,0,0,0,0,0};
  59. minval={0,0,0,0,0,0,1,0,0,0,0,0};
  60. istoggle=[0,0,0,0,0,0,1,0,0,0,0,0];
  61. was_set=istoggle * 0;
  62. paramtype={'InputFile','Double','InputFile','Double','InputFile','InputFile','InputFile','MultiChoice','Double','Double','Double','OutputFile'};
  63. % identify the input arrays and assign them to the arguments as stated by the user
  64. if ~iscell(Inputs)
  65. Inputs = {Inputs};
  66. end
  67. NumReqOutputs=1; nextinput=1; nextoutput=1;
  68. for ii=1:size(arglist,1)
  69. wasmatched=0;
  70. for jj=1:size(narglist,1)
  71. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  72. wasmatched = 1;
  73. was_set(jj) = 1;
  74. if strcmp(narglist{jj,2}, '__input')
  75. if (nextinput > length(Inputs))
  76. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  77. end
  78. narglist{jj,2} = 'OK_in';
  79. nextinput = nextinput + 1;
  80. elseif strcmp(narglist{jj,2}, '__output')
  81. if (nextoutput > nargout)
  82. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  83. end
  84. if (isempty(arglist{ii,2}))
  85. narglist{jj,2} = 'OK_out';
  86. else
  87. narglist{jj,2} = arglist{ii,2};
  88. end
  89. nextoutput = nextoutput + 1;
  90. if (minval{jj} == 0)
  91. NumReqOutputs = NumReqOutputs - 1;
  92. end
  93. elseif isstr(arglist{ii,2})
  94. narglist{jj,2} = arglist{ii,2};
  95. else
  96. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  97. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  98. end
  99. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  100. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  101. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  102. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  103. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  104. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  105. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  106. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  107. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  108. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  109. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  110. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  111. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  112. end
  113. end
  114. end
  115. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  116. narglist{jj,2} = arglist{ii,2};
  117. end
  118. end
  119. end
  120. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  121. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  122. end
  123. end
  124. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  125. for jj=1:size(narglist,1)
  126. if strcmp(paramtype{jj}, 'Toggle')
  127. if (narglist{jj,2} ==0)
  128. narglist{jj,1} = '';
  129. end;
  130. narglist{jj,2} = '';
  131. end;
  132. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  133. narglist{jj,1} = '';
  134. narglist{jj,2} = '';
  135. end;
  136. if strcmp(narglist{jj,2}, '__input')
  137. if (minval{jj} == 0) % meaning this input is required
  138. if (nextinput > size(Inputs))
  139. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  140. else
  141. narglist{jj,2} = 'OK_in';
  142. nextinput = nextinput + 1;
  143. end
  144. else % this is an optional input
  145. if (nextinput <= length(Inputs))
  146. narglist{jj,2} = 'OK_in';
  147. nextinput = nextinput + 1;
  148. else
  149. narglist{jj,1} = '';
  150. narglist{jj,2} = '';
  151. end;
  152. end;
  153. else
  154. if strcmp(narglist{jj,2}, '__output')
  155. if (minval{jj} == 0) % this is a required output
  156. if (nextoutput > nargout & nargout > 1)
  157. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  158. else
  159. narglist{jj,2} = 'OK_out';
  160. nextoutput = nextoutput + 1;
  161. NumReqOutputs = NumReqOutputs-1;
  162. end
  163. else % this is an optional output
  164. if (nargout - nextoutput >= NumReqOutputs)
  165. narglist{jj,2} = 'OK_out';
  166. nextoutput = nextoutput + 1;
  167. else
  168. narglist{jj,1} = '';
  169. narglist{jj,2} = '';
  170. end;
  171. end
  172. end
  173. end
  174. end
  175. if nargout
  176. varargout = cell(1,nargout);
  177. else
  178. varargout = cell(1,1);
  179. end
  180. global KhorosRoot
  181. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  182. w=['"' KhorosRoot];
  183. else
  184. if ispc
  185. w='"C:\Program Files\dip\khorosBin\';
  186. else
  187. [s,w] = system('which cantata');
  188. w=['"' w(1:end-8)];
  189. end
  190. end
  191. [varargout{:}]=callKhoros([w 'weightedavg" -k'],Inputs,narglist);