PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kcxinspector.m

http://github.com/aludnam/MATLAB
Objective C | 190 lines | 187 code | 3 blank | 0 comment | 66 complexity | cf40407c41af49c42c54526c62bd9bff MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kcxinspector 'Interactively inspects results of classification '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros cxinspector.pane file
  3. %
  4. % Parameters:
  5. % InputFile: iorig 'Input Original Image', required: 'Input Original Image'
  6. % InputFile: iclass 'Input Classified Image', required: 'Input Classified Image'
  7. % InputFile: idist 'Input Probabilities', optional: 'input distances (probabilities) file'
  8. % InputFile: icsf 'Class Specification File', required: 'input class specification file'
  9. %
  10. % Example: kcxinspector({iorig, iclass, idist, icsf}, {'iorig','';'iclass','';'idist','';'icsf',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % cxinspector - Interactively inspects results of classification
  16. %
  17. % DESCRIPTION
  18. % Inspector (cxinspector xvroutine) allows the user to interactively inspect the results for a classification using the classifiers in the Classify Toolbox. It can be used to verify pixels in the image for classification errors and results. The user can click on pixels on the classified result to see its original values and classification results.
  19. % This xvroutine expects as inputs the original image [-iorig], the classified result [-iclass], and the Class Specification File for that classification task [-icsf], which will be used to get the classes' labels.
  20. % Optionally the Inspector xvroutine can use the output for the Output Probabilities that most classifiers can create which are related with the discriminant functions for that classifier. If these values are presented as input for the parameter [-idist], their values will be presented in the output window.
  21. % The xvroutine will have a workspace for display of images that can display either the original image or the classification result. When the mouse is clicked on the workspace, a small text report will be output'd on the Output Window (which is shown when the Output button is pressed) with basic information about the classifier, the position where the user clicked the mouse, the original input data at that position and the classification result for that pixel.
  22. % There is a Image Display button which will bring a panel where the user can set whether the original image or the classification result will be displayed, whether the routine will use a private colormap for display and if the images are multiband (i.e. images with depth and/or time > 1) which band will be displayed.
  23. %
  24. %
  25. %
  26. % EXAMPLES
  27. % All examples for the Classify toolbox are listed on the Classify Toolbox Manual. For an example of this routine, please see the Classify:workspaces:MINDIST example workspace.
  28. %
  29. % "SEE ALSO"
  30. % cthematicmap, Class Specification File format in the Classify Toolbox Manual.
  31. %
  32. % RESTRICTIONS
  33. % Expect the parameter [-icsf] to point to a valid Class Specification file, and the parameters [-iclass] to be a result of classification with one of the classifiers in this toolbox.
  34. %
  35. % REFERENCES
  36. % All references for the Classify toolbox are listed on the Classify Toolbox Manual.
  37. %
  38. % COPYRIGHT
  39. % Copyright (C) 1997 Rafael Santos. Khoros (C) Khoral Research, Inc.
  40. %
  41. function varargout = kcxinspector(varargin)
  42. if nargin ==0
  43. Inputs={};arglist={'',''};
  44. elseif nargin ==1
  45. Inputs=varargin{1};arglist={'',''};
  46. elseif nargin ==2
  47. Inputs=varargin{1}; arglist=varargin{2};
  48. else error('Usage: [out1,..] = kcxinspector(Inputs,arglist).');
  49. end
  50. if size(arglist,2)~=2
  51. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  52. end
  53. narglist={'iorig', '__input';'iclass', '__input';'idist', '__input';'icsf', '__input'};
  54. maxval={0,0,1,0};
  55. minval={0,0,1,0};
  56. istoggle=[0,0,1,0];
  57. was_set=istoggle * 0;
  58. paramtype={'InputFile','InputFile','InputFile','InputFile'};
  59. % identify the input arrays and assign them to the arguments as stated by the user
  60. if ~iscell(Inputs)
  61. Inputs = {Inputs};
  62. end
  63. NumReqOutputs=0; nextinput=1; nextoutput=1;
  64. for ii=1:size(arglist,1)
  65. wasmatched=0;
  66. for jj=1:size(narglist,1)
  67. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  68. wasmatched = 1;
  69. was_set(jj) = 1;
  70. if strcmp(narglist{jj,2}, '__input')
  71. if (nextinput > length(Inputs))
  72. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  73. end
  74. narglist{jj,2} = 'OK_in';
  75. nextinput = nextinput + 1;
  76. elseif strcmp(narglist{jj,2}, '__output')
  77. if (nextoutput > nargout)
  78. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  79. end
  80. if (isempty(arglist{ii,2}))
  81. narglist{jj,2} = 'OK_out';
  82. else
  83. narglist{jj,2} = arglist{ii,2};
  84. end
  85. nextoutput = nextoutput + 1;
  86. if (minval{jj} == 0)
  87. NumReqOutputs = NumReqOutputs - 1;
  88. end
  89. elseif isstr(arglist{ii,2})
  90. narglist{jj,2} = arglist{ii,2};
  91. else
  92. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  93. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  94. end
  95. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  96. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  97. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  98. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  99. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  100. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  101. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  102. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  103. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  104. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  105. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  106. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  107. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  108. end
  109. end
  110. end
  111. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  112. narglist{jj,2} = arglist{ii,2};
  113. end
  114. end
  115. end
  116. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  117. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  118. end
  119. end
  120. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  121. for jj=1:size(narglist,1)
  122. if strcmp(paramtype{jj}, 'Toggle')
  123. if (narglist{jj,2} ==0)
  124. narglist{jj,1} = '';
  125. end;
  126. narglist{jj,2} = '';
  127. end;
  128. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  129. narglist{jj,1} = '';
  130. narglist{jj,2} = '';
  131. end;
  132. if strcmp(narglist{jj,2}, '__input')
  133. if (minval{jj} == 0) % meaning this input is required
  134. if (nextinput > size(Inputs))
  135. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  136. else
  137. narglist{jj,2} = 'OK_in';
  138. nextinput = nextinput + 1;
  139. end
  140. else % this is an optional input
  141. if (nextinput <= length(Inputs))
  142. narglist{jj,2} = 'OK_in';
  143. nextinput = nextinput + 1;
  144. else
  145. narglist{jj,1} = '';
  146. narglist{jj,2} = '';
  147. end;
  148. end;
  149. else
  150. if strcmp(narglist{jj,2}, '__output')
  151. if (minval{jj} == 0) % this is a required output
  152. if (nextoutput > nargout & nargout > 1)
  153. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  154. else
  155. narglist{jj,2} = 'OK_out';
  156. nextoutput = nextoutput + 1;
  157. NumReqOutputs = NumReqOutputs-1;
  158. end
  159. else % this is an optional output
  160. if (nargout - nextoutput >= NumReqOutputs)
  161. narglist{jj,2} = 'OK_out';
  162. nextoutput = nextoutput + 1;
  163. else
  164. narglist{jj,1} = '';
  165. narglist{jj,2} = '';
  166. end;
  167. end
  168. end
  169. end
  170. end
  171. if nargout
  172. varargout = cell(1,nargout);
  173. else
  174. varargout = cell(0);
  175. end
  176. global KhorosRoot
  177. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  178. w=['"' KhorosRoot];
  179. else
  180. if ispc
  181. w='"C:\Program Files\dip\khorosBin\';
  182. else
  183. [s,w] = system('which cantata');
  184. w=['"' w(1:end-8)];
  185. end
  186. end
  187. callKhoros([w 'cxinspector" '],Inputs,narglist);