PageRenderTime 24ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/krc_seqsim.m

http://github.com/aludnam/MATLAB
Objective C | 204 lines | 201 code | 3 blank | 0 comment | 57 complexity | c8274c2168207dd29b82a288885d7068 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %krc_seqsim 'sequential similarity detection algorithm'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros rc_seqsim.pane file
  3. %
  4. % Parameters:
  5. % InputFile: iref 'Input Reference Image', required: 'input reference image'
  6. % InputFile: idist 'Input Distorted Image', required: 'input distorted image'
  7. % OutputFile: o 'Output', required: 'Resulting output data object'
  8. % Double: sum_fraction 'fraction of min sum', default: 0.75: 'set threshold to fraction of minimum sum '
  9. % Integer: seed 'seed', default: 1234567: 'seed for krandom'
  10. % Double: threshold 'Set explicit threshold', default: 100: 'similarity metric threshold'
  11. % Integer: pix_number 'number of pixels', default: 20: 'number of pixels to sample for auto-threshold'
  12. % Double: pix_fraction 'fraction of pixels', default: 0.01: 'fraction of pixels to sample for auto-threshold'
  13. %
  14. % Example: o = krc_seqsim({iref, idist}, {'iref','';'idist','';'o','';'sum_fraction',0.75;'seed',1234567;'threshold',100;'pix_number',20;'pix_fraction',0.01})
  15. %
  16. % Khoros helpfile follows below:
  17. %
  18. % PROGRAM
  19. % rc_seqsim - sequential similarity detection algorithm
  20. %
  21. % DESCRIPTION
  22. % This program finds the translation correction needed to register the
  23. % distorted image to the reference image. It operates much like
  24. % standard correlation, but with two exceptions: (1) rather than summing
  25. % the squared differences, the absolute differences are summed, and (2)
  26. % rather than summing over the entire window, the algorithm sums until a
  27. % threshold is exceeded. The output image consists of the number of
  28. % terms summed until the threshold was exceeded at each offset.
  29. %
  30. % The threshold is established in one of three ways. First, you may
  31. % enter the threshold directly with the -threshold flag. Second, a
  32. % number of pixels are randomly sampled (set the number with
  33. % -pix_number) and the sum over all the pixels in the window
  34. % established. Then the threshold is set at the frac'th percentile of
  35. % this sampled population, where frac is set with the -sum_fraction
  36. % flag. Finally, the third method is the same as the second, except
  37. % instead of setting the absolute number of pixels to sample, the sample
  38. % size is some fraction of the total number of pixels determined by the
  39. % -pix_fraction flag.
  40. %
  41. %
  42. %
  43. % EXAMPLES
  44. % See the html tutorial in $REGISTER/examples/html/README_FIRST.html
  45. %
  46. % "SEE ALSO"
  47. %
  48. % RESTRICTIONS
  49. %
  50. % REFERENCES
  51. %
  52. % COPYRIGHT
  53. % Copyright (C) 1996 - 1997, University of New Mexico. All rights reserved.
  54. %
  55. function varargout = krc_seqsim(varargin)
  56. if nargin ==0
  57. Inputs={};arglist={'',''};
  58. elseif nargin ==1
  59. Inputs=varargin{1};arglist={'',''};
  60. elseif nargin ==2
  61. Inputs=varargin{1}; arglist=varargin{2};
  62. else error('Usage: [out1,..] = krc_seqsim(Inputs,arglist).');
  63. end
  64. if size(arglist,2)~=2
  65. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  66. end
  67. narglist={'iref', '__input';'idist', '__input';'o', '__output';'sum_fraction', 0.75;'seed', 1234567;'threshold', 100;'pix_number', 20;'pix_fraction', 0.01};
  68. maxval={0,0,0,1,2,0,2,1};
  69. minval={0,0,0,0,2,0,2,0};
  70. istoggle=[0,0,0,1,1,1,1,1];
  71. was_set=istoggle * 0;
  72. paramtype={'InputFile','InputFile','OutputFile','Double','Integer','Double','Integer','Double'};
  73. % identify the input arrays and assign them to the arguments as stated by the user
  74. if ~iscell(Inputs)
  75. Inputs = {Inputs};
  76. end
  77. NumReqOutputs=1; nextinput=1; nextoutput=1;
  78. for ii=1:size(arglist,1)
  79. wasmatched=0;
  80. for jj=1:size(narglist,1)
  81. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  82. wasmatched = 1;
  83. was_set(jj) = 1;
  84. if strcmp(narglist{jj,2}, '__input')
  85. if (nextinput > length(Inputs))
  86. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  87. end
  88. narglist{jj,2} = 'OK_in';
  89. nextinput = nextinput + 1;
  90. elseif strcmp(narglist{jj,2}, '__output')
  91. if (nextoutput > nargout)
  92. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  93. end
  94. if (isempty(arglist{ii,2}))
  95. narglist{jj,2} = 'OK_out';
  96. else
  97. narglist{jj,2} = arglist{ii,2};
  98. end
  99. nextoutput = nextoutput + 1;
  100. if (minval{jj} == 0)
  101. NumReqOutputs = NumReqOutputs - 1;
  102. end
  103. elseif isstr(arglist{ii,2})
  104. narglist{jj,2} = arglist{ii,2};
  105. else
  106. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  107. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  108. end
  109. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  110. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  111. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  112. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  113. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  114. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  115. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  116. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  117. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  118. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  119. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  120. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  121. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  122. end
  123. end
  124. end
  125. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  126. narglist{jj,2} = arglist{ii,2};
  127. end
  128. end
  129. end
  130. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  131. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  132. end
  133. end
  134. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  135. for jj=1:size(narglist,1)
  136. if strcmp(paramtype{jj}, 'Toggle')
  137. if (narglist{jj,2} ==0)
  138. narglist{jj,1} = '';
  139. end;
  140. narglist{jj,2} = '';
  141. end;
  142. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  143. narglist{jj,1} = '';
  144. narglist{jj,2} = '';
  145. end;
  146. if strcmp(narglist{jj,2}, '__input')
  147. if (minval{jj} == 0) % meaning this input is required
  148. if (nextinput > size(Inputs))
  149. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  150. else
  151. narglist{jj,2} = 'OK_in';
  152. nextinput = nextinput + 1;
  153. end
  154. else % this is an optional input
  155. if (nextinput <= length(Inputs))
  156. narglist{jj,2} = 'OK_in';
  157. nextinput = nextinput + 1;
  158. else
  159. narglist{jj,1} = '';
  160. narglist{jj,2} = '';
  161. end;
  162. end;
  163. else
  164. if strcmp(narglist{jj,2}, '__output')
  165. if (minval{jj} == 0) % this is a required output
  166. if (nextoutput > nargout & nargout > 1)
  167. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  168. else
  169. narglist{jj,2} = 'OK_out';
  170. nextoutput = nextoutput + 1;
  171. NumReqOutputs = NumReqOutputs-1;
  172. end
  173. else % this is an optional output
  174. if (nargout - nextoutput >= NumReqOutputs)
  175. narglist{jj,2} = 'OK_out';
  176. nextoutput = nextoutput + 1;
  177. else
  178. narglist{jj,1} = '';
  179. narglist{jj,2} = '';
  180. end;
  181. end
  182. end
  183. end
  184. end
  185. if nargout
  186. varargout = cell(1,nargout);
  187. else
  188. varargout = cell(1,1);
  189. end
  190. global KhorosRoot
  191. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  192. w=['"' KhorosRoot];
  193. else
  194. if ispc
  195. w='"C:\Program Files\dip\khorosBin\';
  196. else
  197. [s,w] = system('which cantata');
  198. w=['"' w(1:end-8)];
  199. end
  200. end
  201. [varargout{:}]=callKhoros([w 'rc_seqsim" '],Inputs,narglist);