PageRenderTime 71ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvmindis.m

http://github.com/aludnam/MATLAB
Objective C | 230 lines | 227 code | 3 blank | 0 comment | 55 complexity | 364a23e188dbda00c06342417ff55e85 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvmindis 'Minimum Distance Classifier (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vmindis.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Image ', required: 'input image to be classified'
  6. % InputFile: i2 'Input Center/Class Image', required: 'input center/class image'
  7. % Integer: b 'Border Width ', default: 0: ' specifies the border width in pixels (default = 0)'
  8. % OutputFile: o 'Output Classified Image ', required: 'output specifying which vector belongs to which cluster'
  9. %
  10. % Example: o = kvmindis({i1, i2}, {'i1','';'i2','';'b',0;'o',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % vmindis - Minimum Distance Classifier (K1)
  16. %
  17. % DESCRIPTION
  18. % .I vmindis
  19. % is a simple minimum distance classifier. The distance metric used
  20. % to the Euclidean distance. This routine accepts two images as the
  21. % input. The image that corresponds to the -i1 argument is the image
  22. % that needs to be classified. This image can be have as many data
  23. % bands as necessary. The number of data bands depicts the dimensionality
  24. % of the vectors. Each pixel in the image is a vector with dimensionality
  25. % of the number of data bands.
  26. %
  27. % The other input image which corresponds to the -i2 argument is
  28. % the prototype image. The last data band of this image is the
  29. % class data band. This image must contain the same number of data
  30. % bands as the other input image plus an extra data band that represents
  31. % the class mapping. This
  32. % image would most likely have been created by vkmeans or some other
  33. % routine that will give cluster centers. This image contains vectors that
  34. % correspond to the prototype of each class.
  35. %
  36. % As stated above the center image's last data band is a class data band. The
  37. % class data band simply maps each vector in the center image to the final class.
  38. %
  39. % At this point most class images must be created manually.
  40. % A class image can be created by using pseudo color in editimage
  41. % on the resulting clustered image from the
  42. % vkmeans routine. Vcustom can then be used to create the class image. Finally
  43. % kinset can be used to add the class image data to the center image. Normally
  44. % one would over cluster using vkmeans then reduce the space down. So vkmeans
  45. % might produce 100 clusters but, really only 3 clusters are desired. Pseudo
  46. % color in editimage and kasc2val can be used to reduce the space down and
  47. % create a class image. The class data might map cluster center vectors 1-50
  48. % to class 1, vectors 51-60 to class 2 and vectors 61-100 to class 3.
  49. % When the vmindis routine is run, the result would be a classified image of
  50. % three classes.
  51. %
  52. % The border option (-b) allows the user to specify a border width,
  53. % in pixels, encompassing the image. The border region is skipped
  54. % by vmindis when classification is performed.
  55. % This useful if neighborhood operators have been used
  56. % previously and have not updated edge pixels.
  57. %
  58. % All input images must be of data storage type FLOAT.
  59. %
  60. %
  61. %
  62. % EXAMPLES
  63. % vmindis -i1 aerial_image.xv -i2 vkmeans_centers -b 5 -o test
  64. %
  65. % aerial_image.xv is a 5 band image; thus, each vector has dimensionality of 5,
  66. % vkmeans_centers image is a 6 band image, 5 bands are the cluster center values
  67. % produced by vkmeans and 1 class band.
  68. % The border that vmindis will ignore is 5 pixels wide. the output image will be
  69. % a single band image called test.
  70. %
  71. % "SEE ALSO"
  72. %
  73. % RESTRICTIONS
  74. % All input images must be of data storage type FLOAT.
  75. %
  76. % REFERENCES
  77. %
  78. % COPYRIGHT
  79. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  80. %
  81. function varargout = kvmindis(varargin)
  82. if nargin ==0
  83. Inputs={};arglist={'',''};
  84. elseif nargin ==1
  85. Inputs=varargin{1};arglist={'',''};
  86. elseif nargin ==2
  87. Inputs=varargin{1}; arglist=varargin{2};
  88. else error('Usage: [out1,..] = kvmindis(Inputs,arglist).');
  89. end
  90. if size(arglist,2)~=2
  91. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  92. end
  93. narglist={'i1', '__input';'i2', '__input';'b', 0;'o', '__output'};
  94. maxval={0,0,100,0};
  95. minval={0,0,0,0};
  96. istoggle=[0,0,1,0];
  97. was_set=istoggle * 0;
  98. paramtype={'InputFile','InputFile','Integer','OutputFile'};
  99. % identify the input arrays and assign them to the arguments as stated by the user
  100. if ~iscell(Inputs)
  101. Inputs = {Inputs};
  102. end
  103. NumReqOutputs=1; nextinput=1; nextoutput=1;
  104. for ii=1:size(arglist,1)
  105. wasmatched=0;
  106. for jj=1:size(narglist,1)
  107. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  108. wasmatched = 1;
  109. was_set(jj) = 1;
  110. if strcmp(narglist{jj,2}, '__input')
  111. if (nextinput > length(Inputs))
  112. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  113. end
  114. narglist{jj,2} = 'OK_in';
  115. nextinput = nextinput + 1;
  116. elseif strcmp(narglist{jj,2}, '__output')
  117. if (nextoutput > nargout)
  118. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  119. end
  120. if (isempty(arglist{ii,2}))
  121. narglist{jj,2} = 'OK_out';
  122. else
  123. narglist{jj,2} = arglist{ii,2};
  124. end
  125. nextoutput = nextoutput + 1;
  126. if (minval{jj} == 0)
  127. NumReqOutputs = NumReqOutputs - 1;
  128. end
  129. elseif isstr(arglist{ii,2})
  130. narglist{jj,2} = arglist{ii,2};
  131. else
  132. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  133. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  134. end
  135. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  136. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  137. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  138. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  139. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  140. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  141. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  142. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  143. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  144. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  145. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  146. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  147. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  148. end
  149. end
  150. end
  151. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  152. narglist{jj,2} = arglist{ii,2};
  153. end
  154. end
  155. end
  156. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  157. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  158. end
  159. end
  160. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  161. for jj=1:size(narglist,1)
  162. if strcmp(paramtype{jj}, 'Toggle')
  163. if (narglist{jj,2} ==0)
  164. narglist{jj,1} = '';
  165. end;
  166. narglist{jj,2} = '';
  167. end;
  168. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  169. narglist{jj,1} = '';
  170. narglist{jj,2} = '';
  171. end;
  172. if strcmp(narglist{jj,2}, '__input')
  173. if (minval{jj} == 0) % meaning this input is required
  174. if (nextinput > size(Inputs))
  175. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  176. else
  177. narglist{jj,2} = 'OK_in';
  178. nextinput = nextinput + 1;
  179. end
  180. else % this is an optional input
  181. if (nextinput <= length(Inputs))
  182. narglist{jj,2} = 'OK_in';
  183. nextinput = nextinput + 1;
  184. else
  185. narglist{jj,1} = '';
  186. narglist{jj,2} = '';
  187. end;
  188. end;
  189. else
  190. if strcmp(narglist{jj,2}, '__output')
  191. if (minval{jj} == 0) % this is a required output
  192. if (nextoutput > nargout & nargout > 1)
  193. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  194. else
  195. narglist{jj,2} = 'OK_out';
  196. nextoutput = nextoutput + 1;
  197. NumReqOutputs = NumReqOutputs-1;
  198. end
  199. else % this is an optional output
  200. if (nargout - nextoutput >= NumReqOutputs)
  201. narglist{jj,2} = 'OK_out';
  202. nextoutput = nextoutput + 1;
  203. else
  204. narglist{jj,1} = '';
  205. narglist{jj,2} = '';
  206. end;
  207. end
  208. end
  209. end
  210. end
  211. if nargout
  212. varargout = cell(1,nargout);
  213. else
  214. varargout = cell(1,1);
  215. end
  216. global KhorosRoot
  217. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  218. w=['"' KhorosRoot];
  219. else
  220. if ispc
  221. w='"C:\Program Files\dip\khorosBin\';
  222. else
  223. [s,w] = system('which cantata');
  224. w=['"' w(1:end-8)];
  225. end
  226. end
  227. [varargout{:}]=callKhoros([w 'vmindis" '],Inputs,narglist);