PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkmegathresh.m

http://github.com/aludnam/MATLAB
Objective C | 345 lines | 342 code | 3 blank | 0 comment | 55 complexity | 474635c78c90fbfc3bbacf2b6e33a35a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkmegathresh 'Threshold the Range of Data Values in Data Object'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kmegathresh.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input ', required: 'Input file'
  6. % OutputFile: o ' Output ', required: 'output file'
  7. % InputFile: ilc 'Lower Cutoff Values File', optional: 'File containing lower cutoff values'
  8. % InputFile: iuc 'Upper Cutoff Values File', optional: 'File containing upper cutoff values'
  9. %
  10. % Example: o = kkmegathresh({i, ilc, iuc}, {'i','';'o','';'ilc','';'iuc',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % kmegathresh - Threshold the Range of Data Values in Data Object
  16. %
  17. % DESCRIPTION
  18. % The "MegaThresh" operator (kemgathresh) generates a two-level Output
  19. % data object (o) by thresholding the values in the Input data object (i).
  20. % Upper and lower cutoff values can be specified as either single constant
  21. % values (lc, uc), or sets of values passed in as data objects (ilc, iuc).
  22. % It is not necessary to specify both of the upper and lower cutoff values.
  23. % If only the Lower Cutoff is specified, all values at and above it are in
  24. % the threshold range. If only the Upper Cutoff is specified, all values at
  25. % and below it are in the threshold range. Output levels can be set using
  26. % the "True" and "False" Value options (tval, fval). The True Value (tval)
  27. % is assigned to values that are within the threshold range, and all values
  28. % outside of the threshold range are set to the False Value. The data type
  29. % of the Output object will be the same as the Input object data type.
  30. %
  31. % The following four diagrams illustrate how the given operation is evaluated
  32. % for different combinations of upper and lower cutoffs. The plots are example
  33. % data histograms. Threshold output assignment rules are given following the
  34. % diagrams.
  35. % .KS
  36. %
  37. % "\fBLower Cutoff Only:"" 5
  38. %
  39. %
  40. % \f(CW
  41. % lower cutoff result: |<-F->|<----T---->|
  42. % | | : . |
  43. % | .:.:. .::: |
  44. % |:. .::::::.::::: |
  45. % |::::::::::::::::.|
  46. % ------|------------
  47. % lower cutoff (lc)
  48. % if value < lc cutoff result = False
  49. % if value >= lc cutoff result = True
  50. % "
  51. %
  52. % .KE
  53. % .KS
  54. %
  55. % "\fBUpper Cutoff Only:"" 5
  56. %
  57. %
  58. % \f(CW
  59. % upper cutoff result: |<----T---->|<-F->|
  60. % | : | . |
  61. % | .:.:. .::: |
  62. % |:. .::::::.::::: |
  63. % |::::::::::::::::.|
  64. % ------------|------
  65. % upper cutoff (uc)
  66. %
  67. % if value > uc cutoff result = False
  68. % if value <= uc cutoff result = True
  69. % "
  70. %
  71. % .KE
  72. % .KS
  73. %
  74. % "\fBUpper Cutoff is Greater than Lower Cutoff:"" 5
  75. % When both upper and lower cutoff values are specified, and the upper cutoff
  76. % is GREATER THAN the lower cutoff, the combined cutoff result is the logical
  77. % AND of the individual results.
  78. %
  79. %
  80. % \f(CW
  81. % lower cutoff result: |<-F->|<----T---->|
  82. % upper cutoff result: |<----T---->|<-F->|
  83. %
  84. % combined cutoff result: |<-F->|<-T->|<-F->|
  85. % | | : | . |
  86. % | .:.:. .::: |
  87. % |:. .::::::.::::: |
  88. % |::::::::::::::::.|
  89. % ------|-----|------
  90. % lc uc
  91. %
  92. % if value < lc OR value > uc cutoff result = False
  93. % if value >= lc AND value <= uc cutoff result = True
  94. % "
  95. %
  96. % .KE
  97. % .KS
  98. %
  99. % "\fBUpper Cutoff is Less than Lower Cutoff:"" 5
  100. % When both upper and lower cutoff values are specified, but the upper cutoff
  101. % is LESS THAN the lower cutoff, the combined cutoff result is the logical
  102. % OR of the individual results. (Specifying the lower cutoff to be greater
  103. % than the upper cutoff inverts the operation.)
  104. %
  105. %
  106. % \f(CW
  107. % upper cutoff result: |<-T->|<----F---->|
  108. % lower cutoff result: |<----F---->|<-T->|
  109. %
  110. % combined cutoff result: |<-T->|<-F->|<-T->|
  111. % | | : | . |
  112. % | .:.:. .::: |
  113. % |:. .::::::.::::: |
  114. % |::::::::::::::::.|
  115. % ------|-----|------
  116. % uc lc
  117. %
  118. % if value < lc AND value > uc cutoff result = False
  119. % if value >= lc OR value <= uc cutoff result = True
  120. % "
  121. %
  122. % .KE
  123. %
  124. % Thresholding results are assigned according to the following rules.
  125. %
  126. % "1. When lower cutoff < upper cutoff" 5
  127. % If the data value is less than the lower cutoff, or
  128. % it is greater than the upper cutoff, set the output
  129. % value to fval.
  130. % Otherwise, set the output value to tval.
  131. %
  132. % "2. When upper cutoff < lower cutoff" 5
  133. % If the data value is less than the lower cutoff and
  134. % it is greater than the upper cutoff, set output
  135. % value to fval.
  136. % Otherwise, set the output value to tval.
  137. %
  138. % When upper and lower cutoff values are equal, the only data values that
  139. % are evaluated as TRUE are those that are equal to the cutoff values.
  140. %
  141. % "Data Type" 5
  142. % .cI $DATAMANIP/repos/shared/man/sections/value_type_1input
  143. %
  144. % "Data Objects of Different Sizes" 5
  145. % If, in addition to the input data object (i), upper or lower cutoff
  146. % objects (ilc, iuc) are supplied,
  147. % the source objects can be of different sizes. If the sizes are different,
  148. % the size of the destination object's data will be the the same as that of
  149. % the input data object. When resizing the cutoff objects, the data is
  150. % zero padded, or truncated to the size of the input object.
  151. % Alignment between the input files will always be the upper-left hand corner,
  152. % position (0,0,0,0,0).
  153. %
  154. % "Map Data - Single Input" 5
  155. % .cI $DATAMANIP/repos/shared/man/sections/map_1input
  156. %
  157. % "Map Data - Multiple Input Objects" 5
  158. % .cI $DATAMANIP/repos/shared/man/sections/map_2input
  159. %
  160. % "Validity Mask - Single Input" 5
  161. % .cI $DATAMANIP/repos/shared/man/sections/mask_1input
  162. %
  163. % "Validity Mask - Multiple Input Objects" 5
  164. % .cI $DATAMANIP/repos/shared/man/sections/mask_2input
  165. %
  166. % "Explicit Location and Time Data - Single Input" 5
  167. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_1input
  168. %
  169. % "Explicit Location and Time Data - Two Input Objects" 5
  170. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_2input
  171. %
  172. % "Failure Modes - Single Input"
  173. % .cI $DATAMANIP/repos/shared/man/sections/fail_1input
  174. %
  175. % "Failure Modes - Two Input Objects"
  176. % .cI $DATAMANIP/repos/shared/man/sections/fail_2input
  177. %
  178. % Executing "MegaThresh (kmegathresh)" runs the program \fIkclip\fP with
  179. % the -thresh option set to true (-thresh 1).
  180. %
  181. %
  182. %
  183. % EXAMPLES
  184. %
  185. % "SEE ALSO"
  186. % DATAMANIP::kthreshabove, DATAMANIP::kthreshbelow, DATAMANIP::kthreshin,
  187. % DATAMANIP::kthreshout, DATAMANIP::kclip
  188. %
  189. % RESTRICTIONS
  190. %
  191. % REFERENCES
  192. %
  193. % COPYRIGHT
  194. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  195. %
  196. function varargout = kkmegathresh(varargin)
  197. if nargin ==0
  198. Inputs={};arglist={'',''};
  199. elseif nargin ==1
  200. Inputs=varargin{1};arglist={'',''};
  201. elseif nargin ==2
  202. Inputs=varargin{1}; arglist=varargin{2};
  203. else error('Usage: [out1,..] = kkmegathresh(Inputs,arglist).');
  204. end
  205. if size(arglist,2)~=2
  206. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  207. end
  208. narglist={'i', '__input';'o', '__output';'ilc', '__input';'iuc', '__input'};
  209. maxval={0,0,1,1};
  210. minval={0,0,1,1};
  211. istoggle=[0,0,1,1];
  212. was_set=istoggle * 0;
  213. paramtype={'InputFile','OutputFile','InputFile','InputFile'};
  214. % identify the input arrays and assign them to the arguments as stated by the user
  215. if ~iscell(Inputs)
  216. Inputs = {Inputs};
  217. end
  218. NumReqOutputs=1; nextinput=1; nextoutput=1;
  219. for ii=1:size(arglist,1)
  220. wasmatched=0;
  221. for jj=1:size(narglist,1)
  222. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  223. wasmatched = 1;
  224. was_set(jj) = 1;
  225. if strcmp(narglist{jj,2}, '__input')
  226. if (nextinput > length(Inputs))
  227. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  228. end
  229. narglist{jj,2} = 'OK_in';
  230. nextinput = nextinput + 1;
  231. elseif strcmp(narglist{jj,2}, '__output')
  232. if (nextoutput > nargout)
  233. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  234. end
  235. if (isempty(arglist{ii,2}))
  236. narglist{jj,2} = 'OK_out';
  237. else
  238. narglist{jj,2} = arglist{ii,2};
  239. end
  240. nextoutput = nextoutput + 1;
  241. if (minval{jj} == 0)
  242. NumReqOutputs = NumReqOutputs - 1;
  243. end
  244. elseif isstr(arglist{ii,2})
  245. narglist{jj,2} = arglist{ii,2};
  246. else
  247. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  248. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  249. end
  250. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  251. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  252. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  253. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  254. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  255. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  256. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  257. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  258. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  259. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  260. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  261. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  262. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  263. end
  264. end
  265. end
  266. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  267. narglist{jj,2} = arglist{ii,2};
  268. end
  269. end
  270. end
  271. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  272. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  273. end
  274. end
  275. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  276. for jj=1:size(narglist,1)
  277. if strcmp(paramtype{jj}, 'Toggle')
  278. if (narglist{jj,2} ==0)
  279. narglist{jj,1} = '';
  280. end;
  281. narglist{jj,2} = '';
  282. end;
  283. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  284. narglist{jj,1} = '';
  285. narglist{jj,2} = '';
  286. end;
  287. if strcmp(narglist{jj,2}, '__input')
  288. if (minval{jj} == 0) % meaning this input is required
  289. if (nextinput > size(Inputs))
  290. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  291. else
  292. narglist{jj,2} = 'OK_in';
  293. nextinput = nextinput + 1;
  294. end
  295. else % this is an optional input
  296. if (nextinput <= length(Inputs))
  297. narglist{jj,2} = 'OK_in';
  298. nextinput = nextinput + 1;
  299. else
  300. narglist{jj,1} = '';
  301. narglist{jj,2} = '';
  302. end;
  303. end;
  304. else
  305. if strcmp(narglist{jj,2}, '__output')
  306. if (minval{jj} == 0) % this is a required output
  307. if (nextoutput > nargout & nargout > 1)
  308. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  309. else
  310. narglist{jj,2} = 'OK_out';
  311. nextoutput = nextoutput + 1;
  312. NumReqOutputs = NumReqOutputs-1;
  313. end
  314. else % this is an optional output
  315. if (nargout - nextoutput >= NumReqOutputs)
  316. narglist{jj,2} = 'OK_out';
  317. nextoutput = nextoutput + 1;
  318. else
  319. narglist{jj,1} = '';
  320. narglist{jj,2} = '';
  321. end;
  322. end
  323. end
  324. end
  325. end
  326. if nargout
  327. varargout = cell(1,nargout);
  328. else
  329. varargout = cell(1,1);
  330. end
  331. global KhorosRoot
  332. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  333. w=['"' KhorosRoot];
  334. else
  335. if ispc
  336. w='"C:\Program Files\dip\khorosBin\';
  337. else
  338. [s,w] = system('which cantata');
  339. w=['"' w(1:end-8)];
  340. end
  341. end
  342. [varargout{:}]=callKhoros([w 'kclip" -thresh'],Inputs,narglist);