PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kcclassreport.m

http://github.com/aludnam/MATLAB
Objective C | 203 lines | 203 code | 0 blank | 0 comment | 20 complexity | af61c2d5a92e14aed01555e0e13edc39 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kcclassreport 'Create a report for the classification results'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros cclassreport.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Classification Result', required: 'classification result file name'
  6. % InputFile: icsf 'Input Classes Specification File', required: 'input classes specification file'
  7. % MultiChoice: omode 'Output Mode', default: 1: 'output mode toggle'
  8. % Choices are:
  9. % 1: 'Text'
  10. % 2: 'LaTeX'
  11. % 3: 'HTML'
  12. % 4: 'CSV'
  13. % OutputFile: o 'Output Report', optional: 'text report based on the input'
  14. %
  15. % Example: o = kcclassreport({i, icsf}, {'i','';'icsf','';'omode',1;'o',''})
  16. %
  17. % Khoros helpfile follows below:
  18. %
  19. % PROGRAM
  20. % cclassreport - Create a report for the classification results
  21. %
  22. % DESCRIPTION
  23. % This program use the classification result from any classifier in the Classify toolbox (paseed in [-i] parameter) and a Class Specification File (passed in the [-icsf] parameter) to create a report for the classification. The report will contain, for each class in the Class Specification File, the title for the class, the number of pixels classified as that class, the percentage of pixels classified as that class and optionally the area for that class (if specified in the user interface). Options for this program and the related file formats are described below:
  24. % The Text (ASCII) format option ([-omode 1]) formats the output using spaces to make a simple table. The fields in the report are evenly-spaced, making it easy for further text processing by perl or another similar utility.
  25. % The LaTeX format option ([-omode 2]) formats the output as a LaTeX table, complete with caption and label. It can be included in any LaTeX file with the \\input command or read as a block of text using a text editor. The caption for the table will contain the file name of the classification result used for the generation of the report, and should be changed for reports - a reminder of this will appear when you run latex. For references about LaTeX, please refer to the Classify Toolbox Manual.
  26. % The HTML format option ([-omode 3]) also create a table formatted in HTML, including caption, ready for inclusion in HTML documents. The caption should be changed by the user, originally the file name will be used as caption.
  27. % The CSV format option ([-omode 4]) create a comma-delimited file (where the fields are separated by commas) which can be read/imported by Excel and other spreadsheet applications. One caveat: if the class names in the Class Specification File has commas on it, the application reading the CSV report will get confused, some manual editing will be necessary.
  28. % The CSF (Class Specification File) is an ASCII file used to get the classes names for the report. Its format is very simple:
  29. % * lines starting with # or / are considered as comments
  30. % * each line defines a class: the first token is the index for that class, the second, third and fourth defines the red, green and blue values to be used for the thematic maps and the rest of the line defines the title for the class.
  31. % Example: the line
  32. % 3 255 255 0 This is the yellow class
  33. % defines the color for the class index 3 (255,255,0 = Yellow) and the title for the class index 3 ("This is the yellow class")
  34. % \fBImportant:" the index for the class in the Class Specification Format must \fBnot\fP be zero: the class zero is reserved for pixels which were rejected by the classification process. In other words, the classes indexes should be larger or equal to 1 (one).
  35. % The user can optionally provide a scale (with the [-scale] and [-scaleunit] parameters) for the pixels in the images and a string representing the units. For example, for Landsat TM-5 images (except for band 6), each pixel represents 30x30 meters in the ground, so the user could specify a scale of 1 pixel = 900 m2 or 1 pixel = 0.0009 km2. The predefined units are pixels, mm2, cm2, m2 and km2, but the user can specify different units. If the scale is specified, the report will contain the area in pixels and in the specified unit.
  36. % Output can be redirected to a file if the parameter [-o] is specified, otherwise output will be to kstdout.
  37. %
  38. %
  39. %
  40. % EXAMPLES
  41. % All examples for the Classify toolbox are listed on the Classify Toolbox Manual. For an example of this program, please see the example workspace Classify:workspaces:MAXLIK.
  42. %
  43. % "SEE ALSO"
  44. % ccompare, cthematicmap
  45. %
  46. % RESTRICTIONS
  47. %
  48. % REFERENCES
  49. % All references for the Classify toolbox are listed on the Classify Toolbox Manual.
  50. %
  51. % COPYRIGHT
  52. % Copyright (C) 1997 Rafael Santos. Khoros (C) Khoral Research, Inc.
  53. %
  54. function varargout = kcclassreport(varargin)
  55. if nargin ==0
  56. Inputs={};arglist={'',''};
  57. elseif nargin ==1
  58. Inputs=varargin{1};arglist={'',''};
  59. elseif nargin ==2
  60. Inputs=varargin{1}; arglist=varargin{2};
  61. else error('Usage: [out1,..] = kcclassreport(Inputs,arglist).');
  62. end
  63. if size(arglist,2)~=2
  64. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  65. end
  66. narglist={'i', '__input';'icsf', '__input';'omode', 1;'o', '__output'};
  67. maxval={0,0,0,1};
  68. minval={0,0,0,1};
  69. istoggle=[0,0,0,1];
  70. was_set=istoggle * 0;
  71. paramtype={'InputFile','InputFile','MultiChoice','OutputFile'};
  72. % identify the input arrays and assign them to the arguments as stated by the user
  73. if ~iscell(Inputs)
  74. Inputs = {Inputs};
  75. end
  76. NumReqOutputs=0; nextinput=1; nextoutput=1;
  77. for ii=1:size(arglist,1)
  78. wasmatched=0;
  79. for jj=1:size(narglist,1)
  80. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  81. wasmatched = 1;
  82. was_set(jj) = 1;
  83. if strcmp(narglist{jj,2}, '__input')
  84. if (nextinput > length(Inputs))
  85. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  86. end
  87. narglist{jj,2} = 'OK_in';
  88. nextinput = nextinput + 1;
  89. elseif strcmp(narglist{jj,2}, '__output')
  90. if (nextoutput > nargout)
  91. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  92. end
  93. if (isempty(arglist{ii,2}))
  94. narglist{jj,2} = 'OK_out';
  95. else
  96. narglist{jj,2} = arglist{ii,2};
  97. end
  98. nextoutput = nextoutput + 1;
  99. if (minval{jj} == 0)
  100. NumReqOutputs = NumReqOutputs - 1;
  101. end
  102. elseif isstr(arglist{ii,2})
  103. narglist{jj,2} = arglist{ii,2};
  104. else
  105. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  106. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  107. end
  108. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  109. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  110. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  111. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  112. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  113. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  114. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  115. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  116. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  117. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  118. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  119. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  120. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  121. end
  122. end
  123. end
  124. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  125. narglist{jj,2} = arglist{ii,2};
  126. end
  127. end
  128. end
  129. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  130. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  131. end
  132. end
  133. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  134. for jj=1:size(narglist,1)
  135. if strcmp(paramtype{jj}, 'Toggle')
  136. if (narglist{jj,2} ==0)
  137. narglist{jj,1} = '';
  138. end;
  139. narglist{jj,2} = '';
  140. end;
  141. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  142. narglist{jj,1} = '';
  143. narglist{jj,2} = '';
  144. end;
  145. if strcmp(narglist{jj,2}, '__input')
  146. if (minval{jj} == 0) % meaning this input is required
  147. if (nextinput > size(Inputs))
  148. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  149. else
  150. narglist{jj,2} = 'OK_in';
  151. nextinput = nextinput + 1;
  152. end
  153. else % this is an optional input
  154. if (nextinput <= length(Inputs))
  155. narglist{jj,2} = 'OK_in';
  156. nextinput = nextinput + 1;
  157. else
  158. narglist{jj,1} = '';
  159. narglist{jj,2} = '';
  160. end;
  161. end;
  162. else
  163. if strcmp(narglist{jj,2}, '__output')
  164. if (minval{jj} == 0) % this is a required output
  165. if (nextoutput > nargout & nargout > 1)
  166. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  167. else
  168. narglist{jj,2} = 'OK_out';
  169. nextoutput = nextoutput + 1;
  170. NumReqOutputs = NumReqOutputs-1;
  171. end
  172. else % this is an optional output
  173. if (nargout - nextoutput >= NumReqOutputs)
  174. narglist{jj,2} = 'OK_out';
  175. nextoutput = nextoutput + 1;
  176. else
  177. narglist{jj,1} = '';
  178. narglist{jj,2} = '';
  179. end;
  180. end
  181. end
  182. end
  183. end
  184. if nargout
  185. varargout = cell(1,nargout);
  186. else
  187. varargout = cell(1,1);
  188. end
  189. global KhorosRoot
  190. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  191. w=['"' KhorosRoot];
  192. else
  193. if ispc
  194. w='"C:\Program Files\dip\khorosBin\';
  195. else
  196. [s,w] = system('which cantata');
  197. w=['"' w(1:end-8)];
  198. end
  199. end
  200. [varargout{:}]=callKhoros([w 'cclassreport" '],Inputs,narglist);