PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kPCASegment.m

http://github.com/aludnam/MATLAB
Objective C | 164 lines | 161 code | 3 blank | 0 comment | 55 complexity | df621361e22802099e00feb4bbe08f21 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kPCASegment 'segments an image by applying a matrix and thresholding at zero along each dimension '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros PCASegment.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input ', required: 'First Input data object'
  6. % InputFile: m 'Matrix Input', required: 'Matrix has to be in XY format (X being multiplied with elements)'
  7. % Integer: valid 'Valid orders', default: 2: 'numkber of components (after matrix application) that are valid. If <=0 the full size of the matrix will be used'
  8. % OutputFile: o 'Output', required: 'Resulting output data object'
  9. % OutputFile: avg 'Element Average', optional: 'The average over all elements (used for segmentation)'
  10. % OutputFile: vec 'Classified Mean Vectors', optional: 'List of vectors giving the mean (in original) over classified dimensions'
  11. %
  12. % Example: [o, avg, vec] = kPCASegment({i, m}, {'i','';'m','';'valid',2;'o','';'avg','';'vec',''})
  13. %
  14. % Khoros helpfile follows below:
  15. function varargout = kPCASegment(varargin)
  16. if nargin ==0
  17. Inputs={};arglist={'',''};
  18. elseif nargin ==1
  19. Inputs=varargin{1};arglist={'',''};
  20. elseif nargin ==2
  21. Inputs=varargin{1}; arglist=varargin{2};
  22. else error('Usage: [out1,..] = kPCASegment(Inputs,arglist).');
  23. end
  24. if size(arglist,2)~=2
  25. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  26. end
  27. narglist={'i', '__input';'m', '__input';'valid', 2;'o', '__output';'avg', '__output';'vec', '__output'};
  28. maxval={0,0,0,0,1,1};
  29. minval={0,0,0,0,1,1};
  30. istoggle=[0,0,0,0,1,1];
  31. was_set=istoggle * 0;
  32. paramtype={'InputFile','InputFile','Integer','OutputFile','OutputFile','OutputFile'};
  33. % identify the input arrays and assign them to the arguments as stated by the user
  34. if ~iscell(Inputs)
  35. Inputs = {Inputs};
  36. end
  37. NumReqOutputs=1; nextinput=1; nextoutput=1;
  38. for ii=1:size(arglist,1)
  39. wasmatched=0;
  40. for jj=1:size(narglist,1)
  41. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  42. wasmatched = 1;
  43. was_set(jj) = 1;
  44. if strcmp(narglist{jj,2}, '__input')
  45. if (nextinput > length(Inputs))
  46. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  47. end
  48. narglist{jj,2} = 'OK_in';
  49. nextinput = nextinput + 1;
  50. elseif strcmp(narglist{jj,2}, '__output')
  51. if (nextoutput > nargout)
  52. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  53. end
  54. if (isempty(arglist{ii,2}))
  55. narglist{jj,2} = 'OK_out';
  56. else
  57. narglist{jj,2} = arglist{ii,2};
  58. end
  59. nextoutput = nextoutput + 1;
  60. if (minval{jj} == 0)
  61. NumReqOutputs = NumReqOutputs - 1;
  62. end
  63. elseif isstr(arglist{ii,2})
  64. narglist{jj,2} = arglist{ii,2};
  65. else
  66. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  67. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  68. end
  69. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  70. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  71. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  72. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  73. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  74. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  75. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  76. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  77. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  78. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  79. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  80. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  81. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  82. end
  83. end
  84. end
  85. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  86. narglist{jj,2} = arglist{ii,2};
  87. end
  88. end
  89. end
  90. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  91. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  92. end
  93. end
  94. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  95. for jj=1:size(narglist,1)
  96. if strcmp(paramtype{jj}, 'Toggle')
  97. if (narglist{jj,2} ==0)
  98. narglist{jj,1} = '';
  99. end;
  100. narglist{jj,2} = '';
  101. end;
  102. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  103. narglist{jj,1} = '';
  104. narglist{jj,2} = '';
  105. end;
  106. if strcmp(narglist{jj,2}, '__input')
  107. if (minval{jj} == 0) % meaning this input is required
  108. if (nextinput > size(Inputs))
  109. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  110. else
  111. narglist{jj,2} = 'OK_in';
  112. nextinput = nextinput + 1;
  113. end
  114. else % this is an optional input
  115. if (nextinput <= length(Inputs))
  116. narglist{jj,2} = 'OK_in';
  117. nextinput = nextinput + 1;
  118. else
  119. narglist{jj,1} = '';
  120. narglist{jj,2} = '';
  121. end;
  122. end;
  123. else
  124. if strcmp(narglist{jj,2}, '__output')
  125. if (minval{jj} == 0) % this is a required output
  126. if (nextoutput > nargout & nargout > 1)
  127. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  128. else
  129. narglist{jj,2} = 'OK_out';
  130. nextoutput = nextoutput + 1;
  131. NumReqOutputs = NumReqOutputs-1;
  132. end
  133. else % this is an optional output
  134. if (nargout - nextoutput >= NumReqOutputs)
  135. narglist{jj,2} = 'OK_out';
  136. nextoutput = nextoutput + 1;
  137. else
  138. narglist{jj,1} = '';
  139. narglist{jj,2} = '';
  140. end;
  141. end
  142. end
  143. end
  144. end
  145. if nargout
  146. varargout = cell(1,nargout);
  147. else
  148. varargout = cell(1,1);
  149. end
  150. global KhorosRoot
  151. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  152. w=['"' KhorosRoot];
  153. else
  154. if ispc
  155. w='"C:\Program Files\dip\khorosBin\';
  156. else
  157. [s,w] = system('which cantata');
  158. w=['"' w(1:end-8)];
  159. end
  160. end
  161. [varargout{:}]=callKhoros([w 'PCAsegment" -k'],Inputs,narglist);