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

/matlab_tools/Converted/kspectrum.m

http://github.com/aludnam/MATLAB
Objective C | 235 lines | 232 code | 3 blank | 0 comment | 64 complexity | ddbb038722d59204d55cd3c90701d7ad MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kspectrum 'Interactive Image Classification System'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros spectrum.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input File ', optional: 'File containing input image'
  6. % InputFile: l 'Input Legend ', optional: 'File containing input legend'
  7. % InputFile: t 'Input Disp File', optional: 'File containing input display environment file'
  8. % InputFile: p 'Input Pre Class', optional: 'File containing input predetermined classification file'
  9. % Integer: x 'X placement', default: -1: 'X location for GUI autoplacement'
  10. % Integer: y 'Y placement', default: -1: 'Y location for GUI autoplacement'
  11. % Double: update 'Update time', default: 1: 'How often to check input file for modification'
  12. %
  13. % Example: kspectrum({i, l, t, p}, {'i','';'l','';'t','';'p','';'x',-1;'y',-1;'update',1})
  14. %
  15. % Khoros helpfile follows below:
  16. %
  17. % PROGRAM
  18. % spectrum - Interactive Image Classification System
  19. %
  20. % DESCRIPTION
  21. % Spectrum is an interactive signal/image classification system.
  22. % It aids the user in classifying image data. An image may be displayed,
  23. % and then pixels in the image assigned to classes by holding the mouse button
  24. % down and moving the pointer over the desired pixel in the image ("painting").
  25. % For identification, classes are given a name and an unique color. A class
  26. % may contain as many pixels as desired; pixels may be moved from one class to
  27. % another. When the classification procedure is complete, the image can be
  28. % written out along with a legend file for later use.
  29. %
  30. % A "Spectral Response Curve" provides a graph giving information about the map
  31. % data (feature data) associated with a cluster. The "Legend Control" feature
  32. % is used to modify the legend of classes; among other things, you may assign
  33. % a color to a class, list the clusters contained in the class, empty a class of
  34. % clusters, transfer an entire class into another one, create a "catch-all"
  35. % class of remaining unclassified clusters, and hide selected classes
  36. % from view in order to examine the image without their
  37. % interference. A "Zoom" capability allows you to zoom in on the image;
  38. % when the Update Mode is set to Button Press, clusters may be assigned to a
  39. % class by "painting" on the zoom window rather than in the image.
  40. %
  41. % Spectrum was specifically designed for images that have been pre-clustered,
  42. % and therefore have additional information associated with them, this info
  43. % being stored in the map data. This special info in the map data will
  44. % include N rows of cluster centers (mean vectors), where each column of the info
  45. % is associated with a special feature of interest that was extracted
  46. % during the previously-used clustering algorithm. If you do NOT have
  47. % pre-clustered data, spectrum can still be used to interactively classify the
  48. % pixels in the image; however, if you do have pre-clustered images, there are
  49. % additional features of spectrum that you may take advantage of:
  50. % - display of different map columns as Red, Green, or Blue.
  51. % - display of functions of map columns as Red, Green, or Blue
  52. % (note: not implemented as of Khoros 2.0 Beta).
  53. % - a 2D scatter plot where one map column provides the X coordinates, and another
  54. % map column provides the Y coordinates; unassigned cluster numbers appear in
  55. % white, while assigned cluster numbers appear in the same color as was specified
  56. % for their class in the legend.
  57. % - the same 2D scatter plot as above, but with specified functions of map columns
  58. % providing the X and Y coordinates.
  59. %
  60. % Please see the manual section on I/O if you have additional information
  61. % associated with the input image provided by a clustering algorithm; this
  62. % section details the input format expected by spectrum for such information.
  63. % In addition, this section also details the ascii Legend File that is used with
  64. % "spectrum".
  65. %
  66. % "Spectrum" is covered in detail in Chapter 8 of the Envision Manual; the
  67. % information given there will not be repeated here, so you are referred to that
  68. % document.
  69. %
  70. %
  71. %
  72. % EXAMPLES
  73. % % spectrum -i albq2.viff -l albq2.lgd
  74. %
  75. % "SEE ALSO"
  76. % Spectrum is covered in Chapter 8 of the Envision Manual.
  77. %
  78. % RESTRICTIONS
  79. %
  80. % REFERENCES
  81. % Spectrum is covered in Chapter 8 of the Envision Manual.
  82. %
  83. % COPYRIGHT
  84. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  85. %
  86. function varargout = kspectrum(varargin)
  87. if nargin ==0
  88. Inputs={};arglist={'',''};
  89. elseif nargin ==1
  90. Inputs=varargin{1};arglist={'',''};
  91. elseif nargin ==2
  92. Inputs=varargin{1}; arglist=varargin{2};
  93. else error('Usage: [out1,..] = kspectrum(Inputs,arglist).');
  94. end
  95. if size(arglist,2)~=2
  96. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  97. end
  98. narglist={'i', '__input';'l', '__input';'t', '__input';'p', '__input';'x', -1;'y', -1;'update', 1};
  99. maxval={1,1,1,1,1000,1000,1};
  100. minval={1,1,1,1,-1,-1,1};
  101. istoggle=[1,1,1,1,1,1,1];
  102. was_set=istoggle * 0;
  103. paramtype={'InputFile','InputFile','InputFile','InputFile','Integer','Integer','Double'};
  104. % identify the input arrays and assign them to the arguments as stated by the user
  105. if ~iscell(Inputs)
  106. Inputs = {Inputs};
  107. end
  108. NumReqOutputs=0; nextinput=1; nextoutput=1;
  109. for ii=1:size(arglist,1)
  110. wasmatched=0;
  111. for jj=1:size(narglist,1)
  112. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  113. wasmatched = 1;
  114. was_set(jj) = 1;
  115. if strcmp(narglist{jj,2}, '__input')
  116. if (nextinput > length(Inputs))
  117. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  118. end
  119. narglist{jj,2} = 'OK_in';
  120. nextinput = nextinput + 1;
  121. elseif strcmp(narglist{jj,2}, '__output')
  122. if (nextoutput > nargout)
  123. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  124. end
  125. if (isempty(arglist{ii,2}))
  126. narglist{jj,2} = 'OK_out';
  127. else
  128. narglist{jj,2} = arglist{ii,2};
  129. end
  130. nextoutput = nextoutput + 1;
  131. if (minval{jj} == 0)
  132. NumReqOutputs = NumReqOutputs - 1;
  133. end
  134. elseif isstr(arglist{ii,2})
  135. narglist{jj,2} = arglist{ii,2};
  136. else
  137. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  138. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  139. end
  140. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  141. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  142. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  143. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  144. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  145. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  146. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  147. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  148. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  149. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  150. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  151. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  152. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  153. end
  154. end
  155. end
  156. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  157. narglist{jj,2} = arglist{ii,2};
  158. end
  159. end
  160. end
  161. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  162. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  163. end
  164. end
  165. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  166. for jj=1:size(narglist,1)
  167. if strcmp(paramtype{jj}, 'Toggle')
  168. if (narglist{jj,2} ==0)
  169. narglist{jj,1} = '';
  170. end;
  171. narglist{jj,2} = '';
  172. end;
  173. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  174. narglist{jj,1} = '';
  175. narglist{jj,2} = '';
  176. end;
  177. if strcmp(narglist{jj,2}, '__input')
  178. if (minval{jj} == 0) % meaning this input is required
  179. if (nextinput > size(Inputs))
  180. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  181. else
  182. narglist{jj,2} = 'OK_in';
  183. nextinput = nextinput + 1;
  184. end
  185. else % this is an optional input
  186. if (nextinput <= length(Inputs))
  187. narglist{jj,2} = 'OK_in';
  188. nextinput = nextinput + 1;
  189. else
  190. narglist{jj,1} = '';
  191. narglist{jj,2} = '';
  192. end;
  193. end;
  194. else
  195. if strcmp(narglist{jj,2}, '__output')
  196. if (minval{jj} == 0) % this is a required output
  197. if (nextoutput > nargout & nargout > 1)
  198. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  199. else
  200. narglist{jj,2} = 'OK_out';
  201. nextoutput = nextoutput + 1;
  202. NumReqOutputs = NumReqOutputs-1;
  203. end
  204. else % this is an optional output
  205. if (nargout - nextoutput >= NumReqOutputs)
  206. narglist{jj,2} = 'OK_out';
  207. nextoutput = nextoutput + 1;
  208. else
  209. narglist{jj,1} = '';
  210. narglist{jj,2} = '';
  211. end;
  212. end
  213. end
  214. end
  215. end
  216. if nargout
  217. varargout = cell(1,nargout);
  218. else
  219. varargout = cell(0);
  220. end
  221. global KhorosRoot
  222. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  223. w=['"' KhorosRoot];
  224. else
  225. if ispc
  226. w='"C:\Program Files\dip\khorosBin\';
  227. else
  228. [s,w] = system('which cantata');
  229. w=['"' w(1:end-8)];
  230. end
  231. end
  232. callKhoros([w 'spectrum" '],Inputs,narglist);