PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kcorrelator.m

http://github.com/aludnam/MATLAB
Objective C | 201 lines | 198 code | 3 blank | 0 comment | 58 complexity | fdbc504258376969e82a9df9a8e4e03a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kcorrelator 'alligns second image to match the first '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros correlator.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Reference Image', optional: 'serves as reference for allignment'
  6. % InputFile: i2 'Image to allign', optional: 'will be alligned to first image'
  7. % InputFile: i3 'Alternate image to shift', optional: 'will be alligned to first image'
  8. % Integer: r 'region around maximum', default: 1: 'pixel around max that are evaluated in fourierspace'
  9. % Double: expon 'Exponent', default: 1: 'If this is given, the data is raised to the power specified here. This can be used to suppress background information over the forground. The exponent will only be used for the determination of the shifts, but the shifts will be computed on the raw images!'
  10. % Integer: steps 'Iteration Steps', default: 3: 'number of times the maximum search is done'
  11. % Toggle: ishifts 'Indep. Shifts', default: 0: 'Determine shifts independently. If not selected : only element 0 is used for shifts, but all are shifted'
  12. % Toggle: iscale 'Independent Scaling', default: 0: 'Determine scale for each element seperately. If not : element 0 gives scaling'
  13. % Toggle: s 'Do Intensity scaling', default: 0: 'scale the second image to the first by its mean'
  14. % Toggle: noshifts 'No Shifts', default: 0: 'Do only intensity scaling and no shifts (planes is ignored)'
  15. % Toggle: onlyoffset 'Apply only offset', default: 0: 'Apply only offset correction'
  16. % Double: phases 'HF enhance', default: 0.5: '!= 0 -> evaluate mostly phases with phase cross corellation. Formula : F0*F1\' / (abs(F0)+Max*phases) / (abs(F1)+Max*phases)'
  17. % Toggle: p 'adjust planes', default: 0: 'shift planes one after each other to allign'
  18. % Integer: fixplane 'fixed reference', default: 0: 'If selected, the number defines the fixed reference plane (0 to Zmax). If > Zmax, the last plane will be used.'
  19. % Double: gf 'LP-GaussFilter', default: 0.3: 'If > 0.0, a Gauss-filter is applied in frequency space during computation of the cross-correlation. The frequency is relative to the image border.'
  20. % Double: gfz 'Z', default: 1e+20: 'This is the Z-component of the low-pass Gaussfilter (if given as non-zero). A very high value means no filtering along Z is performed.'
  21. % Double: md 'MaxRelDXY', default: 0.5: 'If given (> 0.0) the cross-correlation will be weighted linearly decreasing to the relative border distance'
  22. % Double: mdz 'MaxRelDZ', default: 0.5: 'If given (> 0.0) the cross-correlation will be weighted linearly decreasing to the relative border distance in Z direction'
  23. % Double: sl 'ScreamLlimit', default: 10: 'If this limit in total distance is exceeded, the program will end with an error. Data is still written to disc.'
  24. % Toggle: plane 'Only XY shifts', default: 0: 'restrict the shifting to planes'
  25. % Toggle: withprevelem 'WithPrevElem', default: 0: 'If selected, the correlation will always be with the previous element'
  26. % Toggle: zflipadd 'Flip, Correl, CenterSum', default: 0: 'If selected, the image to align will be mirrored with respect to Z. Then correlated and added to the reference and the result will be centered'
  27. % OutputFile: o 'Output', required: 'Resulting output data object'
  28. % OutputFile: v 'ASCII Vectors', optional: 'Shift vectors are printed into file'
  29. %
  30. % Example: [o, v] = kcorrelator({i1, i2, i3}, {'i1','';'i2','';'i3','';'r',1;'expon',1;'steps',3;'ishifts',0;'iscale',0;'s',0;'noshifts',0;'onlyoffset',0;'phases',0.5;'p',0;'fixplane',0;'gf',0.3;'gfz',1e+20;'md',0.5;'mdz',0.5;'sl',10;'plane',0;'withprevelem',0;'zflipadd',0;'o','';'v',''})
  31. %
  32. % Khoros helpfile follows below:
  33. %
  34. % PROGRAM
  35. % correlator - alligns second image to match the first
  36. %
  37. % DESCRIPTION
  38. %
  39. %
  40. %
  41. % EXAMPLES
  42. %
  43. % "SEE ALSO"
  44. %
  45. % RESTRICTIONS
  46. %
  47. % REFERENCES
  48. %
  49. % COPYRIGHT
  50. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  51. %
  52. function varargout = kcorrelator(varargin)
  53. if nargin ==0
  54. Inputs={};arglist={'',''};
  55. elseif nargin ==1
  56. Inputs=varargin{1};arglist={'',''};
  57. elseif nargin ==2
  58. Inputs=varargin{1}; arglist=varargin{2};
  59. else error('Usage: [out1,..] = kcorrelator(Inputs,arglist).');
  60. end
  61. if size(arglist,2)~=2
  62. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  63. end
  64. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'r', 1;'expon', 1;'steps', 3;'ishifts', 0;'iscale', 0;'s', 0;'noshifts', 0;'onlyoffset', 0;'phases', 0.5;'p', 0;'fixplane', 0;'gf', 0.3;'gfz', 1e+20;'md', 0.5;'mdz', 0.5;'sl', 10;'plane', 0;'withprevelem', 0;'zflipadd', 0;'o', '__output';'v', '__output'};
  65. maxval={1,1,1,100,2,2,0,0,0,0,0,2,0,1,2,2,2,2,2,0,0,0,0,1};
  66. minval={1,1,1,-100,2,2,0,0,0,0,0,2,0,1,2,2,2,2,2,0,0,0,0,1};
  67. istoggle=[1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1];
  68. was_set=istoggle * 0;
  69. paramtype={'InputFile','InputFile','InputFile','Integer','Double','Integer','Toggle','Toggle','Toggle','Toggle','Toggle','Double','Toggle','Integer','Double','Double','Double','Double','Double','Toggle','Toggle','Toggle','OutputFile','OutputFile'};
  70. % identify the input arrays and assign them to the arguments as stated by the user
  71. if ~iscell(Inputs)
  72. Inputs = {Inputs};
  73. end
  74. NumReqOutputs=1; nextinput=1; nextoutput=1;
  75. for ii=1:size(arglist,1)
  76. wasmatched=0;
  77. for jj=1:size(narglist,1)
  78. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  79. wasmatched = 1;
  80. was_set(jj) = 1;
  81. if strcmp(narglist{jj,2}, '__input')
  82. if (nextinput > length(Inputs))
  83. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  84. end
  85. narglist{jj,2} = 'OK_in';
  86. nextinput = nextinput + 1;
  87. elseif strcmp(narglist{jj,2}, '__output')
  88. if (nextoutput > nargout)
  89. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  90. end
  91. if (isempty(arglist{ii,2}))
  92. narglist{jj,2} = 'OK_out';
  93. else
  94. narglist{jj,2} = arglist{ii,2};
  95. end
  96. nextoutput = nextoutput + 1;
  97. if (minval{jj} == 0)
  98. NumReqOutputs = NumReqOutputs - 1;
  99. end
  100. elseif isstr(arglist{ii,2})
  101. narglist{jj,2} = arglist{ii,2};
  102. else
  103. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  104. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  105. end
  106. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  107. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  108. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  109. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  110. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  111. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  112. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  113. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  114. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  115. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  116. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  117. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  118. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  119. end
  120. end
  121. end
  122. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  123. narglist{jj,2} = arglist{ii,2};
  124. end
  125. end
  126. end
  127. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  128. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  129. end
  130. end
  131. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  132. for jj=1:size(narglist,1)
  133. if strcmp(paramtype{jj}, 'Toggle')
  134. if (narglist{jj,2} ==0)
  135. narglist{jj,1} = '';
  136. end;
  137. narglist{jj,2} = '';
  138. end;
  139. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  140. narglist{jj,1} = '';
  141. narglist{jj,2} = '';
  142. end;
  143. if strcmp(narglist{jj,2}, '__input')
  144. if (minval{jj} == 0) % meaning this input is required
  145. if (nextinput > size(Inputs))
  146. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  147. else
  148. narglist{jj,2} = 'OK_in';
  149. nextinput = nextinput + 1;
  150. end
  151. else % this is an optional input
  152. if (nextinput <= length(Inputs))
  153. narglist{jj,2} = 'OK_in';
  154. nextinput = nextinput + 1;
  155. else
  156. narglist{jj,1} = '';
  157. narglist{jj,2} = '';
  158. end;
  159. end;
  160. else
  161. if strcmp(narglist{jj,2}, '__output')
  162. if (minval{jj} == 0) % this is a required output
  163. if (nextoutput > nargout & nargout > 1)
  164. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  165. else
  166. narglist{jj,2} = 'OK_out';
  167. nextoutput = nextoutput + 1;
  168. NumReqOutputs = NumReqOutputs-1;
  169. end
  170. else % this is an optional output
  171. if (nargout - nextoutput >= NumReqOutputs)
  172. narglist{jj,2} = 'OK_out';
  173. nextoutput = nextoutput + 1;
  174. else
  175. narglist{jj,1} = '';
  176. narglist{jj,2} = '';
  177. end;
  178. end
  179. end
  180. end
  181. end
  182. if nargout
  183. varargout = cell(1,nargout);
  184. else
  185. varargout = cell(1,1);
  186. end
  187. global KhorosRoot
  188. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  189. w=['"' KhorosRoot];
  190. else
  191. if ispc
  192. w='"C:\Program Files\dip\khorosBin\';
  193. else
  194. [s,w] = system('which cantata');
  195. w=['"' w(1:end-8)];
  196. end
  197. end
  198. [varargout{:}]=callKhoros([w 'correlator" -k'],Inputs,narglist);