PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkmegaclip.m

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