PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kMultiColorDeconv.m

http://github.com/aludnam/MATLAB
Objective C | 198 lines | 195 code | 3 blank | 0 comment | 57 complexity | 5cbb856bbd8cbc133844947e3263dfe4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kMultiColorDeconv 'Deconvolution using ML/EM algorithm for multiple signatures and multiple colors'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros MultiColorDeconv.pane file
  3. %
  4. % Parameters:
  5. % Integer: n 'Iterations', default: 60: 'Number of iterations until algorithm stops'
  6. % Toggle: noDeconv 'No Deconvolution', default: 0: 'The convolutions during the deconvolution are not performed. Thus a pixelwise recognition is done.'
  7. % Integer: firstConv 'First E', default: 0: 'Number of first element to which deconvolution will be applied'
  8. % Integer: rW 'Border (Pixels)', default: 4: 'a gaussian Window will be applied'
  9. % Toggle: norichardson 'No Richardson', default: 0: 'do not use the richardson iteration, but the stadard ML-correction method instead'
  10. % Toggle: noPSFnorm 'Do not normalize PSFs', default: 0: 'The integral intensity of the PSFs will then not be normalized'
  11. % Double: mf 'Maximal Rel. Frequency X/Y', default: 0.8: 'Higher frequencies are suppressed in X/Y direction'
  12. % Double: mzf 'Z', default: 0.4: 'Higher frequencies are suppressed in Z-direction'
  13. % InputFile: i 'Measured Image', required: 'Measured confocal image'
  14. % InputFile: p 'PSF', required: 'PSF needed for ML algorithm (same size as measured data)'
  15. % InputFile: cmatrix 'Color Matrix', required: 'This matrix describes the colors (columns), that each spectral signature (row) has'
  16. % InputFile: s 'Start File', optional: 'file to start iteration with'
  17. % InputFile: Over 'Overrelaxation Table', optional: 'Table for Overrelaxation Factors'
  18. % Toggle: HolmesLiu 'Holmes & Liu', default: 0: 'If selected, the overrelaxation is choosen according to the Holmes&Liu paper. This specific implementation is however rather slow.'
  19. % Double: penalty 'Penalty', default: 0.05: 'Penalty value (for intensity)'
  20. % Double: rpenalty 'Region Penalty', default: -0.02: 'Penalty value (for intensity)'
  21. % OutputFile: o 'Recon. Image', required: 'Resulting output data object'
  22. % OutputFile: cmatout 'Recon. Color Matrix', optional: 'The output of the reconstructed color matrix'
  23. % OutputFile: c 'Correction Image', required: 'Correction Image'
  24. % OutputFile: f 'Fwd Projected File', optional: 'forward proj. guess'
  25. % OutputFile: hf 'HF Content Output', optional: 'energy of highest 10% frequences'
  26. %
  27. % Example: [o, cmatout, c, f, hf] = kMultiColorDeconv({i, p, cmatrix, s, Over}, {'n',60;'noDeconv',0;'firstConv',0;'rW',4;'norichardson',0;'noPSFnorm',0;'mf',0.8;'mzf',0.4;'i','';'p','';'cmatrix','';'s','';'Over','';'HolmesLiu',0;'penalty',0.05;'rpenalty',-0.02;'o','';'cmatout','';'c','';'f','';'hf',''})
  28. %
  29. % Khoros helpfile follows below:
  30. %
  31. % PROGRAM
  32. % MultiColorDeconv - Deconvolution with N spectral signatures measured in M channels
  33. %
  34. % DESCRIPTION
  35. %
  36. %
  37. %
  38. % EXAMPLES
  39. %
  40. % "SEE ALSO"
  41. %
  42. % RESTRICTIONS
  43. %
  44. % REFERENCES
  45. %
  46. % COPYRIGHT
  47. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  48. %
  49. function varargout = kMultiColorDeconv(varargin)
  50. if nargin ==0
  51. Inputs={};arglist={'',''};
  52. elseif nargin ==1
  53. Inputs=varargin{1};arglist={'',''};
  54. elseif nargin ==2
  55. Inputs=varargin{1}; arglist=varargin{2};
  56. else error('Usage: [out1,..] = kMultiColorDeconv(Inputs,arglist).');
  57. end
  58. if size(arglist,2)~=2
  59. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  60. end
  61. narglist={'n', 60;'noDeconv', 0;'firstConv', 0;'rW', 4;'norichardson', 0;'noPSFnorm', 0;'mf', 0.8;'mzf', 0.4;'i', '__input';'p', '__input';'cmatrix', '__input';'s', '__input';'Over', '__input';'HolmesLiu', 0;'penalty', 0.05;'rpenalty', -0.02;'o', '__output';'cmatout', '__output';'c', '__output';'f', '__output';'hf', '__output'};
  62. maxval={1000,0,1,2,0,0,2,2,0,0,0,1,1,0,0,0,0,1,0,1,1};
  63. minval={1,0,1,2,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1};
  64. istoggle=[0,1,0,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,0,1,1];
  65. was_set=istoggle * 0;
  66. paramtype={'Integer','Toggle','Integer','Integer','Toggle','Toggle','Double','Double','InputFile','InputFile','InputFile','InputFile','InputFile','Toggle','Double','Double','OutputFile','OutputFile','OutputFile','OutputFile','OutputFile'};
  67. % identify the input arrays and assign them to the arguments as stated by the user
  68. if ~iscell(Inputs)
  69. Inputs = {Inputs};
  70. end
  71. NumReqOutputs=2; nextinput=1; nextoutput=1;
  72. for ii=1:size(arglist,1)
  73. wasmatched=0;
  74. for jj=1:size(narglist,1)
  75. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  76. wasmatched = 1;
  77. was_set(jj) = 1;
  78. if strcmp(narglist{jj,2}, '__input')
  79. if (nextinput > length(Inputs))
  80. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  81. end
  82. narglist{jj,2} = 'OK_in';
  83. nextinput = nextinput + 1;
  84. elseif strcmp(narglist{jj,2}, '__output')
  85. if (nextoutput > nargout)
  86. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  87. end
  88. if (isempty(arglist{ii,2}))
  89. narglist{jj,2} = 'OK_out';
  90. else
  91. narglist{jj,2} = arglist{ii,2};
  92. end
  93. nextoutput = nextoutput + 1;
  94. if (minval{jj} == 0)
  95. NumReqOutputs = NumReqOutputs - 1;
  96. end
  97. elseif isstr(arglist{ii,2})
  98. narglist{jj,2} = arglist{ii,2};
  99. else
  100. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  101. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  102. end
  103. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  104. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  105. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  106. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  107. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  108. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  109. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  110. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  111. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  112. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  113. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  114. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  115. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  116. end
  117. end
  118. end
  119. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  120. narglist{jj,2} = arglist{ii,2};
  121. end
  122. end
  123. end
  124. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  125. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  126. end
  127. end
  128. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  129. for jj=1:size(narglist,1)
  130. if strcmp(paramtype{jj}, 'Toggle')
  131. if (narglist{jj,2} ==0)
  132. narglist{jj,1} = '';
  133. end;
  134. narglist{jj,2} = '';
  135. end;
  136. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  137. narglist{jj,1} = '';
  138. narglist{jj,2} = '';
  139. end;
  140. if strcmp(narglist{jj,2}, '__input')
  141. if (minval{jj} == 0) % meaning this input is required
  142. if (nextinput > size(Inputs))
  143. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  144. else
  145. narglist{jj,2} = 'OK_in';
  146. nextinput = nextinput + 1;
  147. end
  148. else % this is an optional input
  149. if (nextinput <= length(Inputs))
  150. narglist{jj,2} = 'OK_in';
  151. nextinput = nextinput + 1;
  152. else
  153. narglist{jj,1} = '';
  154. narglist{jj,2} = '';
  155. end;
  156. end;
  157. else
  158. if strcmp(narglist{jj,2}, '__output')
  159. if (minval{jj} == 0) % this is a required output
  160. if (nextoutput > nargout & nargout > 1)
  161. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  162. else
  163. narglist{jj,2} = 'OK_out';
  164. nextoutput = nextoutput + 1;
  165. NumReqOutputs = NumReqOutputs-1;
  166. end
  167. else % this is an optional output
  168. if (nargout - nextoutput >= NumReqOutputs)
  169. narglist{jj,2} = 'OK_out';
  170. nextoutput = nextoutput + 1;
  171. else
  172. narglist{jj,1} = '';
  173. narglist{jj,2} = '';
  174. end;
  175. end
  176. end
  177. end
  178. end
  179. if nargout
  180. varargout = cell(1,nargout);
  181. else
  182. varargout = cell(1,1);
  183. end
  184. global KhorosRoot
  185. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  186. w=['"' KhorosRoot];
  187. else
  188. if ispc
  189. w='"C:\Program Files\dip\khorosBin\';
  190. else
  191. [s,w] = system('which cantata');
  192. w=['"' w(1:end-8)];
  193. end
  194. end
  195. [varargout{:}]=callKhoros([w 'multicolorrec" -k'],Inputs,narglist);