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

/matlab_tools/Converted/kcmindist_classify.m

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