PageRenderTime 83ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvsymdif.m

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