PageRenderTime 97ms CodeModel.GetById 23ms RepoModel.GetById 8ms app.codeStats 0ms

/matlab_tools/Converted/kkhisto.m

http://github.com/aludnam/MATLAB
Objective C | 303 lines | 300 code | 3 blank | 0 comment | 75 complexity | 7abd92c2771292c7c10f70a670a3058f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkhisto 'Compute Histogram for Data Object'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros khisto.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input ', required: 'Input data object'
  6. % InputFile: igate 'Gating Input', optional: 'Gating input data object'
  7. % Integer: bins 'Number of bins ', default: 256: 'number of histogram bins'
  8. % Toggle: oob 'Append out-of-bounds bins', default: 0: 'append a pair of bins for out-of-bounds data'
  9. % Toggle: map 'If map exists, pull the value data through it', default: 0: 'if map exists, pull the value data through it'
  10. % Toggle: normalize 'Normalize integrated histogram to [0..1]', default: 0: 'normalize integrated histogram to [0..1]'
  11. % OutputFile: o1 'Histogram output object', required: 'histogram output data object'
  12. % OutputFile: o2 'Integrated histogram object', optional: 'integrated histogram output object'
  13. % Toggle: whole 'Whole dataset', default: 0: 'histogram whole data set at one time'
  14. % Toggle: w 'Width', default: 0: 'include width in histogram unit'
  15. % Toggle: h 'Height', default: 0: 'include height in histogram unit'
  16. % Toggle: d 'Depth', default: 0: 'include depth in histogram unit'
  17. % Toggle: t 'Time', default: 0: 'include time in histogram unit'
  18. % Toggle: e 'Elements', default: 0: 'include elements in histogram unit'
  19. %
  20. % Example: [o1, o2] = kkhisto({i, igate}, {'i','';'igate','';'bins',256;'oob',0;'map',0;'normalize',0;'o1','';'o2','';'whole',0;'w',0;'h',0;'d',0;'t',0;'e',0})
  21. %
  22. % Khoros helpfile follows below:
  23. %
  24. % PROGRAM
  25. % khisto - Compute Histogram for Data Object
  26. %
  27. % DESCRIPTION
  28. % .I khisto
  29. % computes histograms from data objects and stores the histogram data in
  30. % another data object. An independent histogram is computed and stored for each
  31. % "unit" of data in the value segment of the input data object.
  32. %
  33. % A unit is
  34. % defined by the settings of the -w,-h,-d,-t,-e and -whole options. For example,
  35. % if it is desired to compute an independent histogram for each WxH plane of a
  36. % WHDTE=(512,480,1,1,256) object, then the unit we want is specified by supplying
  37. % -w and -h and there will be 256 columns in the output object, each column
  38. % being the histogram of a WxH plane. If we want a single histogram for the
  39. % whole data object, then
  40. % we can obtain that result by supplying -whole, or -w -h -e, or -w -h -d -t -e
  41. % since these combinations all cause the histogram unit to span all of the data.
  42. % In this case the output object will have only a single column representing the
  43. % histogram of the whole data set.
  44. %
  45. % Histograms are stored in the output
  46. % data object as column vectors in the WxH plane, one column per histogram unit.
  47. % The computed histograms are stored
  48. % in the order in which the units are accessed in the index order
  49. % assigned to the value segment of the input data object. For example, for a
  50. % value segment with WHDTE=(512,126,48,1,1), with a HxD unit (specified by -h -d)
  51. % and the default index order (WHDTE), then there will be 512 columns in the
  52. % output object. The histogram for the HxD plane at (0,x,x,0,0) will be stored
  53. % in column #0; that for the HxD plane at (1,x,x,0,0) will be stored in column
  54. % #1, and that for the HxD plane at (N,x,x,0,0) will be stored in column #N.
  55. %
  56. % Within each column, the count computed for bin #M is stored in row #M.
  57. %
  58. % The histogram structure is specified by three parameters:
  59. %
  60. % "min side of minimum bin (starting value)" 15
  61. % This number specifies the most negative number that can be trapped in the
  62. % histogram array. Another way to define it is as the lower edge of first
  63. % histogram bin.
  64. %
  65. % "binwidth" 15
  66. % This is the width of each histogram bin.
  67. %
  68. % "bins" 15
  69. % This is the total number of bins to be used in the histogram.
  70. %
  71. % Values are assigned to bin index [0...bins-1] using the following procedure:
  72. %
  73. %
  74. % bin_num = (input_val - mina) / binwidth
  75. %
  76. % if (input_val == min + bins*binwidth) bin_num = bins - 1
  77. %
  78. %
  79. % With this arrangement, a bin collects input values ranging from the value of the
  80. % left edge inclusively up to the value of the right edge exclusively. The
  81. % exception is the last bin which collects values between the left and right
  82. % edges inclusively (for both edges). If the computed bin_num falls
  83. % outside of the array, then that data point is ignored in the histogram unless
  84. % the -oob (append out-of-bounds bins) flag is supplied (described below).
  85. %
  86. % If the input data object has a mask, then data points marked as invalid
  87. % by the mask are ignored in the histogram calculations.
  88. %
  89. % If a gate object is supplied, then only those data points with a value
  90. % corresponding to non-zero in the gate image will be histogrammed. If a
  91. % a gate object is supplied and the input has a mask, then data points are
  92. % ignored if masked "or" marked for "ignore" by the gate object. The gate
  93. % object must have the same value segment dimensions as the input object.
  94. %
  95. % If the input data object has a map, then the data can be optionally
  96. % pulled through the map before histogramming depending on the setting
  97. % of the -map flag. If the input object has a map and -map is supplied, then
  98. % the data will be pulled through the map before histogramming, potentially
  99. % greatly multiplying the size of the data set. If the input object has a map
  100. % and -map is "not" supplied, then the histogram operation will be carried
  101. % out on the "map indices" since that is what is stored in the data (this
  102. % may be useful for data that has been pseudocolored, for example).
  103. %
  104. % If the out-of-bounds flag (-oob) is supplied, then two additional bins will
  105. % be placed at the end of the histogram. The first one will contain the
  106. % number of data values that fell outside of the histogram array on the
  107. % low (more negative) side, and the second will contain the number of data values
  108. % that fell outside the histogram array on the high (more positive) side.
  109. % This option is useful when little is known about the range of the data
  110. % and one is not sure if the specified range of the histogram array is
  111. % capturing all of the data.
  112. %
  113. % The optional integrated histogram output object conforms to the same size and
  114. % structure as the histogram output object except that it is of data type KDOUBLE
  115. % and each histogram has been integrated. The integrated histograms can optionally
  116. % be normalized (each histogram independently) to the range [0..1].
  117. %
  118. % .I khisto
  119. % utilizes data services internally and can process large data sets.
  120. % All internal calculations are done in double precision. All input data
  121. % is converted to KDOUBLE by data services after being read from the input data
  122. % object. The output histogram data object is of type KULONG.
  123. % Complex input data is converted before histogramming by taking the real part.
  124. %
  125. %
  126. %
  127. %
  128. % EXAMPLES
  129. %
  130. % % khisto -i clouds.seq -o h.clouds -w -h -min 0
  131. % -binwidth 1 -bins 256
  132. % will construct an interesting histogram data set from the cloud sequence.
  133. % This sequence is comprised of a set of 582 512x480 frames, taken 15 seconds
  134. % apart, stored as WHDTE=(512,480,1,582,1). Each frame views the same
  135. % section of sky as a storm develops. The output is best visualized using
  136. % editimage with the SA pseudocolor option turned on. Here, the columns of the
  137. % output image are for the frames in time order, so it is easy to see how
  138. % the storm phases develop, modulate, and peak during this period.
  139. %
  140. % "SEE ALSO"
  141. % khistops(1)
  142. %
  143. % RESTRICTIONS
  144. %
  145. % If the input data is complex, then you may want to convert it yourself using
  146. % whatever means you require; the default for complex input is to take only
  147. % the real part.
  148. %
  149. % REFERENCES
  150. %
  151. % COPYRIGHT
  152. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  153. %
  154. function varargout = kkhisto(varargin)
  155. if nargin ==0
  156. Inputs={};arglist={'',''};
  157. elseif nargin ==1
  158. Inputs=varargin{1};arglist={'',''};
  159. elseif nargin ==2
  160. Inputs=varargin{1}; arglist=varargin{2};
  161. else error('Usage: [out1,..] = kkhisto(Inputs,arglist).');
  162. end
  163. if size(arglist,2)~=2
  164. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  165. end
  166. narglist={'i', '__input';'igate', '__input';'bins', 256;'oob', 0;'map', 0;'normalize', 0;'o1', '__output';'o2', '__output';'whole', 0;'w', 0;'h', 0;'d', 0;'t', 0;'e', 0};
  167. maxval={0,1,2,0,0,0,0,1,0,0,0,0,0,0};
  168. minval={0,1,2,0,0,0,0,1,0,0,0,0,0,0};
  169. istoggle=[0,1,1,1,1,1,0,1,1,1,1,1,1,1];
  170. was_set=istoggle * 0;
  171. paramtype={'InputFile','InputFile','Integer','Toggle','Toggle','Toggle','OutputFile','OutputFile','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle'};
  172. % identify the input arrays and assign them to the arguments as stated by the user
  173. if ~iscell(Inputs)
  174. Inputs = {Inputs};
  175. end
  176. NumReqOutputs=1; nextinput=1; nextoutput=1;
  177. for ii=1:size(arglist,1)
  178. wasmatched=0;
  179. for jj=1:size(narglist,1)
  180. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  181. wasmatched = 1;
  182. was_set(jj) = 1;
  183. if strcmp(narglist{jj,2}, '__input')
  184. if (nextinput > length(Inputs))
  185. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  186. end
  187. narglist{jj,2} = 'OK_in';
  188. nextinput = nextinput + 1;
  189. elseif strcmp(narglist{jj,2}, '__output')
  190. if (nextoutput > nargout)
  191. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  192. end
  193. if (isempty(arglist{ii,2}))
  194. narglist{jj,2} = 'OK_out';
  195. else
  196. narglist{jj,2} = arglist{ii,2};
  197. end
  198. nextoutput = nextoutput + 1;
  199. if (minval{jj} == 0)
  200. NumReqOutputs = NumReqOutputs - 1;
  201. end
  202. elseif isstr(arglist{ii,2})
  203. narglist{jj,2} = arglist{ii,2};
  204. else
  205. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  206. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  207. end
  208. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  209. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  210. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  211. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  212. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  213. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  214. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  215. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  216. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  217. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  218. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  219. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  220. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  221. end
  222. end
  223. end
  224. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  225. narglist{jj,2} = arglist{ii,2};
  226. end
  227. end
  228. end
  229. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  230. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  231. end
  232. end
  233. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  234. for jj=1:size(narglist,1)
  235. if strcmp(paramtype{jj}, 'Toggle')
  236. if (narglist{jj,2} ==0)
  237. narglist{jj,1} = '';
  238. end;
  239. narglist{jj,2} = '';
  240. end;
  241. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  242. narglist{jj,1} = '';
  243. narglist{jj,2} = '';
  244. end;
  245. if strcmp(narglist{jj,2}, '__input')
  246. if (minval{jj} == 0) % meaning this input is required
  247. if (nextinput > size(Inputs))
  248. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  249. else
  250. narglist{jj,2} = 'OK_in';
  251. nextinput = nextinput + 1;
  252. end
  253. else % this is an optional input
  254. if (nextinput <= length(Inputs))
  255. narglist{jj,2} = 'OK_in';
  256. nextinput = nextinput + 1;
  257. else
  258. narglist{jj,1} = '';
  259. narglist{jj,2} = '';
  260. end;
  261. end;
  262. else
  263. if strcmp(narglist{jj,2}, '__output')
  264. if (minval{jj} == 0) % this is a required output
  265. if (nextoutput > nargout & nargout > 1)
  266. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  267. else
  268. narglist{jj,2} = 'OK_out';
  269. nextoutput = nextoutput + 1;
  270. NumReqOutputs = NumReqOutputs-1;
  271. end
  272. else % this is an optional output
  273. if (nargout - nextoutput >= NumReqOutputs)
  274. narglist{jj,2} = 'OK_out';
  275. nextoutput = nextoutput + 1;
  276. else
  277. narglist{jj,1} = '';
  278. narglist{jj,2} = '';
  279. end;
  280. end
  281. end
  282. end
  283. end
  284. if nargout
  285. varargout = cell(1,nargout);
  286. else
  287. varargout = cell(1,1);
  288. end
  289. global KhorosRoot
  290. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  291. w=['"' KhorosRoot];
  292. else
  293. if ispc
  294. w='"C:\Program Files\dip\khorosBin\';
  295. else
  296. [s,w] = system('which cantata');
  297. w=['"' w(1:end-8)];
  298. end
  299. end
  300. [varargout{:}]=callKhoros([w 'khisto" '],Inputs,narglist);