PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kcparallel_classify.m

http://github.com/aludnam/MATLAB
Objective C | 192 lines | 189 code | 3 blank | 0 comment | 68 complexity | 8b4460cca0f91f412ce6c3e12d2946e6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kcparallel_classify 'Classify an object using the Parallelepiped algorithm '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros cparallel_classify.pane file
  3. %
  4. % Parameters:
  5. % InputFile: iimage 'Input Image', required: 'input image file'
  6. % InputFile: isigs 'Input Signatures', required: 'input signatures file'
  7. % OutputFile: oclass 'Output Classified', required: 'output classified image'
  8. % OutputFile: oinfo 'Output Information', optional: 'output information about classification'
  9. %
  10. % Example: [oclass, oinfo] = kcparallel_classify({iimage, isigs}, {'iimage','';'isigs','';'oclass','';'oinfo',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % cparallel_classify - Classify an object using the Parallelepiped algorithm
  16. %
  17. % DESCRIPTION
  18. % This routine classifies an object using the Parallelepiped classification algorithm. The Parallelepiped algorithm is a simple, quick algorithm that assigns a class C to a pixel X if all values for the vector that represent X are inside the minimum and maximum values for the signature of C. More details about the Parallelepiped classifier are on the Classify Toolbox Manual.
  19. % This routine requires an object to be classified (passed with the [-iimage] parameter) and a set of classes's signatures object created by "cparallel_signature" and appended by \fIkappend\fP (passed with the [-isigs] parameter). Output will be directed to the file specified by the parameter [-oclass]. The expected dimensions of the input and output objects are shown below:
  20. % The input object which will be classified will have dimensions WxHxDxTxF, where F is the number of features. If it has mask, the masked points won't be classified, and the corresponding points in the output will have value 0 and mask 0.
  21. % The input signatures must have dimensions Fx2x1xNx1, where N is the number of classes. It must be created by using "cparallel_signature" and \fIkappend\fP.
  22. % The output object will have dimensions WxHxDxTx1, and its value segment will have values on the range 0..N, where 0 means that the pixel was rejected. It will also have a corresponding mask segment with values 0 for the rejected pixels and 1 for the non-rejected pixels. The values for the pixels will be associated accordingly to the order the signatures were appended with "kappend".
  23. % If a file is specified with the parameter [-oinfo], information about the classification for all points in the data will be written in ASCII in that file, which can get very large for large images.
  24. % Please refer to the Classify toolbox manual or for one of the example workspaces for usage examples and details.
  25. %
  26. %
  27. %
  28. % EXAMPLES
  29. % All examples for the Classify toolbox are listed on the Classify Toolbox Manual. Examples for this kroutine are on the example workspaces Classify:workspaces:PARALLEL and Classify:workspaces:PARALLEL-Classify.
  30. %
  31. % "SEE ALSO"
  32. % cparallel_signature, kappend.
  33. %
  34. % RESTRICTIONS
  35. % Expects the signatures to be valid signatures for the Parallelepiped algorithm.
  36. %
  37. % REFERENCES
  38. % All references for the Classify toolbox are listed on the Classify Toolbox Manual.
  39. %
  40. % COPYRIGHT
  41. % Copyright (C) 1997 Rafael Santos. Khoros (C) Khoral Research, Inc.
  42. %
  43. function varargout = kcparallel_classify(varargin)
  44. if nargin ==0
  45. Inputs={};arglist={'',''};
  46. elseif nargin ==1
  47. Inputs=varargin{1};arglist={'',''};
  48. elseif nargin ==2
  49. Inputs=varargin{1}; arglist=varargin{2};
  50. else error('Usage: [out1,..] = kcparallel_classify(Inputs,arglist).');
  51. end
  52. if size(arglist,2)~=2
  53. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  54. end
  55. narglist={'iimage', '__input';'isigs', '__input';'oclass', '__output';'oinfo', '__output'};
  56. maxval={0,0,0,1};
  57. minval={0,0,0,1};
  58. istoggle=[0,0,0,1];
  59. was_set=istoggle * 0;
  60. paramtype={'InputFile','InputFile','OutputFile','OutputFile'};
  61. % identify the input arrays and assign them to the arguments as stated by the user
  62. if ~iscell(Inputs)
  63. Inputs = {Inputs};
  64. end
  65. NumReqOutputs=1; nextinput=1; nextoutput=1;
  66. for ii=1:size(arglist,1)
  67. wasmatched=0;
  68. for jj=1:size(narglist,1)
  69. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  70. wasmatched = 1;
  71. was_set(jj) = 1;
  72. if strcmp(narglist{jj,2}, '__input')
  73. if (nextinput > length(Inputs))
  74. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  75. end
  76. narglist{jj,2} = 'OK_in';
  77. nextinput = nextinput + 1;
  78. elseif strcmp(narglist{jj,2}, '__output')
  79. if (nextoutput > nargout)
  80. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  81. end
  82. if (isempty(arglist{ii,2}))
  83. narglist{jj,2} = 'OK_out';
  84. else
  85. narglist{jj,2} = arglist{ii,2};
  86. end
  87. nextoutput = nextoutput + 1;
  88. if (minval{jj} == 0)
  89. NumReqOutputs = NumReqOutputs - 1;
  90. end
  91. elseif isstr(arglist{ii,2})
  92. narglist{jj,2} = arglist{ii,2};
  93. else
  94. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  95. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  96. end
  97. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  98. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  99. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  100. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  101. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  102. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  103. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  104. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  105. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  106. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  107. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  108. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  109. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  110. end
  111. end
  112. end
  113. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  114. narglist{jj,2} = arglist{ii,2};
  115. end
  116. end
  117. end
  118. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  119. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  120. end
  121. end
  122. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  123. for jj=1:size(narglist,1)
  124. if strcmp(paramtype{jj}, 'Toggle')
  125. if (narglist{jj,2} ==0)
  126. narglist{jj,1} = '';
  127. end;
  128. narglist{jj,2} = '';
  129. end;
  130. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  131. narglist{jj,1} = '';
  132. narglist{jj,2} = '';
  133. end;
  134. if strcmp(narglist{jj,2}, '__input')
  135. if (minval{jj} == 0) % meaning this input is required
  136. if (nextinput > size(Inputs))
  137. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  138. else
  139. narglist{jj,2} = 'OK_in';
  140. nextinput = nextinput + 1;
  141. end
  142. else % this is an optional input
  143. if (nextinput <= length(Inputs))
  144. narglist{jj,2} = 'OK_in';
  145. nextinput = nextinput + 1;
  146. else
  147. narglist{jj,1} = '';
  148. narglist{jj,2} = '';
  149. end;
  150. end;
  151. else
  152. if strcmp(narglist{jj,2}, '__output')
  153. if (minval{jj} == 0) % this is a required output
  154. if (nextoutput > nargout & nargout > 1)
  155. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  156. else
  157. narglist{jj,2} = 'OK_out';
  158. nextoutput = nextoutput + 1;
  159. NumReqOutputs = NumReqOutputs-1;
  160. end
  161. else % this is an optional output
  162. if (nargout - nextoutput >= NumReqOutputs)
  163. narglist{jj,2} = 'OK_out';
  164. nextoutput = nextoutput + 1;
  165. else
  166. narglist{jj,1} = '';
  167. narglist{jj,2} = '';
  168. end;
  169. end
  170. end
  171. end
  172. end
  173. if nargout
  174. varargout = cell(1,nargout);
  175. else
  176. varargout = cell(1,1);
  177. end
  178. global KhorosRoot
  179. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  180. w=['"' KhorosRoot];
  181. else
  182. if ispc
  183. w='"C:\Program Files\dip\khorosBin\';
  184. else
  185. [s,w] = system('which cantata');
  186. w=['"' w(1:end-8)];
  187. end
  188. end
  189. [varargout{:}]=callKhoros([w 'cparallel_classify" '],Inputs,narglist);