PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kvtilt.m

http://github.com/aludnam/MATLAB
Objective C | 199 lines | 196 code | 3 blank | 0 comment | 54 complexity | 17d329a010b5dfe76293e99f7a3c20d0 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvtilt 'Add a Specified Illumination Gradient Plane to Image (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vtilt.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input Image ', required: 'input image'
  6. % InputFile: m 'Masking Image ', optional: 'tilt operation masking image'
  7. % Double: x 'Slope in X-dir', default: 0: 'specifies the slope in the X direction'
  8. % Double: y 'Slope in Y-dir', default: 0: 'specifies the slope in the Y direction'
  9. % OutputFile: o 'Output Image ', required: 'resulting output image'
  10. %
  11. % Example: o = kvtilt({i, m}, {'i','';'m','';'x',0;'y',0;'o',''})
  12. %
  13. % Khoros helpfile follows below:
  14. %
  15. % PROGRAM
  16. % vtilt - Add a Specified Illumination Gradient Plane to Image (K1)
  17. %
  18. % DESCRIPTION
  19. % "vtilt"
  20. % adds tilt to an image.
  21. % Often an image will have a skew in the grey level values that represents
  22. % a plane with a certain slope. The tilt takes the form of a plane which has
  23. % an x and y zero crossing at the center of the image with x an y slope
  24. % as specified in the argument list. The x and y slopes
  25. % must be given in units per pixel and the x and y values default to 0.0.
  26. %
  27. % The optional mask image (-m) must be of the same data type as the input images,
  28. % and is used to gate the operation. A non-zero mask pixel enables the output
  29. % pixel to contain the adjusted value. A zero mask pixel just transfers
  30. % the value of the corresponding pixel in the first input image to the output
  31. % pixel.
  32. %
  33. %
  34. %
  35. % EXAMPLES
  36. % vtilt -i image -o out -x 2 -y -1
  37. %
  38. % "SEE ALSO"
  39. % vgettilt, lvgettilt, vdetilt
  40. %
  41. % RESTRICTIONS
  42. % .I vtilt
  43. % will not operate on COMPLEX or BIT data storage types.
  44. %
  45. % REFERENCES
  46. %
  47. % COPYRIGHT
  48. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  49. %
  50. function varargout = kvtilt(varargin)
  51. if nargin ==0
  52. Inputs={};arglist={'',''};
  53. elseif nargin ==1
  54. Inputs=varargin{1};arglist={'',''};
  55. elseif nargin ==2
  56. Inputs=varargin{1}; arglist=varargin{2};
  57. else error('Usage: [out1,..] = kvtilt(Inputs,arglist).');
  58. end
  59. if size(arglist,2)~=2
  60. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  61. end
  62. narglist={'i', '__input';'m', '__input';'x', 0;'y', 0;'o', '__output'};
  63. maxval={0,1,0,0,0};
  64. minval={0,1,0,0,0};
  65. istoggle=[0,1,1,1,0];
  66. was_set=istoggle * 0;
  67. paramtype={'InputFile','InputFile','Double','Double','OutputFile'};
  68. % identify the input arrays and assign them to the arguments as stated by the user
  69. if ~iscell(Inputs)
  70. Inputs = {Inputs};
  71. end
  72. NumReqOutputs=1; nextinput=1; nextoutput=1;
  73. for ii=1:size(arglist,1)
  74. wasmatched=0;
  75. for jj=1:size(narglist,1)
  76. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  77. wasmatched = 1;
  78. was_set(jj) = 1;
  79. if strcmp(narglist{jj,2}, '__input')
  80. if (nextinput > length(Inputs))
  81. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  82. end
  83. narglist{jj,2} = 'OK_in';
  84. nextinput = nextinput + 1;
  85. elseif strcmp(narglist{jj,2}, '__output')
  86. if (nextoutput > nargout)
  87. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  88. end
  89. if (isempty(arglist{ii,2}))
  90. narglist{jj,2} = 'OK_out';
  91. else
  92. narglist{jj,2} = arglist{ii,2};
  93. end
  94. nextoutput = nextoutput + 1;
  95. if (minval{jj} == 0)
  96. NumReqOutputs = NumReqOutputs - 1;
  97. end
  98. elseif isstr(arglist{ii,2})
  99. narglist{jj,2} = arglist{ii,2};
  100. else
  101. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  102. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  103. end
  104. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  105. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  106. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  107. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  108. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  109. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  110. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  111. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  112. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  113. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  114. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  115. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  116. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  117. end
  118. end
  119. end
  120. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  121. narglist{jj,2} = arglist{ii,2};
  122. end
  123. end
  124. end
  125. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  126. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  127. end
  128. end
  129. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  130. for jj=1:size(narglist,1)
  131. if strcmp(paramtype{jj}, 'Toggle')
  132. if (narglist{jj,2} ==0)
  133. narglist{jj,1} = '';
  134. end;
  135. narglist{jj,2} = '';
  136. end;
  137. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  138. narglist{jj,1} = '';
  139. narglist{jj,2} = '';
  140. end;
  141. if strcmp(narglist{jj,2}, '__input')
  142. if (minval{jj} == 0) % meaning this input is required
  143. if (nextinput > size(Inputs))
  144. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  145. else
  146. narglist{jj,2} = 'OK_in';
  147. nextinput = nextinput + 1;
  148. end
  149. else % this is an optional input
  150. if (nextinput <= length(Inputs))
  151. narglist{jj,2} = 'OK_in';
  152. nextinput = nextinput + 1;
  153. else
  154. narglist{jj,1} = '';
  155. narglist{jj,2} = '';
  156. end;
  157. end;
  158. else
  159. if strcmp(narglist{jj,2}, '__output')
  160. if (minval{jj} == 0) % this is a required output
  161. if (nextoutput > nargout & nargout > 1)
  162. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  163. else
  164. narglist{jj,2} = 'OK_out';
  165. nextoutput = nextoutput + 1;
  166. NumReqOutputs = NumReqOutputs-1;
  167. end
  168. else % this is an optional output
  169. if (nargout - nextoutput >= NumReqOutputs)
  170. narglist{jj,2} = 'OK_out';
  171. nextoutput = nextoutput + 1;
  172. else
  173. narglist{jj,1} = '';
  174. narglist{jj,2} = '';
  175. end;
  176. end
  177. end
  178. end
  179. end
  180. if nargout
  181. varargout = cell(1,nargout);
  182. else
  183. varargout = cell(1,1);
  184. end
  185. global KhorosRoot
  186. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  187. w=['"' KhorosRoot];
  188. else
  189. if ispc
  190. w='"C:\Program Files\dip\khorosBin\';
  191. else
  192. [s,w] = system('which cantata');
  193. w=['"' w(1:end-8)];
  194. end
  195. end
  196. [varargout{:}]=callKhoros([w 'vtilt" '],Inputs,narglist);