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

/matlab_tools/Converted/kvsubm.m

http://github.com/aludnam/MATLAB
Objective C | 201 lines | 198 code | 3 blank | 0 comment | 56 complexity | 45dc6ff7dbabb8aa5fa8967e07e439d4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvsubm 'Subtraction of Two Images'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vsubm.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Image #1', required: 'first input image'
  6. % OutputFile: o 'Output Image ', required: 'resulting output image'
  7. % InputFile: i2 'Input Image #2', optional: 'second input image'
  8. % Integer: c 'Constant Image', default: 0: 'sub constant'
  9. %
  10. % Example: o = kvsubm({i1, i2}, {'i1','';'o','';'i2','';'c',0})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % vsubm - Subtraction of Two Images
  16. %
  17. % DESCRIPTION
  18. % .I vsubm
  19. % computes the difference between the first input image and the
  20. % second input image (result = image1 - image2), with an optional
  21. % operation gating image. The second image can, optionally, be chosen as a constant.
  22. % If the difference between two pixel values is less than zero, the resultant pixel value will be set to zero.
  23. %
  24. % The two input images must be of the same size and have the same
  25. % number of data bands. The input
  26. % images may be of the same or different data types. If the input
  27. % images are of different data types, then all input images will be
  28. % upcast to the highest input image data type. The output
  29. % image data type will be the same as that of the highest data type
  30. % of the input images.
  31. %
  32. %
  33. %
  34. % EXAMPLES
  35. % vsubm -i1 input.image1 -i2 input.image2 -o output.image
  36. %
  37. % This subtracts input.image2 from input.image1 and stores the results in output.image.
  38. %
  39. % "SEE ALSO"
  40. % vcast1(1)
  41. %
  42. % RESTRICTIONS
  43. % .I vsubm
  44. % can be defined for all data types supported by Khoros, but at the moment it has been implemented just for the bit and unsigned char types.
  45. % The structuring elements are subsets of the 3x3 matrix and the origin is always at the center of this matrix.
  46. %
  47. % REFERENCES
  48. %
  49. % COPYRIGHT
  50. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  51. %
  52. function varargout = kvsubm(varargin)
  53. if nargin ==0
  54. Inputs={};arglist={'',''};
  55. elseif nargin ==1
  56. Inputs=varargin{1};arglist={'',''};
  57. elseif nargin ==2
  58. Inputs=varargin{1}; arglist=varargin{2};
  59. else error('Usage: [out1,..] = kvsubm(Inputs,arglist).');
  60. end
  61. if size(arglist,2)~=2
  62. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  63. end
  64. narglist={'i1', '__input';'o', '__output';'i2', '__input';'c', 0};
  65. maxval={0,0,1,255};
  66. minval={0,0,1,0};
  67. istoggle=[0,0,1,1];
  68. was_set=istoggle * 0;
  69. paramtype={'InputFile','OutputFile','InputFile','Integer'};
  70. % identify the input arrays and assign them to the arguments as stated by the user
  71. if ~iscell(Inputs)
  72. Inputs = {Inputs};
  73. end
  74. NumReqOutputs=1; nextinput=1; nextoutput=1;
  75. for ii=1:size(arglist,1)
  76. wasmatched=0;
  77. for jj=1:size(narglist,1)
  78. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  79. wasmatched = 1;
  80. was_set(jj) = 1;
  81. if strcmp(narglist{jj,2}, '__input')
  82. if (nextinput > length(Inputs))
  83. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  84. end
  85. narglist{jj,2} = 'OK_in';
  86. nextinput = nextinput + 1;
  87. elseif strcmp(narglist{jj,2}, '__output')
  88. if (nextoutput > nargout)
  89. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  90. end
  91. if (isempty(arglist{ii,2}))
  92. narglist{jj,2} = 'OK_out';
  93. else
  94. narglist{jj,2} = arglist{ii,2};
  95. end
  96. nextoutput = nextoutput + 1;
  97. if (minval{jj} == 0)
  98. NumReqOutputs = NumReqOutputs - 1;
  99. end
  100. elseif isstr(arglist{ii,2})
  101. narglist{jj,2} = arglist{ii,2};
  102. else
  103. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  104. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  105. end
  106. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  107. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  108. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  109. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  110. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  111. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  112. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  113. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  114. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  115. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  116. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  117. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  118. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  119. end
  120. end
  121. end
  122. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  123. narglist{jj,2} = arglist{ii,2};
  124. end
  125. end
  126. end
  127. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  128. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  129. end
  130. end
  131. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  132. for jj=1:size(narglist,1)
  133. if strcmp(paramtype{jj}, 'Toggle')
  134. if (narglist{jj,2} ==0)
  135. narglist{jj,1} = '';
  136. end;
  137. narglist{jj,2} = '';
  138. end;
  139. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  140. narglist{jj,1} = '';
  141. narglist{jj,2} = '';
  142. end;
  143. if strcmp(narglist{jj,2}, '__input')
  144. if (minval{jj} == 0) % meaning this input is required
  145. if (nextinput > size(Inputs))
  146. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  147. else
  148. narglist{jj,2} = 'OK_in';
  149. nextinput = nextinput + 1;
  150. end
  151. else % this is an optional input
  152. if (nextinput <= length(Inputs))
  153. narglist{jj,2} = 'OK_in';
  154. nextinput = nextinput + 1;
  155. else
  156. narglist{jj,1} = '';
  157. narglist{jj,2} = '';
  158. end;
  159. end;
  160. else
  161. if strcmp(narglist{jj,2}, '__output')
  162. if (minval{jj} == 0) % this is a required output
  163. if (nextoutput > nargout & nargout > 1)
  164. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  165. else
  166. narglist{jj,2} = 'OK_out';
  167. nextoutput = nextoutput + 1;
  168. NumReqOutputs = NumReqOutputs-1;
  169. end
  170. else % this is an optional output
  171. if (nargout - nextoutput >= NumReqOutputs)
  172. narglist{jj,2} = 'OK_out';
  173. nextoutput = nextoutput + 1;
  174. else
  175. narglist{jj,1} = '';
  176. narglist{jj,2} = '';
  177. end;
  178. end
  179. end
  180. end
  181. end
  182. if nargout
  183. varargout = cell(1,nargout);
  184. else
  185. varargout = cell(1,1);
  186. end
  187. global KhorosRoot
  188. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  189. w=['"' KhorosRoot];
  190. else
  191. if ispc
  192. w='"C:\Program Files\dip\khorosBin\';
  193. else
  194. [s,w] = system('which cantata');
  195. w=['"' w(1:end-8)];
  196. end
  197. end
  198. [varargout{:}]=callKhoros([w 'vsubm" '],Inputs,narglist);