PageRenderTime 59ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kClassify.m

http://github.com/aludnam/MATLAB
Objective C | 186 lines | 183 code | 3 blank | 0 comment | 58 complexity | 6fbecf207e2c20505f0a6a7887c859b3 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kClassify 'classifies a series of images according to a number of color vectors '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros Classify.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Images (along elements)', required: 'Series of images (also 3D) stacked along elment direction'
  6. % InputFile: i2 'Colors', required: 'Color vectors (along X) stacked along element direcition'
  7. % Double: t 'DAPI threshold', default: 10: 'Element 0 is assumed to contain the DAPI channel. Pixels below threshold are ignored.'
  8. % Double: minq 'Min Quality', default: 0.97: 'Defines the minimal quality for single channel matching. If not reached, method reverts to two channels'
  9. % Integer: co 'Color Optimize Iterations', default: 1: 'If selected, some iterations for finding the optimal color vectors are performed'
  10. % Double: mincq 'Min Color Quality', default: 0.8: 'Defines the minimum quality for adjusting the colors.'
  11. % OutputFile: o1 'Classified', required: 'Resulting classification image'
  12. % OutputFile: o2 'Quality Img', required: 'A classification quality is given for every pixel'
  13. % OutputFile: o3 'Output Colors', optional: 'The (eventually optimized) colors'
  14. %
  15. % Example: [o1, o2, o3] = kClassify({i1, i2}, {'i1','';'i2','';'t',10;'minq',0.97;'co',1;'mincq',0.8;'o1','';'o2','';'o3',''})
  16. %
  17. % Khoros helpfile follows below:
  18. %
  19. % PROGRAM
  20. % Classify - classifies a series of images according to a number of color vectors
  21. %
  22. % DESCRIPTION
  23. %
  24. %
  25. %
  26. % EXAMPLES
  27. %
  28. % "SEE ALSO"
  29. %
  30. % RESTRICTIONS
  31. %
  32. % REFERENCES
  33. %
  34. % COPYRIGHT
  35. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  36. %
  37. function varargout = kClassify(varargin)
  38. if nargin ==0
  39. Inputs={};arglist={'',''};
  40. elseif nargin ==1
  41. Inputs=varargin{1};arglist={'',''};
  42. elseif nargin ==2
  43. Inputs=varargin{1}; arglist=varargin{2};
  44. else error('Usage: [out1,..] = kClassify(Inputs,arglist).');
  45. end
  46. if size(arglist,2)~=2
  47. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  48. end
  49. narglist={'i1', '__input';'i2', '__input';'t', 10;'minq', 0.97;'co', 1;'mincq', 0.8;'o1', '__output';'o2', '__output';'o3', '__output'};
  50. maxval={0,0,0,0,2,0,0,0,1};
  51. minval={0,0,0,0,2,0,0,0,1};
  52. istoggle=[0,0,1,1,1,1,0,0,1];
  53. was_set=istoggle * 0;
  54. paramtype={'InputFile','InputFile','Double','Double','Integer','Double','OutputFile','OutputFile','OutputFile'};
  55. % identify the input arrays and assign them to the arguments as stated by the user
  56. if ~iscell(Inputs)
  57. Inputs = {Inputs};
  58. end
  59. NumReqOutputs=2; nextinput=1; nextoutput=1;
  60. for ii=1:size(arglist,1)
  61. wasmatched=0;
  62. for jj=1:size(narglist,1)
  63. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  64. wasmatched = 1;
  65. was_set(jj) = 1;
  66. if strcmp(narglist{jj,2}, '__input')
  67. if (nextinput > length(Inputs))
  68. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  69. end
  70. narglist{jj,2} = 'OK_in';
  71. nextinput = nextinput + 1;
  72. elseif strcmp(narglist{jj,2}, '__output')
  73. if (nextoutput > nargout)
  74. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  75. end
  76. if (isempty(arglist{ii,2}))
  77. narglist{jj,2} = 'OK_out';
  78. else
  79. narglist{jj,2} = arglist{ii,2};
  80. end
  81. nextoutput = nextoutput + 1;
  82. if (minval{jj} == 0)
  83. NumReqOutputs = NumReqOutputs - 1;
  84. end
  85. elseif isstr(arglist{ii,2})
  86. narglist{jj,2} = arglist{ii,2};
  87. else
  88. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  89. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  90. end
  91. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  92. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  93. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  94. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  95. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  96. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  97. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  98. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  99. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  100. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  101. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  102. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  103. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  104. end
  105. end
  106. end
  107. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  108. narglist{jj,2} = arglist{ii,2};
  109. end
  110. end
  111. end
  112. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  113. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  114. end
  115. end
  116. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  117. for jj=1:size(narglist,1)
  118. if strcmp(paramtype{jj}, 'Toggle')
  119. if (narglist{jj,2} ==0)
  120. narglist{jj,1} = '';
  121. end;
  122. narglist{jj,2} = '';
  123. end;
  124. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  125. narglist{jj,1} = '';
  126. narglist{jj,2} = '';
  127. end;
  128. if strcmp(narglist{jj,2}, '__input')
  129. if (minval{jj} == 0) % meaning this input is required
  130. if (nextinput > size(Inputs))
  131. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  132. else
  133. narglist{jj,2} = 'OK_in';
  134. nextinput = nextinput + 1;
  135. end
  136. else % this is an optional input
  137. if (nextinput <= length(Inputs))
  138. narglist{jj,2} = 'OK_in';
  139. nextinput = nextinput + 1;
  140. else
  141. narglist{jj,1} = '';
  142. narglist{jj,2} = '';
  143. end;
  144. end;
  145. else
  146. if strcmp(narglist{jj,2}, '__output')
  147. if (minval{jj} == 0) % this is a required output
  148. if (nextoutput > nargout & nargout > 1)
  149. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  150. else
  151. narglist{jj,2} = 'OK_out';
  152. nextoutput = nextoutput + 1;
  153. NumReqOutputs = NumReqOutputs-1;
  154. end
  155. else % this is an optional output
  156. if (nargout - nextoutput >= NumReqOutputs)
  157. narglist{jj,2} = 'OK_out';
  158. nextoutput = nextoutput + 1;
  159. else
  160. narglist{jj,1} = '';
  161. narglist{jj,2} = '';
  162. end;
  163. end
  164. end
  165. end
  166. end
  167. if nargout
  168. varargout = cell(1,nargout);
  169. else
  170. varargout = cell(1,1);
  171. end
  172. global KhorosRoot
  173. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  174. w=['"' KhorosRoot];
  175. else
  176. if ispc
  177. w='"C:\Program Files\dip\khorosBin\';
  178. else
  179. [s,w] = system('which cantata');
  180. w=['"' w(1:end-8)];
  181. end
  182. end
  183. [varargout{:}]=callKhoros([w 'classify" -k'],Inputs,narglist);